1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/datetime/datetime.cpp
3 // Purpose: wxDateTime unit test
4 // Author: Vadim Zeitlin
5 // Created: 2004-06-23 (extracted from samples/console/console.cpp)
7 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
25 #include "wx/wxcrt.h" // for wxStrstr()
29 // to test Today() meaningfully we must be able to change the system date which
30 // is not usually the case, but if we're under Win32 we can try it -- define
31 // the macro below to do it
32 //#define CHANGE_SYSTEM_DATE
35 #undef CHANGE_SYSTEM_DATE
38 #ifdef CHANGE_SYSTEM_DATE
43 DateChanger(int year
, int month
, int day
, int hour
, int min
, int sec
)
54 ::GetSystemTime(&m_savedTime
);
55 ::GetTimeZoneInformation(&m_tzi
);
57 m_changed
= ::SetSystemTime(&st
) != 0;
64 ::SetSystemTime(&m_savedTime
);
65 ::SetTimeZoneInformation(&m_tzi
);
70 SYSTEMTIME m_savedTime
;
71 TIME_ZONE_INFORMATION m_tzi
;
75 #endif // CHANGE_SYSTEM_DATE
77 // helper function translating week day/month names from English to the current
79 static wxString
TranslateDate(const wxString
& str
)
81 // small optimization: if there are no alphabetic characters in the string,
82 // there is nothing to translate
83 wxString::const_iterator i
, end
= str
.end();
84 for ( i
= str
.begin(); i
!= end
; ++i
)
95 for ( wxDateTime::WeekDay wd
= wxDateTime::Sun
;
96 wd
< wxDateTime::Inv_WeekDay
;
101 wxDateTime::GetEnglishWeekDayName(wd
, wxDateTime::Name_Abbr
),
102 wxDateTime::GetWeekDayName(wd
, wxDateTime::Name_Abbr
)
106 for ( wxDateTime::Month mon
= wxDateTime::Jan
;
107 mon
< wxDateTime::Inv_Month
;
112 wxDateTime::GetEnglishMonthName(mon
, wxDateTime::Name_Abbr
),
113 wxDateTime::GetMonthName(mon
, wxDateTime::Name_Abbr
)
120 // ----------------------------------------------------------------------------
121 // broken down date representation used for testing
122 // ----------------------------------------------------------------------------
126 wxDateTime::wxDateTime_t day
;
127 wxDateTime::Month month
;
129 wxDateTime::wxDateTime_t hour
, min
, sec
;
131 wxDateTime::WeekDay wday
;
134 void Init(const wxDateTime::Tm
& tm
)
146 wxDateTime
DT() const
147 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
149 bool SameDay(const wxDateTime::Tm
& tm
) const
151 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
154 wxString
Format() const
157 s
.Printf(wxT("%02d:%02d:%02d %10s %02d, %4d%s"),
159 wxDateTime::GetMonthName(month
).c_str(),
161 abs(wxDateTime::ConvertYearToBC(year
)),
162 year
> 0 ? wxT("AD") : wxT("BC"));
166 wxString
FormatDate() const
169 s
.Printf(wxT("%02d-%s-%4d%s"),
171 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
172 abs(wxDateTime::ConvertYearToBC(year
)),
173 year
> 0 ? wxT("AD") : wxT("BC"));
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 static const Date testDates
[] =
184 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0 },
185 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1 },
186 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1 },
187 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1 },
188 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1 },
189 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1 },
190 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200 },
191 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000 },
192 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1 },
193 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1 },
194 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1 },
195 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1 },
196 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1 },
197 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1 },
198 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1 },
199 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1 },
200 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1 },
201 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1 },
202 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1 },
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 class DateTimeTestCase
: public CppUnit::TestCase
213 DateTimeTestCase() { }
216 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
217 CPPUNIT_TEST( TestLeapYears
);
218 CPPUNIT_TEST( TestTimeSet
);
219 CPPUNIT_TEST( TestTimeJDN
);
220 CPPUNIT_TEST( TestTimeWNumber
);
221 CPPUNIT_TEST( TestTimeWDays
);
222 CPPUNIT_TEST( TestTimeDST
);
223 CPPUNIT_TEST( TestTimeFormat
);
224 CPPUNIT_TEST( TestTimeSpanFormat
);
225 CPPUNIT_TEST( TestTimeTicks
);
226 CPPUNIT_TEST( TestParceRFC822
);
227 CPPUNIT_TEST( TestDateParse
);
228 CPPUNIT_TEST( TestDateParseISO
);
229 CPPUNIT_TEST( TestDateTimeParse
);
230 CPPUNIT_TEST( TestTimeArithmetics
);
231 CPPUNIT_TEST( TestDSTBug
);
232 CPPUNIT_TEST( TestDateOnly
);
233 CPPUNIT_TEST_SUITE_END();
235 void TestLeapYears();
238 void TestTimeWNumber();
239 void TestTimeWDays();
241 void TestTimeFormat();
242 void TestTimeSpanFormat();
243 void TestTimeTicks();
244 void TestParceRFC822();
245 void TestDateParse();
246 void TestDateParseISO();
247 void TestDateTimeParse();
248 void TestTimeArithmetics();
252 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
255 // register in the unnamed registry so that these tests are run by default
256 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
258 // also include in its own registry so that these tests can be run alone
259 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
261 // ============================================================================
263 // ============================================================================
265 // test leap years detection
266 void DateTimeTestCase::TestLeapYears()
268 static const struct LeapYearTestData
284 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
286 const LeapYearTestData
& y
= years
[n
];
288 CPPUNIT_ASSERT_EQUAL( y
.isLeap
, wxDateTime::IsLeapYear(y
.year
) );
292 // test constructing wxDateTime objects
293 void DateTimeTestCase::TestTimeSet()
295 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
297 const Date
& d1
= testDates
[n
];
298 wxDateTime dt
= d1
.DT();
303 wxString s1
= d1
.Format(),
306 CPPUNIT_ASSERT_EQUAL( s1
, s2
);
310 // test conversions to JDN &c
311 void DateTimeTestCase::TestTimeJDN()
313 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
315 const Date
& d
= testDates
[n
];
316 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
318 // JDNs must be computed for UTC times
319 double jdn
= dt
.FromUTC().GetJulianDayNumber();
321 CPPUNIT_ASSERT_EQUAL( d
.jdn
, jdn
);
324 CPPUNIT_ASSERT_EQUAL( jdn
, dt
.GetJulianDayNumber() );
328 // test week days computation
329 void DateTimeTestCase::TestTimeWDays()
333 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
335 const Date
& d
= testDates
[n
];
336 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
338 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
339 CPPUNIT_ASSERT_EQUAL( d
.wday
, wday
);
342 // test SetToWeekDay()
343 struct WeekDateTestData
345 Date date
; // the real date (precomputed)
346 int nWeek
; // its week index in the month
347 wxDateTime::WeekDay wday
; // the weekday
348 wxDateTime::Month month
; // the month
349 int year
; // and the year
351 wxString
Format() const
354 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
356 case 1: which
= wxT("first"); break;
357 case 2: which
= wxT("second"); break;
358 case 3: which
= wxT("third"); break;
359 case 4: which
= wxT("fourth"); break;
360 case 5: which
= wxT("fifth"); break;
362 case -1: which
= wxT("last"); break;
367 which
+= wxT(" from end");
370 s
.Printf(wxT("The %s %s of %s in %d"),
372 wxDateTime::GetWeekDayName(wday
).c_str(),
373 wxDateTime::GetMonthName(month
).c_str(),
380 // the array data was generated by the following python program
382 from DateTime import *
383 from whrandom import *
386 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
387 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
389 week = DateTimeDelta(7)
392 year = randint(1900, 2100)
393 month = randint(1, 12)
395 dt = DateTime(year, month, day)
396 wday = dt.day_of_week
398 countFromEnd = choice([-1, 1])
401 while dt.month is month:
402 dt = dt - countFromEnd * week
403 weekNum = weekNum + countFromEnd
405 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
407 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
408 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
411 static const WeekDateTestData weekDatesTestData
[] =
413 { { 20, wxDateTime::Mar
, 2045, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
414 { { 5, wxDateTime::Jun
, 1985, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
415 { { 12, wxDateTime::Nov
, 1961, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
416 { { 27, wxDateTime::Feb
, 2093, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
417 { { 4, wxDateTime::Jul
, 2070, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
418 { { 2, wxDateTime::Apr
, 1906, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
419 { { 19, wxDateTime::Jul
, 2023, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
420 { { 5, wxDateTime::May
, 1958, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
421 { { 11, wxDateTime::Aug
, 1900, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
422 { { 14, wxDateTime::Feb
, 1945, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
423 { { 25, wxDateTime::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
424 { { 9, wxDateTime::May
, 1916, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
425 { { 20, wxDateTime::Jun
, 1927, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
426 { { 2, wxDateTime::Aug
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
427 { { 20, wxDateTime::Apr
, 2044, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
428 { { 20, wxDateTime::Feb
, 1932, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
429 { { 25, wxDateTime::Jul
, 2069, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
430 { { 3, wxDateTime::Apr
, 1925, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
431 { { 21, wxDateTime::Mar
, 2093, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
432 { { 3, wxDateTime::Dec
, 2074, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 }
436 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
438 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
440 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
442 const Date
& d
= wd
.date
;
443 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
447 // test the computation of (ISO) week numbers
448 void DateTimeTestCase::TestTimeWNumber()
450 struct WeekNumberTestData
452 Date date
; // the date
453 wxDateTime::wxDateTime_t week
; // the week number in the year
454 wxDateTime::wxDateTime_t wmon
; // the week number in the month
455 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
456 wxDateTime::wxDateTime_t dnum
; // day number in the year
459 // data generated with the following python script:
461 from DateTime import *
462 from whrandom import *
465 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
466 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
468 def GetMonthWeek(dt):
469 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
471 weekNumMonth = weekNumMonth + 53
474 def GetLastSundayBefore(dt):
475 if dt.iso_week[2] == 7:
478 return dt - DateTimeDelta(dt.iso_week[2])
481 year = randint(1900, 2100)
482 month = randint(1, 12)
484 dt = DateTime(year, month, day)
485 dayNum = dt.day_of_year
486 weekNum = dt.iso_week[1]
487 weekNumMonth = GetMonthWeek(dt)
490 dtSunday = GetLastSundayBefore(dt)
492 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
493 weekNumMonth2 = weekNumMonth2 + 1
494 dtSunday = dtSunday - DateTimeDelta(7)
496 data = { 'day': rjust(`day`, 2), \
497 'month': monthNames[month - 1], \
499 'weekNum': rjust(`weekNum`, 2), \
500 'weekNumMonth': weekNumMonth, \
501 'weekNumMonth2': weekNumMonth2, \
502 'dayNum': rjust(`dayNum`, 3) }
504 print " { { %(day)s, "\
505 "wxDateTime::%(month)s, "\
508 "%(weekNumMonth)s, "\
509 "%(weekNumMonth2)s, "\
510 "%(dayNum)s }," % data
513 static const WeekNumberTestData weekNumberTestDates
[] =
515 { { 27, wxDateTime::Dec
, 1966, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 52, 5, 5, 361 },
516 { { 22, wxDateTime::Jul
, 1926, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 29, 4, 4, 203 },
517 { { 22, wxDateTime::Oct
, 2076, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 43, 4, 4, 296 },
518 { { 1, wxDateTime::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 26, 1, 1, 182 },
519 { { 8, wxDateTime::Nov
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 46, 2, 2, 313 },
520 { { 21, wxDateTime::Mar
, 1920, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 12, 3, 4, 81 },
521 { { 7, wxDateTime::Jan
, 1965, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 7 },
522 { { 19, wxDateTime::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 42, 4, 4, 292 },
523 { { 13, wxDateTime::Aug
, 1955, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 32, 2, 2, 225 },
524 { { 18, wxDateTime::Jul
, 2087, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 29, 3, 3, 199 },
525 { { 2, wxDateTime::Sep
, 2028, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 35, 1, 1, 246 },
526 { { 28, wxDateTime::Jul
, 1945, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 30, 5, 4, 209 },
527 { { 15, wxDateTime::Jun
, 1901, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 24, 3, 3, 166 },
528 { { 10, wxDateTime::Oct
, 1939, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 41, 3, 2, 283 },
529 { { 3, wxDateTime::Dec
, 1965, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 48, 1, 1, 337 },
530 { { 23, wxDateTime::Feb
, 1940, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 8, 4, 4, 54 },
531 { { 2, wxDateTime::Jan
, 1987, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
532 { { 11, wxDateTime::Aug
, 2079, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 32, 2, 2, 223 },
533 { { 2, wxDateTime::Feb
, 2063, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 5, 1, 1, 33 },
534 { { 16, wxDateTime::Oct
, 1942, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 42, 3, 3, 289 },
535 { { 30, wxDateTime::Dec
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 5, 5, 364 },
536 { { 2, wxDateTime::Jan
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
537 { { 5, wxDateTime::Jan
, 2010, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 5 },
538 { { 3, wxDateTime::Jan
, 2011, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 3 },
541 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
543 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
544 const Date
& d
= wn
.date
;
546 wxDateTime dt
= d
.DT();
548 wxDateTime::wxDateTime_t
549 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
550 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
551 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
552 dnum
= dt
.GetDayOfYear();
554 WX_ASSERT_EQUAL_MESSAGE( ("day of year for %s", d
.Format()),
556 WX_ASSERT_EQUAL_MESSAGE( ("week of month (Monday) for %s", d
.Format()),
558 WX_ASSERT_EQUAL_MESSAGE( ("week of month (Sunday) for %s", d
.Format()),
560 WX_ASSERT_EQUAL_MESSAGE( ("week of year for %s", d
.Format()),
564 if ( week
== 1 && d
.month
!= wxDateTime::Jan
)
566 // this means we're in the first week of the next year
571 dt2
= wxDateTime::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
572 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
576 // test DST applicability
577 void DateTimeTestCase::TestTimeDST()
579 // taken from http://www.energy.ca.gov/daylightsaving.html
580 static const Date datesDST
[2][2009 - 1990 + 1] =
583 { 1, wxDateTime::Apr
, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
584 { 7, wxDateTime::Apr
, 1991, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
585 { 5, wxDateTime::Apr
, 1992, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
586 { 4, wxDateTime::Apr
, 1993, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
587 { 3, wxDateTime::Apr
, 1994, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
588 { 2, wxDateTime::Apr
, 1995, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
589 { 7, wxDateTime::Apr
, 1996, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
590 { 6, wxDateTime::Apr
, 1997, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
591 { 5, wxDateTime::Apr
, 1998, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
592 { 4, wxDateTime::Apr
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
593 { 2, wxDateTime::Apr
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
594 { 1, wxDateTime::Apr
, 2001, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
595 { 7, wxDateTime::Apr
, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
596 { 6, wxDateTime::Apr
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
597 { 4, wxDateTime::Apr
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
598 { 3, wxDateTime::Apr
, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
599 { 2, wxDateTime::Apr
, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
600 {11, wxDateTime::Mar
, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
601 { 9, wxDateTime::Mar
, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
602 { 8, wxDateTime::Mar
, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
605 { 28, wxDateTime::Oct
, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
606 { 27, wxDateTime::Oct
, 1991, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
607 { 25, wxDateTime::Oct
, 1992, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
608 { 31, wxDateTime::Oct
, 1993, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
609 { 30, wxDateTime::Oct
, 1994, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
610 { 29, wxDateTime::Oct
, 1995, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
611 { 27, wxDateTime::Oct
, 1996, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
612 { 26, wxDateTime::Oct
, 1997, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
613 { 25, wxDateTime::Oct
, 1998, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
614 { 31, wxDateTime::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
615 { 29, wxDateTime::Oct
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
616 { 28, wxDateTime::Oct
, 2001, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
617 { 27, wxDateTime::Oct
, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
618 { 26, wxDateTime::Oct
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
619 { 31, wxDateTime::Oct
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
620 { 30, wxDateTime::Oct
, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
621 { 29, wxDateTime::Oct
, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
622 { 4, wxDateTime::Nov
, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
623 { 2, wxDateTime::Nov
, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
624 { 1, wxDateTime::Nov
, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
629 for ( size_t n
= 0; n
< WXSIZEOF(datesDST
[0]); n
++ )
631 const int year
= 1990 + n
;
632 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
633 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
635 const Date
& dBegin
= datesDST
[0][n
];
636 const Date
& dEnd
= datesDST
[1][n
];
638 CPPUNIT_ASSERT_EQUAL( dBegin
.DT().FormatDate(), dtBegin
.FormatDate() );
639 CPPUNIT_ASSERT_EQUAL( dEnd
.DT().FormatDate(), dtEnd
.FormatDate() );
643 // test wxDateTime -> text conversion
644 void DateTimeTestCase::TestTimeFormat()
646 // some information may be lost during conversion, so store what kind
647 // of info should we recover after a round trip
650 CompareNone
, // don't try comparing
651 CompareBoth
, // dates and times should be identical
652 CompareYear
, // don't compare centuries (fails for 2 digit years)
653 CompareDate
, // dates only
654 CompareTime
// time only
659 CompareKind compareKind
;
661 } formatTestFormats
[] =
663 { CompareYear
, "---> %c" }, // %c could use 2 digit years
664 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
665 { CompareYear
, "Date is %x, time is %X" }, // %x could use 2 digits
666 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
667 { CompareNone
, "The day of year: %j, the week of year: %W" },
668 { CompareDate
, "ISO date without separators: %Y%m%d" },
671 static const Date formatTestDates
[] =
673 { 29, wxDateTime::May
, 1976, 18, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
674 { 31, wxDateTime::Dec
, 1999, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
675 { 6, wxDateTime::Feb
, 1937, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
676 { 6, wxDateTime::Feb
, 1856, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
677 { 6, wxDateTime::Feb
, 1857, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
678 { 29, wxDateTime::May
, 2076, 18, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
680 // FIXME: the test with 02:15:25 time doesn't pass because of DST
681 // computation problems, we get back 03:15:25
682 { 29, wxDateTime::Feb
, 2400, 04, 15, 25, 0.0, wxDateTime::Inv_WeekDay
},
684 // Need to add support for BCE dates.
685 { 01, wxDateTime::Jan
, -52, 03, 16, 47, 0.0, wxDateTime::Inv_WeekDay
},
689 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
); d
++ )
691 wxDateTime dt
= formatTestDates
[d
].DT();
692 for ( unsigned n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
694 const char *fmt
= formatTestFormats
[n
].format
;
696 // skip the check with %p for those locales which have empty AM/PM strings:
697 // for those locales it's impossible to pass the test with %p...
699 wxDateTime::GetAmPmStrings(&am
, &pm
);
700 if (am
.empty() && pm
.empty() && wxStrstr(fmt
, "%p") != NULL
)
703 wxString s
= dt
.Format(fmt
);
705 // what can we recover?
706 CompareKind kind
= formatTestFormats
[n
].compareKind
;
710 const char *result
= dt2
.ParseFormat(s
, fmt
);
713 // conversion failed - should it have?
715 ("Test #%u failed: failed to parse \"%s\"", n
, s
),
719 else // conversion succeeded
721 // currently ParseFormat() doesn't support "%Z" and so is
722 // incapable of parsing time zone part used at the end of date
723 // representations in many (but not "C") locales, compensate
724 // for it ourselves by simply consuming and ignoring it
725 while ( *result
&& (*result
>= 'A' && *result
<= 'Z') )
729 ("Test #%u failed: \"%s\" was left unparsed in \"%s\"",
737 if ( dt2
.GetCentury() != dt
.GetCentury() )
739 CPPUNIT_ASSERT_EQUAL(dt
.GetYear() % 100,
740 dt2
.GetYear() % 100);
742 dt2
.SetYear(dt
.GetYear());
744 // fall through and compare everything
747 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
751 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
755 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
759 wxFAIL_MSG( wxT("unexpected") );
769 // special case which was known to fail
770 CPPUNIT_ASSERT( dt
.ParseFormat("02/06/1856", "%x") );
771 CPPUNIT_ASSERT_EQUAL( 1856, dt
.GetYear() );
774 // also test %l separately
775 CPPUNIT_ASSERT( dt
.ParseFormat("12:23:45.678", "%H:%M:%S.%l") );
776 CPPUNIT_ASSERT_EQUAL( 678, dt
.GetMillisecond() );
778 // test special case of %l matching 0 milliseconds
779 CPPUNIT_ASSERT( dt
.ParseFormat("12:23:45.000", "%H:%M:%S.%l") );
780 CPPUNIT_ASSERT_EQUAL( 0, dt
.GetMillisecond() );
782 // test partially specified dates too
783 wxDateTime
dtDef(26, wxDateTime::Sep
, 2008);
784 CPPUNIT_ASSERT( dt
.ParseFormat("17", "%d") );
785 CPPUNIT_ASSERT_EQUAL( 17, dt
.GetDay() );
787 // test compilation of some calls which should compile (and not result in
788 // ambiguity because of char*<->wxCStrData<->wxString conversions)
790 CPPUNIT_ASSERT( !dt
.ParseFormat("foo") );
791 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo")) );
792 CPPUNIT_ASSERT( !dt
.ParseFormat(s
) );
793 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str()) );
795 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", "%c") );
796 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), "%c") );
797 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
798 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), "%c") );
800 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", wxT("%c")) );
801 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), wxT("%c")) );
802 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
803 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), wxT("%c")) );
806 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", spec
) );
807 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), spec
) );
808 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, spec
) );
809 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), spec
) );
812 void DateTimeTestCase::TestTimeSpanFormat()
814 static const struct TimeSpanFormatTestData
816 long h
, min
, sec
, msec
;
821 { 12, 34, 56, 789, "%H:%M:%S.%l", "12:34:56.789" },
822 { 1, 2, 3, 0, "%H:%M:%S", "01:02:03" },
823 { 1, 2, 3, 0, "%S", "3723" },
824 { -1, -2, -3, 0, "%S", "-3723" },
825 { -1, -2, -3, 0, "%H:%M:%S", "-01:02:03" },
826 { 26, 0, 0, 0, "%H", "26" },
827 { 26, 0, 0, 0, "%D, %H", "1, 02" },
828 { -26, 0, 0, 0, "%H", "-26" },
829 { -26, 0, 0, 0, "%D, %H", "-1, 02" },
830 { 219, 0, 0, 0, "%H", "219" },
831 { 219, 0, 0, 0, "%D, %H", "9, 03" },
832 { 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
833 { 0, -1, 0, 0, "%H:%M:%S", "-00:01:00" },
834 { 0, 0, -1, 0, "%H:%M:%S", "-00:00:01" },
837 for ( size_t n
= 0; n
< WXSIZEOF(testSpans
); n
++ )
839 const TimeSpanFormatTestData
& td
= testSpans
[n
];
840 wxTimeSpan
ts(td
.h
, td
.min
, td
.sec
, td
.msec
);
841 CPPUNIT_ASSERT_EQUAL( td
.result
, ts
.Format(td
.fmt
) );
845 void DateTimeTestCase::TestTimeTicks()
847 static const wxDateTime::TimeZone
TZ_LOCAL(wxDateTime::Local
);
848 static const wxDateTime::TimeZone
TZ_TEST(wxDateTime::NZST
);
850 // this offset is needed to make the test work in any time zone when we
851 // only have expected test results in UTC in testDates
852 static const long tzOffset
= TZ_LOCAL
.GetOffset() - TZ_TEST
.GetOffset();
854 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
856 const Date
& d
= testDates
[n
];
857 if ( d
.gmticks
== -1 )
860 wxDateTime dt
= d
.DT().MakeTimezone(TZ_TEST
, true /* no DST */);
862 // GetValue() returns internal UTC-based representation, we need to
863 // convert it to local TZ before comparing
864 time_t ticks
= (dt
.GetValue() / 1000).ToLong() + TZ_LOCAL
.GetOffset();
867 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
+ tzOffset
);
869 dt
= d
.DT().FromTimezone(wxDateTime::UTC
);
870 ticks
= (dt
.GetValue() / 1000).ToLong();
871 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
);
875 // test parsing dates in RFC822 format
876 void DateTimeTestCase::TestParceRFC822()
878 static const struct ParseTestData
881 Date date
; // NB: this should be in UTC
886 "Sat, 18 Dec 1999 00:46:40 +0100",
887 { 17, wxDateTime::Dec
, 1999, 23, 46, 40 },
891 "Wed, 1 Dec 1999 05:17:20 +0300",
892 { 1, wxDateTime::Dec
, 1999, 2, 17, 20 },
896 "Sun, 28 Aug 2005 03:31:30 +0200",
897 { 28, wxDateTime::Aug
, 2005, 1, 31, 30 },
902 "Sat, 18 Dec 1999 10:48:30 -0500",
903 { 18, wxDateTime::Dec
, 1999, 15, 48, 30 },
907 // seconds are optional according to the RFC
909 "Sun, 01 Jun 2008 16:30 +0200",
910 { 1, wxDateTime::Jun
, 2008, 14, 30, 00 },
914 // try some bogus ones too
916 "Sun, 01 Jun 2008 16:30: +0200",
922 for ( unsigned n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
924 const char * const datestr
= parseTestDates
[n
].rfc822
;
927 if ( dt
.ParseRfc822Date(datestr
) )
930 ("Erroneously parsed \"%s\"", datestr
),
931 parseTestDates
[n
].good
934 wxDateTime dtReal
= parseTestDates
[n
].date
.DT().FromUTC();
935 CPPUNIT_ASSERT_EQUAL( dtReal
, dt
);
937 else // failed to parse
940 ("Failed to parse \"%s\"", datestr
),
941 !parseTestDates
[n
].good
947 // test parsing dates in free format
948 void DateTimeTestCase::TestDateParse()
950 static const struct ParseTestData
953 Date date
; // NB: this should be in UTC
957 { "21 Mar 2006", { 21, wxDateTime::Mar
, 2006 }, true },
958 { "29 Feb 1976", { 29, wxDateTime::Feb
, 1976 }, true },
959 { "Feb 29 1976", { 29, wxDateTime::Feb
, 1976 }, true },
960 { "31/03/06", { 31, wxDateTime::Mar
, 6 }, true },
961 { "31/03/2006", { 31, wxDateTime::Mar
, 2006 }, true },
963 // some invalid ones too
972 CPPUNIT_ASSERT( dt
.ParseDate(wxT("today")) );
973 CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), dt
);
975 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
977 const wxString datestr
= TranslateDate(parseTestDates
[n
].str
);
979 const char * const end
= dt
.ParseDate(datestr
);
983 ("Erroneously parsed \"%s\"", datestr
),
984 parseTestDates
[n
].good
987 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
989 else // failed to parse
992 ("Failed to parse \"%s\"", datestr
),
993 !parseTestDates
[n
].good
999 void DateTimeTestCase::TestDateParseISO()
1004 Date date
; // NB: this should be in UTC
1006 } parseTestDates
[] =
1008 { "2006-03-21", { 21, wxDateTime::Mar
, 2006 }, true },
1009 { "1976-02-29", { 29, wxDateTime::Feb
, 1976 }, true },
1010 { "0006-03-31", { 31, wxDateTime::Mar
, 6 }, true },
1012 // some invalid ones too
1022 wxDateTime::wxDateTime_t hour
, min
, sec
;
1024 } parseTestTimes
[] =
1026 { "13:42:17", 13, 42, 17, true },
1027 { "02:17:01", 2, 17, 1, true },
1029 // some invalid ones too
1036 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1039 if ( dt
.ParseISODate(parseTestDates
[n
].str
) )
1041 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
1043 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1045 for ( size_t m
= 0; m
< WXSIZEOF(parseTestTimes
); m
++ )
1047 wxString dtCombined
;
1048 dtCombined
<< parseTestDates
[n
].str
1050 << parseTestTimes
[m
].str
;
1052 if ( dt
.ParseISOCombined(dtCombined
) )
1054 CPPUNIT_ASSERT( parseTestTimes
[m
].good
);
1056 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].hour
, dt
.GetHour()) ;
1057 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].min
, dt
.GetMinute()) ;
1058 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].sec
, dt
.GetSecond()) ;
1060 else // failed to parse combined date/time
1062 CPPUNIT_ASSERT( !parseTestTimes
[m
].good
);
1066 else // failed to parse
1068 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1073 void DateTimeTestCase::TestDateTimeParse()
1075 static const struct ParseTestData
1078 Date date
; // NB: this should be in UTC
1080 } parseTestDates
[] =
1083 "Thu 22 Nov 2007 07:40:00 PM",
1084 { 22, wxDateTime::Nov
, 2007, 19, 40, 0 },
1090 { 4, wxDateTime::Jan
, 2010, 14, 30, 0 },
1096 { 1, wxDateTime::Jan
, 9999, 0, 0, 0},
1101 // the test strings here use "PM" which is not available in all locales so
1102 // we need to use "C" locale for them
1106 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1108 const wxString datestr
= TranslateDate(parseTestDates
[n
].str
);
1110 const char * const end
= dt
.ParseDateTime(datestr
);
1114 ("Erroneously parsed \"%s\"", datestr
),
1115 parseTestDates
[n
].good
1118 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1120 else // failed to parse
1123 ("Failed to parse \"%s\"", datestr
),
1124 !parseTestDates
[n
].good
1127 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1132 void DateTimeTestCase::TestTimeArithmetics()
1134 static const wxDateSpan testArithmData
[] =
1138 wxDateSpan::Month(),
1142 // the test will *not* work with arbitrary date!
1143 wxDateTime
dt(2, wxDateTime::Dec
, 1999),
1147 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
1149 const wxDateSpan
& span
= testArithmData
[n
];
1153 CPPUNIT_ASSERT_EQUAL( dt
, dt1
- span
);
1154 CPPUNIT_ASSERT_EQUAL( dt
, dt2
+ span
);
1155 CPPUNIT_ASSERT_EQUAL( dt1
, dt2
+ 2*span
);
1159 void DateTimeTestCase::TestDSTBug()
1161 /////////////////////////
1163 wxDateTime dt
= wxDateTime::GetEndDST(2004, wxDateTime::France
);
1164 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1165 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1166 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1167 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1168 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1169 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1170 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1172 /////////////////////////
1175 CPPUNIT_ASSERT_EQUAL(5, (int)dt
.GetHour());
1177 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1178 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1179 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1180 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1181 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1182 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1183 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1186 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1188 /////////////////////////
1190 #ifdef CHANGE_SYSTEM_DATE
1192 DateChanger
change(2004, 10, 31, 5, 0, 0);
1193 dt
= wxDateTime::Today();
1196 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1197 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1198 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1199 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1200 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1201 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1202 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1204 /////////////////////////
1205 // Test Set(hour, minute, second, milli)
1208 DateChanger
change(2004, 10, 31, 5, 0, 0);
1209 dt
.Set(1, 30, 0, 0);
1210 dt2
.Set(5, 30, 0, 0);
1213 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1214 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1215 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1216 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1217 CPPUNIT_ASSERT_EQUAL(30, (int)dt
.GetMinute());
1218 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1219 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1221 CPPUNIT_ASSERT_EQUAL(31, (int)dt2
.GetDay());
1222 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt2
.GetMonth());
1223 CPPUNIT_ASSERT_EQUAL(2004, (int)dt2
.GetYear());
1224 CPPUNIT_ASSERT_EQUAL(5, (int)dt2
.GetHour());
1225 CPPUNIT_ASSERT_EQUAL(30, (int)dt2
.GetMinute());
1226 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetSecond());
1227 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetMillisecond());
1228 #endif // CHANGE_SYSTEM_DATE
1231 void DateTimeTestCase::TestDateOnly()
1233 wxDateTime
dt(19, wxDateTime::Jan
, 2007, 15, 01, 00);
1235 static const wxDateTime::wxDateTime_t DATE_ZERO
= 0;
1236 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetHour() );
1237 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMinute() );
1238 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetSecond() );
1239 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMillisecond() );
1242 CPPUNIT_ASSERT_EQUAL( wxDateTime(19, wxDateTime::Jan
, 2007), dt
);
1244 CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), wxDateTime::Now().GetDateOnly() );
1247 #endif // wxUSE_DATETIME