#endif
#include "wx/datetime.h"
+#include "wx/time.h"
// ============================================================================
// implementation of wxDateTime
extern void InitTm(struct tm& tm);
-extern int GetTimeZone();
-
extern wxString CallStrftime(const wxString& format, const tm* tm);
// ----------------------------------------------------------------------------
format.Replace("%X",wxLocale::GetInfo(wxLOCALE_TIME_FMT));
#endif
// we have to use our own implementation if the date is out of range of
- // strftime() or if we use non standard specificators
+ // strftime() or if we use non standard specifiers (notice that "%z" is
+ // special because it is de facto standard under Unix but is not supported
+ // under Windows)
#ifdef wxHAS_STRFTIME
time_t time = GetTicks();
- if ( (time != (time_t)-1) && !wxStrstr(format, wxT("%l")) )
+ if ( (time != (time_t)-1) && !wxStrstr(format, wxT("%l"))
+#ifdef __WXMSW__
+ && !wxStrstr(format, wxT("%z"))
+#endif
+ )
{
// use strftime()
struct tm tmstruct;
struct tm *tm;
- if ( tz.GetOffset() == -GetTimeZone() )
+ if ( tz.GetOffset() == -wxGetTimeZone() )
{
// we are working with local time
tm = wxLocaltime_r(&time, &tmstruct);
switch ( (*++p).GetValue() )
{
case wxT('Y'): // year has 4 digits
+ case wxT('z'): // time zone as well
fmt = wxT("%04d");
break;
res += wxString::Format(fmt, tm.year);
break;
+ case wxT('z'): // time zone as [-+]HHMM
+ {
+ int ofs = tz.GetOffset();
+ if ( ofs < 0 )
+ {
+ res += '-';
+ ofs = -ofs;
+ }
+ else
+ {
+ res += '+';
+ }
+
+ // Converts seconds to HHMM representation.
+ res += wxString::Format(fmt,
+ 100*(ofs/3600) + (ofs/60)%60);
+ }
+ break;
+
case wxT('Z'): // timezone name
#ifdef wxHAS_STRFTIME
res += CallStrftime(wxT("%Z"), &tmTimeOnly);
default:
// is it the format width?
- fmt.Empty();
- while ( *p == wxT('-') || *p == wxT('+') ||
- *p == wxT(' ') || wxIsdigit(*p) )
+ for ( fmt.clear();
+ *p == wxT('-') || *p == wxT('+') ||
+ *p == wxT(' ') || wxIsdigit(*p);
+ ++p )
{
fmt += *p;
}
}
// no, it wasn't the width
- wxFAIL_MSG(wxT("unknown format specificator"));
+ wxFAIL_MSG(wxT("unknown format specifier"));
// fall through and just copy it nevertheless
bool hourIsIn12hFormat = false, // or in 24h one?
isPM = false; // AM by default
+ bool haveTimeZone = false;
+
// and the value of the items we have (init them to get rid of warnings)
wxDateTime_t msec = 0,
sec = 0,
mday = 0;
wxDateTime::Month mon = Inv_Month;
int year = 0;
+ long timeZone = 0; // time zone in seconds as expected in Tm structure
wxString::const_iterator input = date.begin();
const wxString::const_iterator end = date.end();
year = (wxDateTime_t)num;
break;
+ case wxT('z'):
+ {
+ bool minusFound;
+ if ( *input == wxT('-') )
+ minusFound = true;
+ else if ( *input == wxT('+') )
+ minusFound = false;
+ else
+ return false; // no match
+
+ // here should follow 4 digits HHMM
+ ++input;
+ unsigned long tzHourMin;
+ if ( !GetNumericToken(4, input, end, &tzHourMin) )
+ return false; // no match
+
+ const unsigned hours = tzHourMin / 100;
+ const unsigned minutes = tzHourMin % 100;
+
+ if ( hours > 12 || minutes > 59 )
+ return false; // bad format
+
+ timeZone = 3600*hours + 60*minutes;
+ if ( minusFound )
+ timeZone = -timeZone;
+
+ haveTimeZone = true;
+ }
+ break;
+
case wxT('Z'): // timezone name
// FIXME: currently we just ignore everything that looks like a
// time zone here
Set(tm);
+ // If a time zone was specified and it is not the local time zone, we need
+ // to shift the time accordingly.
+ //
+ // Note that avoiding the call to MakeFromTimeZone is necessary to avoid
+ // DST problems.
+ if ( haveTimeZone && timeZone != -wxGetTimeZone() )
+ MakeFromTimezone(timeZone);
+
// finally check that the week day is consistent -- if we had it
if ( haveWDay && GetWeekDay() != wday )
return false;
while ( p != pEnd )
{
// skip white space and date delimiters
- while ( wxStrchr(".,/-\t\r\n ", *p) )
+ if ( wxStrchr(".,/-\t\r\n ", *p) )
{
++p;
+ continue;
}
// modify copy of the iterator as we're not sure if the next token is