]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datetime.cpp
Add wxDataViewModel::ChangeValue() and use it in wxDVC implementation.
[wxWidgets.git] / src / common / datetime.cpp
index 5de52dd01ec85a7b51cff12d7a4ad061b5cac830..827cb51a22a690f9cc9894e0d678e9b1b1a0cc2f 100644 (file)
@@ -130,14 +130,9 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter<wxDateTime> , wxFromStringCon
         #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;
+            struct timeb tb;
+            ftime(&tb);
+            return tb.timezone;
         }
         #define WX_TIMEZONE wxGetTimeZone()
     #elif defined(__DARWIN__)
@@ -148,28 +143,18 @@ wxCUSTOM_TYPE_INFO(wxDateTime, wxToStringConverter<wxDateTime> , wxFromStringCon
         // 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;
+            long t;
+            _get_timezone(& t);
+            return t;
         }
         #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;
+            TIME_ZONE_INFORMATION tzi;
+            ::GetTimeZoneInformation(&tzi);
+            return tzi.Bias; // x 60
         }
         #define WX_TIMEZONE wxGetTimeZone()
         #else
@@ -385,6 +370,7 @@ wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month)
 // NOTE: not static because used by datetimefmt.cpp
 int GetTimeZone()
 {
+#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
@@ -400,17 +386,15 @@ int GetTimeZone()
         wxLocaltime_r(&t, &tm);
         s_timezoneSet = true;
 
-#ifdef WX_GMTOFF_IN_TM
         // 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;
-#else // !WX_GMTOFF_IN_TM
-        gmtoffset = WX_TIMEZONE;
-#endif // WX_GMTOFF_IN_TM/!WX_GMTOFF_IN_TM
     }
-
     return (int)gmtoffset;
+#else // !WX_GMTOFF_IN_TM
+    return WX_TIMEZONE;
+#endif // WX_GMTOFF_IN_TM/!WX_GMTOFF_IN_TM
 }
 
 // return the integral part of the JDN for the midnight of the given date (to
@@ -875,7 +859,7 @@ wxString wxDateTime::GetEnglishWeekDayName(WeekDay wday, NameFlags flags)
 {
     wxCHECK_MSG( wday != Inv_WeekDay, wxEmptyString, wxT("invalid weekday") );
 
-    static const char *weekdayNames[2][DAYS_PER_400_YEARS] =
+    static const char *weekdayNames[2][DAYS_PER_WEEK] =
     {
         { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
           "Saturday" },
@@ -2356,7 +2340,7 @@ wxDateTime& wxDateTime::SetFromMSWSysTime(const SYSTEMTIME& st)
     return Set(st.wDay,
             static_cast<wxDateTime::Month>(wxDateTime::Jan + st.wMonth - 1),
             st.wYear,
-            0, 0, 0);
+            st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
 }
 
 void wxDateTime::GetAsMSWSysTime(SYSTEMTIME* st) const
@@ -2367,11 +2351,11 @@ void wxDateTime::GetAsMSWSysTime(SYSTEMTIME* st) const
     st->wMonth = (WXWORD)(tm.mon - wxDateTime::Jan + 1);
     st->wDay = tm.mday;
 
-    st->wDayOfWeek =
-    st->wHour =
-    st->wMinute =
-    st->wSecond =
-    st->wMilliseconds = 0;
+    st->wDayOfWeek = 0;
+    st->wHour = tm.hour;
+    st->wMinute = tm.min;
+    st->wSecond = tm.sec;
+    st->wMilliseconds = tm.msec;
 }
 #endif // __WXMSW__