-
-// ----------------------------------------------------------------------------
-// conditional compilation
-// ----------------------------------------------------------------------------
-
-#if defined(__MWERKS__) && wxUSE_UNICODE
- #include <wtime.h>
-#endif
-
-#if !defined(WX_TIMEZONE) && !defined(WX_GMTOFF_IN_TM)
- #if defined(__WXPALMOS__)
- #define WX_GMTOFF_IN_TM
- #elif defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__)
- #define WX_TIMEZONE _timezone
- #elif defined(__MWERKS__)
- long wxmw_timezone = 28800;
- #define WX_TIMEZONE wxmw_timezone
- #elif defined(__DJGPP__) || defined(__WINE__)
- #include <sys/timeb.h>
- #include <values.h>
- static long wxGetTimeZone()
- {
- static long timezone = MAXLONG; // invalid timezone
- if (timezone == MAXLONG)
- {
- struct timeb tb;
- ftime(&tb);
- timezone = tb.timezone;
- }
- return timezone;
- }
- #define WX_TIMEZONE wxGetTimeZone()
- #elif defined(__DARWIN__)
- #define WX_GMTOFF_IN_TM
- #elif defined(__WXWINCE__) && defined(__VISUALC8__)
- // _timezone is not present in dynamic run-time library
- #if 0
- // Solution (1): use the function equivalent of _timezone
- static long wxGetTimeZone()
- {
- static long s_Timezone = MAXLONG; // invalid timezone
- if (s_Timezone == MAXLONG)
- {
- int t;
- _get_timezone(& t);
- s_Timezone = (long) t;
- }
- return s_Timezone;
- }
- #define WX_TIMEZONE wxGetTimeZone()
- #elif 1
- // Solution (2): using GetTimeZoneInformation
- static long wxGetTimeZone()
- {
- static long timezone = MAXLONG; // invalid timezone
- if (timezone == MAXLONG)
- {
- TIME_ZONE_INFORMATION tzi;
- ::GetTimeZoneInformation(&tzi);
- timezone = tzi.Bias;
- }
- return timezone;
- }
- #define WX_TIMEZONE wxGetTimeZone()
- #else
- // Old method using _timezone: this symbol doesn't exist in the dynamic run-time library (i.e. using /MD)
- #define WX_TIMEZONE _timezone
- #endif
- #else // unknown platform - try timezone
- #define WX_TIMEZONE timezone
- #endif
-#endif // !WX_TIMEZONE && !WX_GMTOFF_IN_TM
-
-// NB: VC8 safe time functions could/should be used for wxMSW as well probably
-#if defined(__WXWINCE__) && defined(__VISUALC8__)
-
-struct tm *wxLocaltime_r(const time_t *t, struct tm* tm)
-{
- __time64_t t64 = *t;
- return _localtime64_s(tm, &t64) == 0 ? tm : NULL;
-}
-
-struct tm *wxGmtime_r(const time_t* t, struct tm* tm)
-{
- __time64_t t64 = *t;
- return _gmtime64_s(tm, &t64) == 0 ? tm : NULL;
-}
-
-#else // !wxWinCE with VC8
-
-#if (!defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)) && wxUSE_THREADS && !defined(__WINDOWS__)
-static wxMutex timeLock;
-#endif
-
-#ifndef HAVE_LOCALTIME_R
-struct tm *wxLocaltime_r(const time_t* ticks, struct tm* temp)
-{
-#if wxUSE_THREADS && !defined(__WINDOWS__)
- // No need to waste time with a mutex on windows since it's using
- // thread local storage for localtime anyway.
- wxMutexLocker locker(timeLock);
-#endif
-
- // Borland CRT crashes when passed 0 ticks for some reason, see SF bug 1704438
-#ifdef __BORLANDC__
- if ( !*ticks )
- return NULL;
-#endif
-
- const tm * const t = localtime(ticks);
- if ( !t )
- return NULL;
-
- memcpy(temp, t, sizeof(struct tm));
- return temp;
-}
-#endif // !HAVE_LOCALTIME_R
-
-#ifndef HAVE_GMTIME_R
-struct tm *wxGmtime_r(const time_t* ticks, struct tm* temp)
-{
-#if wxUSE_THREADS && !defined(__WINDOWS__)
- // No need to waste time with a mutex on windows since it's
- // using thread local storage for gmtime anyway.
- wxMutexLocker locker(timeLock);
-#endif
-
-#ifdef __BORLANDC__
- if ( !*ticks )
- return NULL;
-#endif
-
- const tm * const t = gmtime(ticks);
- if ( !t )
- return NULL;
-
- memcpy(temp, gmtime(ticks), sizeof(struct tm));
- return temp;
-}
-#endif // !HAVE_GMTIME_R
-
-#endif // wxWinCE with VC8/other platforms
-