+// test the computation of (ISO) week numbers
+static void TestTimeWNumber()
+{
+ puts("\n*** wxDateTime week number test ***");
+
+ struct WeekNumberTestData
+ {
+ Date date; // the date
+ wxDateTime::wxDateTime_t week; // the week number
+ wxDateTime::wxDateTime_t dnum; // day number in the year
+ };
+
+ // data generated with the following python script:
+ /*
+from DateTime import *
+from whrandom import *
+from string import *
+
+monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
+wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
+
+for n in range(20):
+ year = randint(1900, 2100)
+ month = randint(1, 12)
+ day = randint(1, 28)
+ dt = DateTime(year, month, day)
+ dayNum = dt.day_of_year
+ weekNum = dt.iso_week[1]
+
+ data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'dayNum': rjust(`dayNum`, 3) }
+
+ print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)s, "\
+ "%(dayNum)s }," % data
+ */
+ static const WeekNumberTestData weekNumberTestDates[] =
+ {
+ { { 2, wxDateTime::Jul, 2093 }, 27, 183 },
+ { { 25, wxDateTime::Jun, 1986 }, 26, 176 },
+ { { 15, wxDateTime::Jun, 2014 }, 24, 166 },
+ { { 20, wxDateTime::Jul, 2018 }, 29, 201 },
+ { { 3, wxDateTime::Aug, 2074 }, 31, 215 },
+ { { 26, wxDateTime::Jul, 2012 }, 30, 208 },
+ { { 4, wxDateTime::Nov, 1915 }, 44, 308 },
+ { { 11, wxDateTime::Feb, 2035 }, 6, 42 },
+ { { 15, wxDateTime::Feb, 1942 }, 7, 46 },
+ { { 5, wxDateTime::Jan, 2087 }, 1, 5 },
+ { { 6, wxDateTime::Nov, 2016 }, 44, 311 },
+ { { 6, wxDateTime::Jun, 2057 }, 23, 157 },
+ { { 25, wxDateTime::Feb, 1976 }, 9, 56 },
+ { { 12, wxDateTime::Jan, 2073 }, 2, 12 },
+ { { 12, wxDateTime::Sep, 2040 }, 37, 256 },
+ { { 15, wxDateTime::Jul, 1931 }, 29, 196 },
+ { { 23, wxDateTime::Mar, 2084 }, 12, 83 },
+ { { 12, wxDateTime::Dec, 1970 }, 50, 346 },
+ { { 6, wxDateTime::Sep, 1996 }, 36, 250 },
+ { { 7, wxDateTime::Jan, 2076 }, 2, 7 },
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(weekNumberTestDates); n++ )
+ {
+ const WeekNumberTestData& wn = weekNumberTestDates[n];
+ const Date& d = wn.date;
+
+ wxDateTime dt = d.DT();
+
+ wxDateTime::wxDateTime_t week = dt.GetWeekOfYear(),
+ dnum = dt.GetDayOfYear();
+
+ printf("%s: the day number is %d",
+ d.FormatDate().c_str(), dnum);
+ if ( dnum == wn.dnum )
+ {
+ printf(" (ok)");
+ }
+ else
+ {
+ printf(" (ERROR: should be %d)", wn.dnum);
+ }
+
+ printf(", week number is %d", week);
+ if ( week == wn.week )
+ {
+ puts(" (ok)");
+ }
+ else
+ {
+ printf(" (ERROR: should be %d)\n", wn.week);
+ }
+ }
+}
+
+// test DST calculations
+static void TestTimeDST()
+{
+ puts("\n*** wxDateTime DST test ***");
+
+ printf("DST is%s in effect now.\n\n",
+ wxDateTime::Now().IsDST() ? "" : " not");
+
+ // taken from http://www.energy.ca.gov/daylightsaving.html
+ static const Date datesDST[2][2004 - 1900 + 1] =
+ {
+ {
+ { 1, wxDateTime::Apr, 1990 },
+ { 7, wxDateTime::Apr, 1991 },
+ { 5, wxDateTime::Apr, 1992 },
+ { 4, wxDateTime::Apr, 1993 },
+ { 3, wxDateTime::Apr, 1994 },
+ { 2, wxDateTime::Apr, 1995 },
+ { 7, wxDateTime::Apr, 1996 },
+ { 6, wxDateTime::Apr, 1997 },
+ { 5, wxDateTime::Apr, 1998 },
+ { 4, wxDateTime::Apr, 1999 },
+ { 2, wxDateTime::Apr, 2000 },
+ { 1, wxDateTime::Apr, 2001 },
+ { 7, wxDateTime::Apr, 2002 },
+ { 6, wxDateTime::Apr, 2003 },
+ { 4, wxDateTime::Apr, 2004 },
+ },
+ {
+ { 28, wxDateTime::Oct, 1990 },
+ { 27, wxDateTime::Oct, 1991 },
+ { 25, wxDateTime::Oct, 1992 },
+ { 31, wxDateTime::Oct, 1993 },
+ { 30, wxDateTime::Oct, 1994 },
+ { 29, wxDateTime::Oct, 1995 },
+ { 27, wxDateTime::Oct, 1996 },
+ { 26, wxDateTime::Oct, 1997 },
+ { 25, wxDateTime::Oct, 1998 },
+ { 31, wxDateTime::Oct, 1999 },
+ { 29, wxDateTime::Oct, 2000 },
+ { 28, wxDateTime::Oct, 2001 },
+ { 27, wxDateTime::Oct, 2002 },
+ { 26, wxDateTime::Oct, 2003 },
+ { 31, wxDateTime::Oct, 2004 },
+ }
+ };
+
+ int year;
+ for ( year = 1990; year < 2005; year++ )
+ {
+ wxDateTime dtBegin = wxDateTime::GetBeginDST(year, wxDateTime::USA),
+ dtEnd = wxDateTime::GetEndDST(year, wxDateTime::USA);
+
+ printf("DST period in the US for year %d: from %s to %s",
+ year, dtBegin.Format().c_str(), dtEnd.Format().c_str());
+
+ size_t n = year - 1990;
+ const Date& dBegin = datesDST[0][n];
+ const Date& dEnd = datesDST[1][n];
+
+ if ( dBegin.SameDay(dtBegin.GetTm()) && dEnd.SameDay(dtEnd.GetTm()) )
+ {
+ puts(" (ok)");
+ }
+ else
+ {
+ printf(" (ERROR: should be %s %d to %s %d)\n",
+ wxDateTime::GetMonthName(dBegin.month).c_str(), dBegin.day,
+ wxDateTime::GetMonthName(dEnd.month).c_str(), dEnd.day);
+ }
+ }
+
+ puts("");
+
+ for ( year = 1990; year < 2005; year++ )
+ {
+ printf("DST period in Europe for year %d: from %s to %s\n",
+ year,
+ wxDateTime::GetBeginDST(year, wxDateTime::Country_EEC).Format().c_str(),
+ wxDateTime::GetEndDST(year, wxDateTime::Country_EEC).Format().c_str());
+ }
+}
+