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/datetime.h"
26 #include "wx/wxcrt.h" // for wxStrstr()
28 // need this to be able to use CPPUNIT_ASSERT_EQUAL with wxDateTime objects
29 static std::ostream
& operator<<(std::ostream
& ostr
, const wxDateTime
& dt
)
31 ostr
<< dt
.FormatISOCombined(' ');
36 WX_CPPUNIT_ALLOW_EQUALS_TO_INT(wxDateTime::wxDateTime_t
)
38 // to test Today() meaningfully we must be able to change the system date which
39 // is not usually the case, but if we're under Win32 we can try it -- define
40 // the macro below to do it
41 //#define CHANGE_SYSTEM_DATE
44 #undef CHANGE_SYSTEM_DATE
47 #ifdef CHANGE_SYSTEM_DATE
52 DateChanger(int year
, int month
, int day
, int hour
, int min
, int sec
)
63 ::GetSystemTime(&m_savedTime
);
64 ::GetTimeZoneInformation(&m_tzi
);
66 m_changed
= ::SetSystemTime(&st
) != 0;
73 ::SetSystemTime(&m_savedTime
);
74 ::SetTimeZoneInformation(&m_tzi
);
79 SYSTEMTIME m_savedTime
;
80 TIME_ZONE_INFORMATION m_tzi
;
84 #endif // CHANGE_SYSTEM_DATE
86 // helper function translating week day/month names from English to the current
88 static wxString
TranslateDate(const wxString
& str
)
90 // small optimization: if there are no alphabetic characters in the string,
91 // there is nothing to translate
92 wxString::const_iterator i
, end
= str
.end();
93 for ( i
= str
.begin(); i
!= end
; ++i
)
104 for ( wxDateTime::WeekDay wd
= wxDateTime::Sun
;
105 wd
< wxDateTime::Inv_WeekDay
;
110 wxDateTime::GetEnglishWeekDayName(wd
, wxDateTime::Name_Abbr
),
111 wxDateTime::GetWeekDayName(wd
, wxDateTime::Name_Abbr
)
115 for ( wxDateTime::Month mon
= wxDateTime::Jan
;
116 mon
< wxDateTime::Inv_Month
;
121 wxDateTime::GetEnglishMonthName(mon
, wxDateTime::Name_Abbr
),
122 wxDateTime::GetMonthName(mon
, wxDateTime::Name_Abbr
)
129 // ----------------------------------------------------------------------------
130 // broken down date representation used for testing
131 // ----------------------------------------------------------------------------
135 wxDateTime::wxDateTime_t day
;
136 wxDateTime::Month month
;
138 wxDateTime::wxDateTime_t hour
, min
, sec
;
140 wxDateTime::WeekDay wday
;
143 void Init(const wxDateTime::Tm
& tm
)
155 wxDateTime
DT() const
156 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
158 bool SameDay(const wxDateTime::Tm
& tm
) const
160 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
163 wxString
Format() const
166 s
.Printf(wxT("%02d:%02d:%02d %10s %02d, %4d%s"),
168 wxDateTime::GetMonthName(month
).c_str(),
170 abs(wxDateTime::ConvertYearToBC(year
)),
171 year
> 0 ? wxT("AD") : wxT("BC"));
175 wxString
FormatDate() const
178 s
.Printf(wxT("%02d-%s-%4d%s"),
180 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
181 abs(wxDateTime::ConvertYearToBC(year
)),
182 year
> 0 ? wxT("AD") : wxT("BC"));
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 static const Date testDates
[] =
193 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0 },
194 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1 },
195 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1 },
196 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1 },
197 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1 },
198 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1 },
199 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200 },
200 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000 },
201 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1 },
202 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1 },
203 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1 },
204 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1 },
205 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1 },
206 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1 },
207 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1 },
208 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1 },
209 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1 },
210 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1 },
211 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1 },
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
219 class DateTimeTestCase
: public CppUnit::TestCase
222 DateTimeTestCase() { }
225 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
226 CPPUNIT_TEST( TestLeapYears
);
227 CPPUNIT_TEST( TestTimeSet
);
228 CPPUNIT_TEST( TestTimeJDN
);
229 CPPUNIT_TEST( TestTimeWNumber
);
230 CPPUNIT_TEST( TestTimeWDays
);
231 CPPUNIT_TEST( TestTimeDST
);
232 CPPUNIT_TEST( TestTimeFormat
);
233 CPPUNIT_TEST( TestTimeSpanFormat
);
234 CPPUNIT_TEST( TestTimeTicks
);
235 CPPUNIT_TEST( TestParceRFC822
);
236 CPPUNIT_TEST( TestDateParse
);
237 CPPUNIT_TEST( TestDateParseISO
);
238 CPPUNIT_TEST( TestDateTimeParse
);
239 CPPUNIT_TEST( TestTimeArithmetics
);
240 CPPUNIT_TEST( TestDSTBug
);
241 CPPUNIT_TEST( TestDateOnly
);
242 CPPUNIT_TEST_SUITE_END();
244 void TestLeapYears();
247 void TestTimeWNumber();
248 void TestTimeWDays();
250 void TestTimeFormat();
251 void TestTimeSpanFormat();
252 void TestTimeTicks();
253 void TestParceRFC822();
254 void TestDateParse();
255 void TestDateParseISO();
256 void TestDateTimeParse();
257 void TestTimeArithmetics();
261 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
264 // register in the unnamed registry so that these tests are run by default
265 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
267 // also include in it's own registry so that these tests can be run alone
268 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
270 // ============================================================================
272 // ============================================================================
274 // test leap years detection
275 void DateTimeTestCase::TestLeapYears()
277 static const struct LeapYearTestData
293 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
295 const LeapYearTestData
& y
= years
[n
];
297 CPPUNIT_ASSERT_EQUAL( y
.isLeap
, wxDateTime::IsLeapYear(y
.year
) );
301 // test constructing wxDateTime objects
302 void DateTimeTestCase::TestTimeSet()
304 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
306 const Date
& d1
= testDates
[n
];
307 wxDateTime dt
= d1
.DT();
312 wxString s1
= d1
.Format(),
315 CPPUNIT_ASSERT_EQUAL( s1
, s2
);
319 // test conversions to JDN &c
320 void DateTimeTestCase::TestTimeJDN()
322 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
324 const Date
& d
= testDates
[n
];
325 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
327 // JDNs must be computed for UTC times
328 double jdn
= dt
.FromUTC().GetJulianDayNumber();
330 CPPUNIT_ASSERT_EQUAL( d
.jdn
, jdn
);
333 CPPUNIT_ASSERT_EQUAL( jdn
, dt
.GetJulianDayNumber() );
337 // test week days computation
338 void DateTimeTestCase::TestTimeWDays()
342 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
344 const Date
& d
= testDates
[n
];
345 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
347 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
348 CPPUNIT_ASSERT_EQUAL( d
.wday
, wday
);
351 // test SetToWeekDay()
352 struct WeekDateTestData
354 Date date
; // the real date (precomputed)
355 int nWeek
; // its week index in the month
356 wxDateTime::WeekDay wday
; // the weekday
357 wxDateTime::Month month
; // the month
358 int year
; // and the year
360 wxString
Format() const
363 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
365 case 1: which
= wxT("first"); break;
366 case 2: which
= wxT("second"); break;
367 case 3: which
= wxT("third"); break;
368 case 4: which
= wxT("fourth"); break;
369 case 5: which
= wxT("fifth"); break;
371 case -1: which
= wxT("last"); break;
376 which
+= wxT(" from end");
379 s
.Printf(wxT("The %s %s of %s in %d"),
381 wxDateTime::GetWeekDayName(wday
).c_str(),
382 wxDateTime::GetMonthName(month
).c_str(),
389 // the array data was generated by the following python program
391 from DateTime import *
392 from whrandom import *
395 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
396 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
398 week = DateTimeDelta(7)
401 year = randint(1900, 2100)
402 month = randint(1, 12)
404 dt = DateTime(year, month, day)
405 wday = dt.day_of_week
407 countFromEnd = choice([-1, 1])
410 while dt.month is month:
411 dt = dt - countFromEnd * week
412 weekNum = weekNum + countFromEnd
414 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
416 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
417 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
420 static const WeekDateTestData weekDatesTestData
[] =
422 { { 20, wxDateTime::Mar
, 2045, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
423 { { 5, wxDateTime::Jun
, 1985, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
424 { { 12, wxDateTime::Nov
, 1961, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
425 { { 27, wxDateTime::Feb
, 2093, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
426 { { 4, wxDateTime::Jul
, 2070, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
427 { { 2, wxDateTime::Apr
, 1906, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
428 { { 19, wxDateTime::Jul
, 2023, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
429 { { 5, wxDateTime::May
, 1958, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
430 { { 11, wxDateTime::Aug
, 1900, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
431 { { 14, wxDateTime::Feb
, 1945, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
432 { { 25, wxDateTime::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
433 { { 9, wxDateTime::May
, 1916, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
434 { { 20, wxDateTime::Jun
, 1927, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
435 { { 2, wxDateTime::Aug
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
436 { { 20, wxDateTime::Apr
, 2044, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
437 { { 20, wxDateTime::Feb
, 1932, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
438 { { 25, wxDateTime::Jul
, 2069, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
439 { { 3, wxDateTime::Apr
, 1925, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
440 { { 21, wxDateTime::Mar
, 2093, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
441 { { 3, wxDateTime::Dec
, 2074, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 }
445 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
447 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
449 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
451 const Date
& d
= wd
.date
;
452 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
456 // test the computation of (ISO) week numbers
457 void DateTimeTestCase::TestTimeWNumber()
459 struct WeekNumberTestData
461 Date date
; // the date
462 wxDateTime::wxDateTime_t week
; // the week number in the year
463 wxDateTime::wxDateTime_t wmon
; // the week number in the month
464 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
465 wxDateTime::wxDateTime_t dnum
; // day number in the year
468 // data generated with the following python script:
470 from DateTime import *
471 from whrandom import *
474 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
475 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
477 def GetMonthWeek(dt):
478 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
480 weekNumMonth = weekNumMonth + 53
483 def GetLastSundayBefore(dt):
484 if dt.iso_week[2] == 7:
487 return dt - DateTimeDelta(dt.iso_week[2])
490 year = randint(1900, 2100)
491 month = randint(1, 12)
493 dt = DateTime(year, month, day)
494 dayNum = dt.day_of_year
495 weekNum = dt.iso_week[1]
496 weekNumMonth = GetMonthWeek(dt)
499 dtSunday = GetLastSundayBefore(dt)
501 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
502 weekNumMonth2 = weekNumMonth2 + 1
503 dtSunday = dtSunday - DateTimeDelta(7)
505 data = { 'day': rjust(`day`, 2), \
506 'month': monthNames[month - 1], \
508 'weekNum': rjust(`weekNum`, 2), \
509 'weekNumMonth': weekNumMonth, \
510 'weekNumMonth2': weekNumMonth2, \
511 'dayNum': rjust(`dayNum`, 3) }
513 print " { { %(day)s, "\
514 "wxDateTime::%(month)s, "\
517 "%(weekNumMonth)s, "\
518 "%(weekNumMonth2)s, "\
519 "%(dayNum)s }," % data
522 static const WeekNumberTestData weekNumberTestDates
[] =
524 { { 27, wxDateTime::Dec
, 1966, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 52, 5, 5, 361 },
525 { { 22, wxDateTime::Jul
, 1926, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 29, 4, 4, 203 },
526 { { 22, wxDateTime::Oct
, 2076, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 43, 4, 4, 296 },
527 { { 1, wxDateTime::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 26, 1, 1, 182 },
528 { { 8, wxDateTime::Nov
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 46, 2, 2, 313 },
529 { { 21, wxDateTime::Mar
, 1920, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 12, 3, 4, 81 },
530 { { 7, wxDateTime::Jan
, 1965, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 7 },
531 { { 19, wxDateTime::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 42, 4, 4, 292 },
532 { { 13, wxDateTime::Aug
, 1955, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 32, 2, 2, 225 },
533 { { 18, wxDateTime::Jul
, 2087, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 29, 3, 3, 199 },
534 { { 2, wxDateTime::Sep
, 2028, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 35, 1, 1, 246 },
535 { { 28, wxDateTime::Jul
, 1945, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 30, 5, 4, 209 },
536 { { 15, wxDateTime::Jun
, 1901, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 24, 3, 3, 166 },
537 { { 10, wxDateTime::Oct
, 1939, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 41, 3, 2, 283 },
538 { { 3, wxDateTime::Dec
, 1965, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 48, 1, 1, 337 },
539 { { 23, wxDateTime::Feb
, 1940, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 8, 4, 4, 54 },
540 { { 2, wxDateTime::Jan
, 1987, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
541 { { 11, wxDateTime::Aug
, 2079, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 32, 2, 2, 223 },
542 { { 2, wxDateTime::Feb
, 2063, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 5, 1, 1, 33 },
543 { { 16, wxDateTime::Oct
, 1942, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 42, 3, 3, 289 },
544 { { 30, wxDateTime::Dec
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 5, 5, 364 },
545 { { 2, wxDateTime::Jan
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
546 { { 5, wxDateTime::Jan
, 2010, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 5 },
547 { { 3, wxDateTime::Jan
, 2011, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 3 },
550 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
552 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
553 const Date
& d
= wn
.date
;
555 wxDateTime dt
= d
.DT();
557 wxDateTime::wxDateTime_t
558 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
559 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
560 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
561 dnum
= dt
.GetDayOfYear();
563 WX_ASSERT_EQUAL_MESSAGE( ("day of year for %s", d
.Format()),
565 WX_ASSERT_EQUAL_MESSAGE( ("week of month (Monday) for %s", d
.Format()),
567 WX_ASSERT_EQUAL_MESSAGE( ("week of month (Sunday) for %s", d
.Format()),
569 WX_ASSERT_EQUAL_MESSAGE( ("week of year for %s", d
.Format()),
573 if ( week
== 1 && d
.month
!= wxDateTime::Jan
)
575 // this means we're in the first week of the next year
580 dt2
= wxDateTime::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
581 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
585 // test DST applicability
586 void DateTimeTestCase::TestTimeDST()
588 // taken from http://www.energy.ca.gov/daylightsaving.html
589 static const Date datesDST
[2][2009 - 1990 + 1] =
592 { 1, wxDateTime::Apr
, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
593 { 7, wxDateTime::Apr
, 1991, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
594 { 5, wxDateTime::Apr
, 1992, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
595 { 4, wxDateTime::Apr
, 1993, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
596 { 3, wxDateTime::Apr
, 1994, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
597 { 2, wxDateTime::Apr
, 1995, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
598 { 7, wxDateTime::Apr
, 1996, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
599 { 6, wxDateTime::Apr
, 1997, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
600 { 5, wxDateTime::Apr
, 1998, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
601 { 4, wxDateTime::Apr
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
602 { 2, wxDateTime::Apr
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
603 { 1, wxDateTime::Apr
, 2001, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
604 { 7, wxDateTime::Apr
, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
605 { 6, wxDateTime::Apr
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
606 { 4, wxDateTime::Apr
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
607 { 3, wxDateTime::Apr
, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
608 { 2, wxDateTime::Apr
, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
609 {11, wxDateTime::Mar
, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
610 { 9, wxDateTime::Mar
, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
611 { 8, wxDateTime::Mar
, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
614 { 28, wxDateTime::Oct
, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
615 { 27, wxDateTime::Oct
, 1991, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
616 { 25, wxDateTime::Oct
, 1992, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
617 { 31, wxDateTime::Oct
, 1993, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
618 { 30, wxDateTime::Oct
, 1994, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
619 { 29, wxDateTime::Oct
, 1995, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
620 { 27, wxDateTime::Oct
, 1996, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
621 { 26, wxDateTime::Oct
, 1997, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
622 { 25, wxDateTime::Oct
, 1998, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
623 { 31, wxDateTime::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
624 { 29, wxDateTime::Oct
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
625 { 28, wxDateTime::Oct
, 2001, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
626 { 27, wxDateTime::Oct
, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
627 { 26, wxDateTime::Oct
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
628 { 31, wxDateTime::Oct
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
629 { 30, wxDateTime::Oct
, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
630 { 29, wxDateTime::Oct
, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
631 { 4, wxDateTime::Nov
, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
632 { 2, wxDateTime::Nov
, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
633 { 1, wxDateTime::Nov
, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
638 for ( size_t n
= 0; n
< WXSIZEOF(datesDST
[0]); n
++ )
640 const int year
= 1990 + n
;
641 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
642 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
644 const Date
& dBegin
= datesDST
[0][n
];
645 const Date
& dEnd
= datesDST
[1][n
];
647 CPPUNIT_ASSERT_EQUAL( dBegin
.DT().FormatDate(), dtBegin
.FormatDate() );
648 CPPUNIT_ASSERT_EQUAL( dEnd
.DT().FormatDate(), dtEnd
.FormatDate() );
652 // test wxDateTime -> text conversion
653 void DateTimeTestCase::TestTimeFormat()
655 // some information may be lost during conversion, so store what kind
656 // of info should we recover after a round trip
659 CompareNone
, // don't try comparing
660 CompareBoth
, // dates and times should be identical
661 CompareYear
, // don't compare centuries (fails for 2 digit years)
662 CompareDate
, // dates only
663 CompareTime
// time only
668 CompareKind compareKind
;
670 } formatTestFormats
[] =
672 { CompareYear
, "---> %c" }, // %c could use 2 digit years
673 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
674 { CompareYear
, "Date is %x, time is %X" }, // %x could use 2 digits
675 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
676 { CompareNone
, "The day of year: %j, the week of year: %W" },
677 { CompareDate
, "ISO date without separators: %Y%m%d" },
680 static const Date formatTestDates
[] =
682 { 29, wxDateTime::May
, 1976, 18, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
683 { 31, wxDateTime::Dec
, 1999, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
684 { 6, wxDateTime::Feb
, 1937, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
685 { 6, wxDateTime::Feb
, 1856, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
686 { 6, wxDateTime::Feb
, 1857, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
687 { 29, wxDateTime::May
, 2076, 18, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
689 // FIXME: the test with 02:15:25 time doesn't pass because of DST
690 // computation problems, we get back 03:15:25
691 { 29, wxDateTime::Feb
, 2400, 04, 15, 25, 0.0, wxDateTime::Inv_WeekDay
},
693 // Need to add support for BCE dates.
694 { 01, wxDateTime::Jan
, -52, 03, 16, 47, 0.0, wxDateTime::Inv_WeekDay
},
698 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
); d
++ )
700 wxDateTime dt
= formatTestDates
[d
].DT();
701 for ( unsigned n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
703 const char *fmt
= formatTestFormats
[n
].format
;
705 // skip the check with %p for those locales which have empty AM/PM strings:
706 // for those locales it's impossible to pass the test with %p...
708 wxDateTime::GetAmPmStrings(&am
, &pm
);
709 if (am
.empty() && pm
.empty() && wxStrstr(fmt
, "%p") != NULL
)
712 wxString s
= dt
.Format(fmt
);
714 // what can we recover?
715 CompareKind kind
= formatTestFormats
[n
].compareKind
;
719 const char *result
= dt2
.ParseFormat(s
, fmt
);
722 // conversion failed - should it have?
724 ("Test #%u failed: failed to parse \"%s\"", n
, s
),
728 else // conversion succeeded
730 // currently ParseFormat() doesn't support "%Z" and so is
731 // incapable of parsing time zone part used at the end of date
732 // representations in many (but not "C") locales, compensate
733 // for it ourselves by simply consuming and ignoring it
734 while ( *result
&& (*result
>= 'A' && *result
<= 'Z') )
738 ("Test #%u failed: \"%s\" was left unparsed in \"%s\"",
746 if ( dt2
.GetCentury() != dt
.GetCentury() )
748 CPPUNIT_ASSERT_EQUAL(dt
.GetYear() % 100,
749 dt2
.GetYear() % 100);
751 dt2
.SetYear(dt
.GetYear());
753 // fall through and compare everything
756 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
760 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
764 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
768 wxFAIL_MSG( wxT("unexpected") );
778 // special case which was known to fail
779 CPPUNIT_ASSERT( dt
.ParseFormat("02/06/1856", "%x") );
780 CPPUNIT_ASSERT_EQUAL( 1856, dt
.GetYear() );
783 // also test %l separately
784 CPPUNIT_ASSERT( dt
.ParseFormat("12:23:45.678", "%H:%M:%S.%l") );
785 CPPUNIT_ASSERT_EQUAL( 678, dt
.GetMillisecond() );
787 // test special case of %l matching 0 milliseconds
788 CPPUNIT_ASSERT( dt
.ParseFormat("12:23:45.000", "%H:%M:%S.%l") );
789 CPPUNIT_ASSERT_EQUAL( 0, dt
.GetMillisecond() );
791 // test partially specified dates too
792 wxDateTime
dtDef(26, wxDateTime::Sep
, 2008);
793 CPPUNIT_ASSERT( dt
.ParseFormat("17", "%d") );
794 CPPUNIT_ASSERT_EQUAL( 17, dt
.GetDay() );
796 // test compilation of some calls which should compile (and not result in
797 // ambiguity because of char*<->wxCStrData<->wxString conversions)
799 CPPUNIT_ASSERT( !dt
.ParseFormat("foo") );
800 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo")) );
801 CPPUNIT_ASSERT( !dt
.ParseFormat(s
) );
802 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str()) );
804 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", "%c") );
805 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), "%c") );
806 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
807 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), "%c") );
809 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", wxT("%c")) );
810 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), wxT("%c")) );
811 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
812 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), wxT("%c")) );
815 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", spec
) );
816 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), spec
) );
817 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, spec
) );
818 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), spec
) );
821 void DateTimeTestCase::TestTimeSpanFormat()
823 static const struct TimeSpanFormatTestData
825 long h
, min
, sec
, msec
;
830 { 12, 34, 56, 789, "%H:%M:%S.%l", "12:34:56.789" },
831 { 1, 2, 3, 0, "%H:%M:%S", "01:02:03" },
832 { 1, 2, 3, 0, "%S", "3723" },
833 { -1, -2, -3, 0, "%S", "-3723" },
834 { -1, -2, -3, 0, "%H:%M:%S", "-01:02:03" },
835 { 26, 0, 0, 0, "%H", "26" },
836 { 26, 0, 0, 0, "%D, %H", "1, 02" },
837 { -26, 0, 0, 0, "%H", "-26" },
838 { -26, 0, 0, 0, "%D, %H", "-1, 02" },
839 { 219, 0, 0, 0, "%H", "219" },
840 { 219, 0, 0, 0, "%D, %H", "9, 03" },
841 { 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
842 { 0, -1, 0, 0, "%H:%M:%S", "-00:01:00" },
843 { 0, 0, -1, 0, "%H:%M:%S", "-00:00:01" },
846 for ( size_t n
= 0; n
< WXSIZEOF(testSpans
); n
++ )
848 const TimeSpanFormatTestData
& td
= testSpans
[n
];
849 wxTimeSpan
ts(td
.h
, td
.min
, td
.sec
, td
.msec
);
850 CPPUNIT_ASSERT_EQUAL( td
.result
, ts
.Format(td
.fmt
) );
854 void DateTimeTestCase::TestTimeTicks()
856 static const wxDateTime::TimeZone
TZ_LOCAL(wxDateTime::Local
);
857 static const wxDateTime::TimeZone
TZ_TEST(wxDateTime::NZST
);
859 // this offset is needed to make the test work in any time zone when we
860 // only have expected test results in UTC in testDates
861 static const long tzOffset
= TZ_LOCAL
.GetOffset() - TZ_TEST
.GetOffset();
863 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
865 const Date
& d
= testDates
[n
];
866 if ( d
.gmticks
== -1 )
869 wxDateTime dt
= d
.DT().MakeTimezone(TZ_TEST
, true /* no DST */);
871 // GetValue() returns internal UTC-based representation, we need to
872 // convert it to local TZ before comparing
873 time_t ticks
= (dt
.GetValue() / 1000).ToLong() + TZ_LOCAL
.GetOffset();
876 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
+ tzOffset
);
878 dt
= d
.DT().FromTimezone(wxDateTime::UTC
);
879 ticks
= (dt
.GetValue() / 1000).ToLong();
880 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
);
884 // test parsing dates in RFC822 format
885 void DateTimeTestCase::TestParceRFC822()
887 static const struct ParseTestData
890 Date date
; // NB: this should be in UTC
895 "Sat, 18 Dec 1999 00:46:40 +0100",
896 { 17, wxDateTime::Dec
, 1999, 23, 46, 40 },
900 "Wed, 1 Dec 1999 05:17:20 +0300",
901 { 1, wxDateTime::Dec
, 1999, 2, 17, 20 },
905 "Sun, 28 Aug 2005 03:31:30 +0200",
906 { 28, wxDateTime::Aug
, 2005, 1, 31, 30 },
911 "Sat, 18 Dec 1999 10:48:30 -0500",
912 { 18, wxDateTime::Dec
, 1999, 15, 48, 30 },
916 // seconds are optional according to the RFC
918 "Sun, 01 Jun 2008 16:30 +0200",
919 { 1, wxDateTime::Jun
, 2008, 14, 30, 00 },
923 // try some bogus ones too
925 "Sun, 01 Jun 2008 16:30: +0200",
931 for ( unsigned n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
933 const char * const datestr
= parseTestDates
[n
].rfc822
;
936 if ( dt
.ParseRfc822Date(datestr
) )
939 ("Erroneously parsed \"%s\"", datestr
),
940 parseTestDates
[n
].good
943 wxDateTime dtReal
= parseTestDates
[n
].date
.DT().FromUTC();
944 CPPUNIT_ASSERT_EQUAL( dtReal
, dt
);
946 else // failed to parse
949 ("Failed to parse \"%s\"", datestr
),
950 !parseTestDates
[n
].good
956 // test parsing dates in free format
957 void DateTimeTestCase::TestDateParse()
959 static const struct ParseTestData
962 Date date
; // NB: this should be in UTC
966 { "21 Mar 2006", { 21, wxDateTime::Mar
, 2006 }, true },
967 { "29 Feb 1976", { 29, wxDateTime::Feb
, 1976 }, true },
968 { "Feb 29 1976", { 29, wxDateTime::Feb
, 1976 }, true },
969 { "31/03/06", { 31, wxDateTime::Mar
, 6 }, true },
970 { "31/03/2006", { 31, wxDateTime::Mar
, 2006 }, true },
972 // some invalid ones too
981 CPPUNIT_ASSERT( dt
.ParseDate(wxT("today")) );
982 CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), dt
);
984 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
986 const wxString datestr
= TranslateDate(parseTestDates
[n
].str
);
988 const char * const end
= dt
.ParseDate(datestr
);
992 ("Erroneously parsed \"%s\"", datestr
),
993 parseTestDates
[n
].good
996 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
998 else // failed to parse
1001 ("Failed to parse \"%s\"", datestr
),
1002 !parseTestDates
[n
].good
1008 void DateTimeTestCase::TestDateParseISO()
1013 Date date
; // NB: this should be in UTC
1015 } parseTestDates
[] =
1017 { "2006-03-21", { 21, wxDateTime::Mar
, 2006 }, true },
1018 { "1976-02-29", { 29, wxDateTime::Feb
, 1976 }, true },
1019 { "0006-03-31", { 31, wxDateTime::Mar
, 6 }, true },
1021 // some invalid ones too
1031 wxDateTime::wxDateTime_t hour
, min
, sec
;
1033 } parseTestTimes
[] =
1035 { "13:42:17", 13, 42, 17, true },
1036 { "02:17:01", 2, 17, 1, true },
1038 // some invalid ones too
1045 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1048 if ( dt
.ParseISODate(parseTestDates
[n
].str
) )
1050 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
1052 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1054 for ( size_t m
= 0; m
< WXSIZEOF(parseTestTimes
); m
++ )
1056 wxString dtCombined
;
1057 dtCombined
<< parseTestDates
[n
].str
1059 << parseTestTimes
[m
].str
;
1061 if ( dt
.ParseISOCombined(dtCombined
) )
1063 CPPUNIT_ASSERT( parseTestTimes
[m
].good
);
1065 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].hour
, dt
.GetHour()) ;
1066 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].min
, dt
.GetMinute()) ;
1067 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].sec
, dt
.GetSecond()) ;
1069 else // failed to parse combined date/time
1071 CPPUNIT_ASSERT( !parseTestTimes
[m
].good
);
1075 else // failed to parse
1077 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1082 void DateTimeTestCase::TestDateTimeParse()
1084 static const struct ParseTestData
1087 Date date
; // NB: this should be in UTC
1089 } parseTestDates
[] =
1092 "Thu 22 Nov 2007 07:40:00 PM",
1093 { 22, wxDateTime::Nov
, 2007, 19, 40, 0 },
1099 { 4, wxDateTime::Jan
, 2010, 14, 30, 0 },
1105 { 1, wxDateTime::Jan
, 9999, 0, 0, 0},
1110 // the test strings here use "PM" which is not available in all locales so
1111 // we need to use "C" locale for them
1115 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1117 const wxString datestr
= TranslateDate(parseTestDates
[n
].str
);
1119 const char * const end
= dt
.ParseDateTime(datestr
);
1123 ("Erroneously parsed \"%s\"", datestr
),
1124 parseTestDates
[n
].good
1127 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1129 else // failed to parse
1132 ("Failed to parse \"%s\"", datestr
),
1133 !parseTestDates
[n
].good
1136 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1141 void DateTimeTestCase::TestTimeArithmetics()
1143 static const wxDateSpan testArithmData
[] =
1147 wxDateSpan::Month(),
1151 // the test will *not* work with arbitrary date!
1152 wxDateTime
dt(2, wxDateTime::Dec
, 1999),
1156 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
1158 const wxDateSpan
& span
= testArithmData
[n
];
1162 CPPUNIT_ASSERT_EQUAL( dt
, dt1
- span
);
1163 CPPUNIT_ASSERT_EQUAL( dt
, dt2
+ span
);
1164 CPPUNIT_ASSERT_EQUAL( dt1
, dt2
+ 2*span
);
1168 void DateTimeTestCase::TestDSTBug()
1170 /////////////////////////
1172 wxDateTime dt
= wxDateTime::GetEndDST(2004, wxDateTime::France
);
1173 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1174 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1175 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1176 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1177 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1178 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1179 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1181 /////////////////////////
1184 CPPUNIT_ASSERT_EQUAL(5, (int)dt
.GetHour());
1186 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1187 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1188 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1189 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1190 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1191 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1192 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1195 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1197 /////////////////////////
1199 #ifdef CHANGE_SYSTEM_DATE
1201 DateChanger
change(2004, 10, 31, 5, 0, 0);
1202 dt
= wxDateTime::Today();
1205 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1206 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1207 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1208 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1209 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1210 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1211 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1213 /////////////////////////
1214 // Test Set(hour, minute, second, milli)
1217 DateChanger
change(2004, 10, 31, 5, 0, 0);
1218 dt
.Set(1, 30, 0, 0);
1219 dt2
.Set(5, 30, 0, 0);
1222 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1223 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1224 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1225 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1226 CPPUNIT_ASSERT_EQUAL(30, (int)dt
.GetMinute());
1227 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1228 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1230 CPPUNIT_ASSERT_EQUAL(31, (int)dt2
.GetDay());
1231 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt2
.GetMonth());
1232 CPPUNIT_ASSERT_EQUAL(2004, (int)dt2
.GetYear());
1233 CPPUNIT_ASSERT_EQUAL(5, (int)dt2
.GetHour());
1234 CPPUNIT_ASSERT_EQUAL(30, (int)dt2
.GetMinute());
1235 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetSecond());
1236 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetMillisecond());
1237 #endif // CHANGE_SYSTEM_DATE
1240 void DateTimeTestCase::TestDateOnly()
1242 wxDateTime
dt(19, wxDateTime::Jan
, 2007, 15, 01, 00);
1244 static const wxDateTime::wxDateTime_t DATE_ZERO
= 0;
1245 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetHour() );
1246 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMinute() );
1247 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetSecond() );
1248 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMillisecond() );
1251 CPPUNIT_ASSERT_EQUAL( wxDateTime(19, wxDateTime::Jan
, 2007), dt
);
1253 CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), wxDateTime::Now().GetDateOnly() );
1256 #endif // wxUSE_DATETIME