// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
+// TODO: for $DEITY sake, someone please fix the #ifdef __WXWINCE__ everywhere,
+// the proper way to do it is to implement (subset of) wxStrftime() for
+// CE instead of this horror!!
+
/*
* Implementation notes:
*
#ifdef __WINDOWS__
#include "wx/msw/wrapwin.h"
#include <winnls.h>
- #include <locale.h>
+ #ifndef __WXWINCE__
+ #include <locale.h>
+ #endif
#endif
#include "wx/datetime.h"
- JDN_OFFSET;
}
+#ifndef __WXWINCE__
// this function is a wrapper around strftime(3) adding error checking
static wxString CallStrftime(const wxChar *format, const tm* tm)
{
wxChar buf[4096];
- if ( !wxStrftime(buf, WXSIZEOF(buf), format, tm) )
+ if ( !wxStrftime(buf, WXSIZEOF(buf), format, tm) )
{
// buffer is too small?
wxFAIL_MSG(_T("strftime() failed"));
return wxString(buf);
}
+#endif
#ifdef HAVE_STRPTIME
return CallStrftime(flags == Name_Abbr ? _T("%b") : _T("%B"), &tm);
#else
- wxString ret;
- switch(month)
- {
- case Jan:
- ret = (flags == Name_Abbr ? wxT("Jan"): wxT("January"));
- break;
- case Feb:
- ret = (flags == Name_Abbr ? wxT("Feb"): wxT("Febuary"));
- break;
- case Mar:
- ret = (flags == Name_Abbr ? wxT("Mar"): wxT("March"));
- break;
- case Apr:
- ret = (flags == Name_Abbr ? wxT("Apr"): wxT("April"));
- break;
- case May:
- ret = (flags == Name_Abbr ? wxT("May"): wxT("May"));
- break;
- case Jun:
- ret = (flags == Name_Abbr ? wxT("Jun"): wxT("June"));
- break;
- case Jul:
- ret = (flags == Name_Abbr ? wxT("Jul"): wxT("July"));
- break;
- case Aug:
- ret = (flags == Name_Abbr ? wxT("Aug"): wxT("August"));
- break;
- case Sep:
- ret = (flags == Name_Abbr ? wxT("Sep"): wxT("September"));
- break;
- case Oct:
- ret = (flags == Name_Abbr ? wxT("Oct"): wxT("October"));
- break;
- case Nov:
- ret = (flags == Name_Abbr ? wxT("Nov"): wxT("November"));
- break;
- case Dec:
- ret = (flags == Name_Abbr ? wxT("Dec"): wxT("December"));
- break;
- }
- return ret;
+ wxString ret;
+ switch(month)
+ {
+ case Jan:
+ ret = (flags == Name_Abbr ? wxT("Jan"): wxT("January"));
+ break;
+ case Feb:
+ ret = (flags == Name_Abbr ? wxT("Feb"): wxT("Febuary"));
+ break;
+ case Mar:
+ ret = (flags == Name_Abbr ? wxT("Mar"): wxT("March"));
+ break;
+ case Apr:
+ ret = (flags == Name_Abbr ? wxT("Apr"): wxT("April"));
+ break;
+ case May:
+ ret = (flags == Name_Abbr ? wxT("May"): wxT("May"));
+ break;
+ case Jun:
+ ret = (flags == Name_Abbr ? wxT("Jun"): wxT("June"));
+ break;
+ case Jul:
+ ret = (flags == Name_Abbr ? wxT("Jul"): wxT("July"));
+ break;
+ case Aug:
+ ret = (flags == Name_Abbr ? wxT("Aug"): wxT("August"));
+ break;
+ case Sep:
+ ret = (flags == Name_Abbr ? wxT("Sep"): wxT("September"));
+ break;
+ case Oct:
+ ret = (flags == Name_Abbr ? wxT("Oct"): wxT("October"));
+ break;
+ case Nov:
+ ret = (flags == Name_Abbr ? wxT("Nov"): wxT("November"));
+ break;
+ case Dec:
+ ret = (flags == Name_Abbr ? wxT("Dec"): wxT("December"));
+ break;
+ }
+ return ret;
#endif
}
// ... and call strftime()
return CallStrftime(flags == Name_Abbr ? _T("%a") : _T("%A"), &tm);
#else
- wxString ret;
- switch(wday)
- {
- case Sun:
- ret = (flags == Name_Abbr ? wxT("Sun") : wxT("Sunday"));
- break;
- case Mon:
- ret = (flags == Name_Abbr ? wxT("Mon") : wxT("Monday"));
- break;
- case Tue:
- ret = (flags == Name_Abbr ? wxT("Tue") : wxT("Tuesday"));
- break;
- case Wed:
- ret = (flags == Name_Abbr ? wxT("Wed") : wxT("Wednesday"));
- break;
- case Thu:
- ret = (flags == Name_Abbr ? wxT("Thu") : wxT("Thursday"));
- break;
- case Fri:
- ret = (flags == Name_Abbr ? wxT("Fri") : wxT("Friday"));
- break;
- case Sat:
- ret = (flags == Name_Abbr ? wxT("Sat") : wxT("Saturday"));
- break;
- }
- return ret;
+ wxString ret;
+ switch(wday)
+ {
+ case Sun:
+ ret = (flags == Name_Abbr ? wxT("Sun") : wxT("Sunday"));
+ break;
+ case Mon:
+ ret = (flags == Name_Abbr ? wxT("Mon") : wxT("Monday"));
+ break;
+ case Tue:
+ ret = (flags == Name_Abbr ? wxT("Tue") : wxT("Tuesday"));
+ break;
+ case Wed:
+ ret = (flags == Name_Abbr ? wxT("Wed") : wxT("Wednesday"));
+ break;
+ case Thu:
+ ret = (flags == Name_Abbr ? wxT("Thu") : wxT("Thursday"));
+ break;
+ case Fri:
+ ret = (flags == Name_Abbr ? wxT("Fri") : wxT("Friday"));
+ break;
+ case Sat:
+ ret = (flags == Name_Abbr ? wxT("Sat") : wxT("Saturday"));
+ break;
+ }
+ return ret;
#endif
}
// assert, even though it is a perfectly legal use.
if ( am )
{
- if (wxStrftime(buffer, sizeof buffer, _T("%p"), &tm) > 0)
+ if (wxStrftime(buffer, sizeof(buffer)/sizeof(wxChar), _T("%p"), &tm) > 0)
*am = wxString(buffer);
else
*am = wxString();
if ( pm )
{
tm.tm_hour = 13;
- if (wxStrftime(buffer, sizeof buffer, _T("%p"), &tm) > 0)
+ if (wxStrftime(buffer, sizeof(buffer)/sizeof(wxChar), _T("%p"), &tm) > 0)
*pm = wxString(buffer);
else
*pm = wxString();
jdn *= MILLISECONDS_PER_DAY;
+ m_time.Assign(jdn);
+
// JDNs always suppose an UTC date, so bring it back to local time zone
// (also see GetJulianDayNumber() implementation)
long tzDiff = GetTimeZone();
tzDiff -= 3600;
}
- jdn += tzDiff*1000; // tzDiff is in seconds
-
- m_time.Assign(jdn);
+ m_time += tzDiff*1000; // tzDiff is in seconds
return *this;
}
{
wxDATETIME_CHECK( weekday != Inv_WeekDay, _T("invalid weekday") );
- int wdayThis = GetWeekDay();
- if ( weekday == wdayThis )
+ int wdayDst = weekday,
+ wdayThis = GetWeekDay();
+ if ( wdayDst == wdayThis )
{
// nothing to do
return *this;
// the logic below based on comparing weekday and wdayThis works if Sun (0)
// is the first day in the week, but breaks down for Monday_First case so
// we adjust the week days in this case
- if( flags == Monday_First )
+ if ( flags == Monday_First )
{
if ( wdayThis == Sun )
wdayThis += 7;
+ if ( wdayDst == Sun )
+ wdayDst += 7;
}
//else: Sunday_First, nothing to do
// go forward or back in time to the day we want
- if ( weekday < wdayThis )
+ if ( wdayDst < wdayThis )
{
- return Subtract(wxDateSpan::Days(wdayThis - weekday));
+ return Subtract(wxDateSpan::Days(wdayThis - wdayDst));
}
else // weekday > wdayThis
{
- return Add(wxDateSpan::Days(weekday - wdayThis));
+ return Add(wxDateSpan::Days(wdayDst - wdayThis));
}
}
}
}
#ifndef __WXWINCE__
- //Windows CE doesn't support strftime or wcsftime, so we use the generic implementation
+ //Windows CE doesn't support strftime or wcsftime, so we use the generic implementation
if ( tm )
{
return CallStrftime(format, tm);
res += str;
}
#else
- //Use "%m/%d/%y %H:%M:%S" format instead
- res += wxString::Format(wxT("%02d/%02d/%04d %02d:%02d:%02d"),
- tm.mon+1,tm.mday, tm.year, tm.hour, tm.min, tm.sec);
+ //Use "%m/%d/%y %H:%M:%S" format instead
+ res += wxString::Format(wxT("%02d/%02d/%04d %02d:%02d:%02d"),
+ tm.mon+1,tm.mday, tm.year, tm.hour, tm.min, tm.sec);
#endif
break;
#ifndef __WXWINCE__
res += CallStrftime(_T("%p"), &tmTimeOnly);
#else
- res += (tmTimeOnly.tm_hour > 12) ? wxT("pm") : wxT("am");
+ res += (tmTimeOnly.tm_hour > 12) ? wxT("pm") : wxT("am");
#endif
break;
#ifndef __WXWINCE__
res += CallStrftime(_T("%X"), &tmTimeOnly);
#else
- res += wxString::Format(wxT("%02d:%02d:%02d"),tm.hour, tm.min, tm.sec);
+ res += wxString::Format(wxT("%02d:%02d:%02d"),tm.hour, tm.min, tm.sec);
#endif
break;
}
// and now the interesting part: the timezone
- int offset;
+ int offset wxDUMMY_INITIALIZE(0);
if ( *p == _T('-') || *p == _T('+') )
{
// the explicit offset given: it has the form of hhmm
}
#ifdef __WINDOWS__
+
// Get's current locale's date formatting string and stores it in fmt if
// the locale is set; otherwise or in case of failure, leaves fmt unchanged
-void GetLocaleDateFormat(wxString *fmt)
+static void GetLocaleDateFormat(wxString *fmt)
{
+ // there is no setlocale() under Windows CE, so just always query the
+ // system there
+#ifndef __WXWINCE__
if ( strcmp(setlocale(LC_ALL, NULL), "C") != 0 )
+#endif
{
// The locale was programatically set to non-C. We assume that this was
// done using wxLocale, in which case thread's current locale is also
// set to correct LCID value and we can use GetLocaleInfo to determine
// the correct formatting string:
+#ifdef __WXWINCE__
+ LCID lcid = LOCALE_USER_DEFAULT;
+#else
LCID lcid = GetThreadLocale();
+#endif
wxChar delim[5]; // fields deliminer, 4 chars max
if ( GetLocaleInfo(lcid, LOCALE_SDATE, delim, 5) )
{
// try our luck with the default set above
}
}
+
#endif // __WINDOWS__
const wxChar *wxDateTime::ParseFormat(const wxChar *date,
hour = tm.hour;
min = tm.min;
}
+ break;
case _T('S'): // second as a decimal number (00-61)
if ( !GetNumericToken(width, input, &num) || (num > 61) )