- return FormatTime();
-}
-
-void wxTime::SetFormat(const wxTime::tFormat lFormat,
- const wxTime::tPrecision lPrecision) {
-
- wxTime::Format = lFormat;
- wxTime::Precision = lPrecision;
-}
-
-char *wxTime::FormatTime() const {
- static char timeBuf[30];
- unsigned hh(GetHour());
-
- switch (Format) {
- case wx12h:
- hh -= 12;
- break;
- case wx24h:
- break;
- }
-
- switch (Precision) {
- case wxStdMinSec:
- sprintf(timeBuf,"%2d:%02d:%02d",hh,GetMinute(),GetSecond());
- break;
- case wxStdMin:
- sprintf(timeBuf,"%2d:%02d",hh,GetMinute());
- break;
- }
-
- if (Format == wx12h)
- if (GetHour() <= 12)
- strcat(timeBuf,"am");
- else
- strcat(timeBuf,"pm");
-
- return timeBuf;
+#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