X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/173a5ddc77ceb29b7a0dba6d9feeea95ebbbd72b..9ba371fa05c50f65e887ca894518f293b4f88c25:/src/common/time.cpp?ds=sidebyside diff --git a/src/common/time.cpp b/src/common/time.cpp index 3b60d27438..4a76dfac48 100644 --- a/src/common/time.cpp +++ b/src/common/time.cpp @@ -26,7 +26,7 @@ #include "wx/time.h" #ifndef WX_PRECOMP - #ifdef __WXMSW__ + #ifdef __WINDOWS__ #include "wx/msw/wrapwin.h" #endif #include "wx/intl.h" @@ -36,7 +36,7 @@ #ifndef WX_GMTOFF_IN_TM // Define it for some systems which don't (always) use configure but are // known to have tm_gmtoff field. - #if defined(__WXPALMOS__) || defined(__DARWIN__) + #if defined(__DARWIN__) #define WX_GMTOFF_IN_TM #endif #endif @@ -48,19 +48,12 @@ # endif #endif -#if defined(__MWERKS__) && defined(__WXMSW__) -# undef HAVE_FTIME -# undef HAVE_GETTIMEOFDAY -#endif - -#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ #include #else #include "wx/msw/private.h" #include "wx/msw/wince/time.h" #endif -#endif // __WXPALMOS5__ #if !defined(__WXMAC__) && !defined(__WXWINCE__) @@ -74,10 +67,9 @@ #include #endif -#ifdef __WXPALMOS__ - #include - #include - #include +#if defined(__DJGPP__) || defined(__WINE__) + #include + #include #endif namespace @@ -93,6 +85,76 @@ const int MICROSECONDS_PER_SECOND = 1000*1000; // implementation // ============================================================================ +// 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 + // returns the time zone in the C sense, i.e. the difference UTC - local // (in seconds) int wxGetTimeZone() @@ -144,15 +206,18 @@ int wxGetTimeZone() #else // VC++ < 8 return timezone; #endif -#elif defined(WX_TIMEZONE) // If WX_TIMEZONE was defined by configure, use it. - return WX_TIMEZONE; -#elif defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__) - return _timezone; -#elif defined(__MWERKS__) - return 28800; -#else // unknown platform -- assume it has timezone - return timezone; -#endif // WX_GMTOFF_IN_TM/!WX_GMTOFF_IN_TM +#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 @@ -196,7 +261,7 @@ long wxGetUTCTime() wxLongLong wxGetUTCTimeUSec() { -#if defined(__WXMSW__) +#if defined(__WINDOWS__) FILETIME ft; ::GetSystemTimeAsFileTime(&ft); @@ -231,19 +296,7 @@ wxLongLong wxGetUTCTimeMillis() // If possible, use a function which avoids conversions from // broken-up time structures to milliseconds -#if defined(__WXPALMOS__) - DateTimeType thenst; - thenst.second = 0; - thenst.minute = 0; - thenst.hour = 0; - thenst.day = 1; - thenst.month = 1; - thenst.year = 1970; - thenst.weekDay = 5; - uint32_t now = TimGetSeconds(); - uint32_t then = TimDateTimeToSeconds (&thenst); - return SysTimeToMilliSecs(SysTimeInSecs(now - then)); -#elif defined(__WXMSW__) +#if defined(__WINDOWS__) FILETIME ft; ::GetSystemTimeAsFileTime(&ft);