]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/timercmn.cpp
test for timegm() added
[wxWidgets.git] / src / common / timercmn.cpp
index e2ac6496aed56eb739a7fac24e67936b1a04896f..8a34f3cfda7975d70056d5f84ff845f328a2a8c1 100644 (file)
 #include "wx/timer.h"
 
 // I'm told VMS is POSIX, so should have localtime()
-#if defined(__WXMSW__) || defined(__VMS__)
+#if defined(__WXMSW__) || defined(__VMS__) || defined(__WXPM__) || defined(__WXMAC__)
     // configure might have found it already for us
     #ifndef HAVE_LOCALTIME
         #define HAVE_LOCALTIME
-
-        // TODO add test for broken compilers here if needed
-        #define WX_GMTOFF_IN_TM
     #endif
 #endif
 
+// TODO: #define WX_GMTOFF_IN_TM for Windows compilers which have it here
+
+#if defined(__WIN32__) && !defined(WX_GMTOFF_IN_TM)
+    #include <windows.h>
+#endif
+
 #if defined(HAVE_GETTIMEOFDAY)
     #include <sys/time.h>
     #include <unistd.h>
@@ -133,6 +136,12 @@ long wxGetCurrentTime()
 // return GMT time in millisecond
 long wxGetCurrentMTime()
 {
+#if defined(__WIN32__)
+    SYSTEMTIME st;
+    ::GetLocalTime(&st);
+
+    return 1000*(60*(60*st.wHour+st.wMinute)+st.wSecond)+st.wMilliseconds;
+#else
 #if defined(HAVE_LOCALTIME)
     time_t t0 = time(&t0);
     if ( t0 != (time_t)-1 )
@@ -163,6 +172,7 @@ long wxGetCurrentMTime()
     wxLogSysError(_("Failed to get the system time"));
 
     return -1;
+#endif // __WIN32__/!__WIN32__
 }
 
 bool wxGetLocalTime(long *timeZone, int *dstObserved)
@@ -198,11 +208,9 @@ bool wxGetLocalTime(long *timeZone, int *dstObserved)
         *timeZone = 60*tb.timezone;
         *dstObserved = tb.dstflag;
     }
-#else
-    // special hacks for known compilers - I wonder if this is still needed,
-    // i.e. if there are any of them which don't support localtime()? (VZ)
-
-    #if defined(__BORLANDC__)
+#else // no standard function return tz info
+    // special hacks for known compilers
+    #if defined(__BORLANDC__) || defined(__VISUALC__)
         *timeZone = _timezone;
         *dstObserved = _daylight;
     #elif defined(__SALFORDC__)
@@ -211,10 +219,29 @@ bool wxGetLocalTime(long *timeZone, int *dstObserved)
     #elif defined(__VISAGECPP__)
         *timeZone = _timezone;
         *dstObserved = daylight;
+    #elif defined(__WIN32__)
+        TIME_ZONE_INFORMATION tzInfo;
+        switch ( GetTimeZoneInformation(&tzInfo) )
+        {
+            default:
+                wxFAIL_MSG(_T("unknown GetTimeZoneInformation return code"));
+                // fall through
+
+            case TIME_ZONE_ID_UNKNOWN:
+            case TIME_ZONE_ID_STANDARD:
+                *dstObserved = FALSE;
+                break;
+
+            case TIME_ZONE_ID_DAYLIGHT:
+                *dstObserved = TRUE;
+                break;
+        }
+
+        *timeZone = 60*tzInfo.Bias;
     #else
         wxFAIL_MSG(_T("wxGetLocalTime() not implemented"));
     #endif // compiler
-#endif
+#endif // all ways in the known Universe to get tz info
 
     return FALSE;
 }