]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datetime.cpp
added support for leaving out <embedded objects> that are created during their parent...
[wxWidgets.git] / src / common / datetime.cpp
index 6751dd2ad9498f3b1ed593f9d382253ee1b63cdc..9335c17f0cf7afe926603bda70ec7e49b0548dd3 100644 (file)
@@ -52,7 +52,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "datetime.h"
 #endif
 
@@ -78,7 +78,7 @@
 #include <ctype.h>
 
 #include "wx/datetime.h"
-#include "wx/timer.h"           // for wxGetLocalTimeMillis()
+#include "wx/stopwatch.h"           // for wxGetLocalTimeMillis()
 
 const long wxDateTime::TIME_T_FACTOR = 1000l;
 
@@ -222,16 +222,6 @@ const wxDateTime wxDefaultDateTime;
 
 wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown;
 
-// ----------------------------------------------------------------------------
-// private globals
-// ----------------------------------------------------------------------------
-
-// a critical section is needed to protect GetTimeZone() static
-// variable in MT case
-#if wxUSE_THREADS
-    static wxCriticalSection gs_critsectTimezone;
-#endif // wxUSE_THREADS
-
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -267,13 +257,10 @@ wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month)
 // (in seconds)
 static int GetTimeZone()
 {
+#ifdef WX_GMTOFF_IN_TM
     // set to TRUE when the timezone is set
     static bool s_timezoneSet = FALSE;
-#ifdef WX_GMTOFF_IN_TM
     static long gmtoffset = LONG_MAX; // invalid timezone
-#endif
-
-    wxCRIT_SECT_LOCKER(lock, gs_critsectTimezone);
 
     // ensure that the timezone variable is set by calling localtime
     if ( !s_timezoneSet )
@@ -286,19 +273,16 @@ static int GetTimeZone()
         tm = localtime(&t);
         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;
-#endif
     }
 
-#ifdef WX_GMTOFF_IN_TM
     return (int)gmtoffset;
-#else
+#else // !WX_GMTOFF_IN_TM
     return (int)WX_TIMEZONE;
-#endif
+#endif // WX_GMTOFF_IN_TM/!WX_GMTOFF_IN_TM
 }
 
 // return the integral part of the JDN for the midnight of the given date (to
@@ -356,6 +340,12 @@ static wxString CallStrftime(const wxChar *format, const tm* tm)
 
 #ifdef HAVE_STRPTIME
 
+// glibc2 doesn't define this in the headers unless _XOPEN_SOURCE is defined
+// which, unfortunately, wreaks havoc elsewhere
+#if defined(__GLIBC__) && (__GLIBC__ == 2)
+    extern "C" char *strptime(const char *, const char *, struct tm *);
+#endif
+
 // Unicode-friendly strptime() wrapper
 static const wxChar *
 CallStrptime(const wxChar *input, const char *fmt, tm *tm)
@@ -2680,7 +2670,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
 
         // parse the optional width
         size_t width = 0;
-        while ( isdigit(*++fmt) )
+        while ( wxIsdigit(*++fmt) )
         {
             width *= 10;
             width += *fmt - _T('0');
@@ -3195,6 +3185,14 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
 
     Set(tm);
 
+    // finally check that the week day is consistent -- if we had it
+    if ( haveWDay && GetWeekDay() != wday )
+    {
+        wxLogDebug(_T("inconsistsnet week day in wxDateTime::ParseFormat()"));
+
+        return NULL;
+    }
+
     return input;
 }
 
@@ -3471,8 +3469,7 @@ const wxChar *wxDateTime::ParseDate(const wxChar *date)
                 mon = (wxDateTime::Month)(day - 1);
 
                 // we're in the current year then
-                if ( (year > 0) &&
-                        (unsigned)year <= GetNumOfDaysInMonth(Inv_Year, mon) )
+                if ( (year > 0) && (year <= (int)GetNumOfDaysInMonth(Inv_Year, mon)) )
                 {
                     day = year;