#pragma hdrstop
#endif
+#if !defined(wxUSE_DATETIME) || wxUSE_DATETIME
+
#ifndef WX_PRECOMP
#include "wx/string.h"
- #include "wx/intl.h"
#include "wx/log.h"
#endif // WX_PRECOMP
+#include "wx/intl.h"
#include "wx/thread.h"
#include "wx/tokenzr.h"
#include "wx/module.h"
#undef HAVE_STRPTIME
#endif // broken strptime()
-#ifndef WX_TIMEZONE
+#if !defined(WX_TIMEZONE) && !defined(WX_GMTOFF_IN_TM)
#if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__)
#define WX_TIMEZONE _timezone
#elif defined(__MWERKS__)
long wxmw_timezone = 28800;
- #define WX_TIMEZONE wxmw_timezone;
+ #define WX_TIMEZONE wxmw_timezone
+ #elif defined(__DJGPP__)
+ #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
#else // unknown platform - try timezone
#define WX_TIMEZONE timezone
#endif
-#endif // !WX_TIMEZONE
+#endif // !WX_TIMEZONE && !WX_GMTOFF_IN_TM
// ----------------------------------------------------------------------------
// macros
// in the fine tradition of ANSI C we use our equivalent of (time_t)-1 to
// indicate an invalid wxDateTime object
-
-static const wxDateTime gs_dtDefault;
-
-const wxDateTime& wxDefaultDateTime = gs_dtDefault;
+const wxDateTime wxDefaultDateTime;
wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown;
{
// 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);
if ( !s_timezoneSet )
{
// just call localtime() instead of figuring out whether this system
// supports tzset(), _tzset() or something else
- time_t t = 0;
+ time_t t = 0;
+ struct tm *tm;
- (void)localtime(&t);
+ tm = localtime(&t);
s_timezoneSet = TRUE;
+#ifdef WX_GMTOFF_IN_TM
+ gmtoffset = tm->tm_gmtoff;
+#endif
}
+#ifdef WX_GMTOFF_IN_TM
+ return (int)gmtoffset;
+#else
return (int)WX_TIMEZONE;
+#endif
}
// return the integral part of the JDN for the midnight of the given date (to
}
}
- // try all time formats we may think about starting with the standard one
- const wxChar *result = ParseFormat(time, _T("%X"));
+ // try all time formats we may think about in the order from longest to
+ // shortest
+
+ // 12hour with AM/PM?
+ const wxChar *result = ParseFormat(time, _T("%I:%M:%S %p"));
+
if ( !result )
{
// normally, it's the same, but why not try it?
if ( !result )
{
- // 12hour with AM/PM?
- result = ParseFormat(time, _T("%I:%M:%S %p"));
+ // 12hour with AM/PM but without seconds?
+ result = ParseFormat(time, _T("%I:%M %p"));
}
if ( !result )
if ( !result )
{
- // 12hour with AM/PM but without seconds?
- result = ParseFormat(time, _T("%I:%M %p"));
+ // just the hour and AM/PM?
+ result = ParseFormat(time, _T("%I %p"));
}
if ( !result )
if ( !result )
{
- // just the hour and AM/PM?
- result = ParseFormat(time, _T("%I %p"));
+ // parse the standard format: normally it is one of the formats above
+ // but it may be set to something completely different by the user
+ result = ParseFormat(time, _T("%X"));
}
// TODO: parse timezones
return holidays.GetCount();
}
-
+#endif // wxUSE_DATETIME