+#ifdef WX_GMTOFF_IN_TM
+ // set to true when the timezone is set
+ static bool s_timezoneSet = false;
+ static long gmtoffset = LONG_MAX; // invalid timezone
+
+ // ensure that the timezone variable is set by calling wxLocaltime_r
+ if ( !s_timezoneSet )
+ {
+ // just call wxLocaltime_r() instead of figuring out whether this
+ // system supports tzset(), _tzset() or something else
+ time_t t = time(NULL);
+ struct tm tm;
+
+ wxLocaltime_r(&t, &tm);
+ s_timezoneSet = true;
+
+ // note that GMT offset is the opposite of time zone and so to return
+ // consistent results in both WX_GMTOFF_IN_TM and !WX_GMTOFF_IN_TM
+ // cases we have to negate it
+ gmtoffset = -tm.tm_gmtoff;
+
+ // this function is supposed to return the same value whether DST is
+ // enabled or not, so we need to use an additional offset if DST is on
+ // as tm_gmtoff already does include it
+ if ( tm.tm_isdst )
+ gmtoffset += 3600;
+ }
+ return (int)gmtoffset;
+#elif defined(__DJGPP__) || defined(__WINE__)
+ struct timeb tb;
+ ftime(&tb);
+ return tb.timezone*60;
+#elif defined(__VISUALC__)
+ // We must initialize the time zone information before using it (this will
+ // be done only once internally).
+ _tzset();
+
+ // Starting with VC++ 8 timezone variable is deprecated and is not even
+ // available in some standard library version so use the new function for
+ // accessing it instead.
+ #if wxCHECK_VISUALC_VERSION(8)
+ long t;
+ _get_timezone(&t);
+ return t;
+ #else // VC++ < 8
+ return timezone;
+ #endif
+#else // Use some kind of time zone variable.
+ // In any case we must initialize the time zone before using it.
+ tzset();
+
+ #if defined(WX_TIMEZONE) // If WX_TIMEZONE was defined by configure, use it.
+ return WX_TIMEZONE;
+ #elif defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__)
+ return _timezone;
+ #else // unknown platform -- assume it has timezone
+ return timezone;
+ #endif // different time zone variables
+#endif // different ways to determine time zone
+}
+
+// Get local time as seconds since 00:00:00, Jan 1st 1970
+long wxGetLocalTime()
+{
+ struct tm tm;
+ time_t t0, t1;
+
+ // This cannot be made static because mktime can overwrite it.
+ //
+ memset(&tm, 0, sizeof(tm));
+ tm.tm_year = 70;
+ tm.tm_mon = 0;
+ tm.tm_mday = 5; // not Jan 1st 1970 due to mktime 'feature'
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ tm.tm_isdst = -1; // let mktime guess
+
+ // Note that mktime assumes that the struct tm contains local time.
+ //
+ t1 = time(&t1); // now
+ t0 = mktime(&tm); // origin
+
+ // Return the difference in seconds.
+ //
+ if (( t0 != (time_t)-1 ) && ( t1 != (time_t)-1 ))
+ return (long)difftime(t1, t0) + (60 * 60 * 24 * 4);
+
+ wxLogSysError(_("Failed to get the local system time"));
+ return -1;
+}
+
+// Get UTC time as seconds since 00:00:00, Jan 1st 1970
+long wxGetUTCTime()