#include <wtime.h>
#endif
-#if !defined(WX_TIMEZONE) && !defined(WX_GMTOFF_IN_TM)
- #if defined(__WXPALMOS__)
- #define WX_GMTOFF_IN_TM
- #elif defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__)
- #define WX_TIMEZONE _timezone
- #elif defined(__MWERKS__)
- long wxmw_timezone = 28800;
- #define WX_TIMEZONE wxmw_timezone
- #elif defined(__DJGPP__) || defined(__WINE__)
- #include <sys/timeb.h>
- #include <values.h>
- static long wxGetTimeZone()
- {
- struct timeb tb;
- ftime(&tb);
- return tb.timezone;
- }
- #define WX_TIMEZONE wxGetTimeZone()
- #elif defined(__DARWIN__)
+#if defined(__DJGPP__) || defined(__WINE__)
+ #include <sys/timeb.h>
+ #include <values.h>
+#endif
+
+#ifndef WX_GMTOFF_IN_TM
+ // Define it for some systems which don't (always) use configure but are
+ // known to have tm_gmtoff field.
+ #if defined(__WXPALMOS__) || defined(__DARWIN__)
#define WX_GMTOFF_IN_TM
- #elif defined(__WXWINCE__) && defined(__VISUALC8__)
- // _timezone is not present in dynamic run-time library
- #if 0
- // Solution (1): use the function equivalent of _timezone
- static long wxGetTimeZone()
- {
- long t;
- _get_timezone(& t);
- return t;
- }
- #define WX_TIMEZONE wxGetTimeZone()
- #elif 1
- // Solution (2): using GetTimeZoneInformation
- static long wxGetTimeZone()
- {
- TIME_ZONE_INFORMATION tzi;
- ::GetTimeZoneInformation(&tzi);
- return tzi.Bias; // x 60
- }
- #define WX_TIMEZONE wxGetTimeZone()
- #else
- // Old method using _timezone: this symbol doesn't exist in the dynamic run-time library (i.e. using /MD)
- #define WX_TIMEZONE _timezone
- #endif
- #else // unknown platform - try timezone
- #define WX_TIMEZONE timezone
#endif
-#endif // !WX_TIMEZONE && !WX_GMTOFF_IN_TM
+#endif
// NB: VC8 safe time functions could/should be used for wxMSW as well probably
#if defined(__WXWINCE__) && defined(__VISUALC8__)
static const int MIN_PER_HOUR = 60;
-static const int HOURS_PER_DAY = 24;
-
static const long SECONDS_PER_DAY = 86400l;
static const int DAYS_PER_WEEK = 7;
gmtoffset = -tm.tm_gmtoff;
}
return (int)gmtoffset;
-#else // !WX_GMTOFF_IN_TM
+#elif defined(__DJGPP__) || defined(__WINE__)
+ struct timeb tb;
+ ftime(&tb);
+ return tb.timezone*60;
+#elif defined(__VISUALC__)
+ // We must initialize the time zone information before using it (this will
+ // be done only once internally).
+ _tzset();
+
+ // Starting with VC++ 8 timezone variable is deprecated and is not even
+ // available in some standard library version so use the new function for
+ // accessing it instead.
+ #if wxCHECK_VISUALC_VERSION(8)
+ long t;
+ _get_timezone(&t);
+ return t;
+ #else // VC++ < 8
+ return timezone;
+ #endif
+#elif defined(WX_TIMEZONE) // If WX_TIMEZONE was defined by configure, use it.
return WX_TIMEZONE;
+#elif defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__)
+ return _timezone;
+#elif defined(__MWERKS__)
+ return 28800;
+#else // unknown platform -- assume it has timezone
+ return timezone;
#endif // WX_GMTOFF_IN_TM/!WX_GMTOFF_IN_TM
}
{
year = (wxDateTime_t)wxDateTime::Inv_Year;
mon = wxDateTime::Inv_Month;
- mday = 0;
- hour = min = sec = msec = 0;
+ mday =
+ yday = 0;
+ hour =
+ min =
+ sec =
+ msec = 0;
wday = wxDateTime::Inv_WeekDay;
}
bool wxDateTime::Tm::IsValid() const
{
+ if ( mon == wxDateTime::Inv_Month )
+ return false;
+
+ // We need to check this here to avoid crashing in GetNumOfDaysInMonth() if
+ // somebody passed us "(wxDateTime::Month)1000".
+ wxCHECK_MSG( mon >= wxDateTime::Jan && mon < wxDateTime::Inv_Month, false,
+ wxS("Invalid month value") );
+
// we allow for the leap seconds, although we don't use them (yet)
return (year != wxDateTime::Inv_Year) && (mon != wxDateTime::Inv_Month) &&
- (mday <= GetNumOfDaysInMonth(year, mon)) &&
+ (mday > 0 && mday <= GetNumOfDaysInMonth(year, mon)) &&
(hour < 24) && (min < 60) && (sec < 62) && (msec < 1000);
}
// construct Tm from these values
Tm tm;
tm.year = (int)year;
+ tm.yday = (wxDateTime_t)(dayOfYear - 1); // use C convention for day number
tm.mon = (Month)(month - 1); // algorithm yields 1 for January, not 0
tm.mday = (wxDateTime_t)day;
tm.msec = (wxDateTime_t)(timeOnly % 1000);
const TimeZone& tz) const
{
Tm tm = GetTm(tz);
- wxDateTime dtMonthStart = wxDateTime(1, tm.mon, tm.year);
- int nWeek = GetWeekOfYear(flags) - dtMonthStart.GetWeekOfYear(flags) + 1;
- if ( nWeek < 0 )
+ const wxDateTime dateFirst = wxDateTime(1, tm.mon, tm.year);
+ const wxDateTime::WeekDay wdFirst = dateFirst.GetWeekDay();
+
+ if ( flags == Default_First )
{
- // this may happen for January when Jan, 1 is the last week of the
- // previous year
- nWeek += IsLeapYear(tm.year - 1) ? 53 : 52;
+ flags = GetCountry() == USA ? Sunday_First : Monday_First;
}
- return (wxDateTime::wxDateTime_t)nWeek;
+ // compute offset of dateFirst from the beginning of the week
+ int firstOffset;
+ if ( flags == Sunday_First )
+ firstOffset = wdFirst - Sun;
+ else
+ firstOffset = wdFirst == Sun ? DAYS_PER_WEEK - 1 : wdFirst - Mon;
+
+ return (wxDateTime::wxDateTime_t)((tm.mday - 1 + firstOffset)/7 + 1);
}
wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday)
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
}
+wxDateTime& wxDateTime::SetFromMSWSysDate(const SYSTEMTIME& st)
+{
+ return Set(st.wDay,
+ static_cast<wxDateTime::Month>(wxDateTime::Jan + st.wMonth - 1),
+ st.wYear,
+ 0, 0, 0, 0);
+}
+
void wxDateTime::GetAsMSWSysTime(SYSTEMTIME* st) const
{
const wxDateTime::Tm tm(GetTm());
st->wSecond = tm.sec;
st->wMilliseconds = tm.msec;
}
+
+void wxDateTime::GetAsMSWSysDate(SYSTEMTIME* st) const
+{
+ const wxDateTime::Tm tm(GetTm());
+
+ st->wYear = (WXWORD)tm.year;
+ st->wMonth = (WXWORD)(tm.mon - wxDateTime::Jan + 1);
+ st->wDay = tm.mday;
+
+ st->wDayOfWeek =
+ st->wHour =
+ st->wMinute =
+ st->wSecond =
+ st->wMilliseconds = 0;
+}
+
#endif // __WXMSW__
#endif // wxUSE_DATETIME