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 // ----------------------------------------------------------------------------
87 // broken down date representation used for testing
88 // ----------------------------------------------------------------------------
92 wxDateTime::wxDateTime_t day
;
93 wxDateTime::Month month
;
95 wxDateTime::wxDateTime_t hour
, min
, sec
;
97 wxDateTime::WeekDay wday
;
100 void Init(const wxDateTime::Tm
& tm
)
112 wxDateTime
DT() const
113 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
115 bool SameDay(const wxDateTime::Tm
& tm
) const
117 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
120 wxString
Format() const
123 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
125 wxDateTime::GetMonthName(month
).c_str(),
127 abs(wxDateTime::ConvertYearToBC(year
)),
128 year
> 0 ? _T("AD") : _T("BC"));
132 wxString
FormatDate() const
135 s
.Printf(_T("%02d-%s-%4d%s"),
137 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
138 abs(wxDateTime::ConvertYearToBC(year
)),
139 year
> 0 ? _T("AD") : _T("BC"));
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 static const Date testDates
[] =
150 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0 },
151 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1 },
152 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1 },
153 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1 },
154 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1 },
155 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1 },
156 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200 },
157 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000 },
158 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1 },
159 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1 },
160 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1 },
161 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1 },
162 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1 },
163 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1 },
164 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1 },
165 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1 },
166 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1 },
167 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1 },
168 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1 },
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 class DateTimeTestCase
: public CppUnit::TestCase
179 DateTimeTestCase() { }
182 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
183 CPPUNIT_TEST( TestLeapYears
);
184 CPPUNIT_TEST( TestTimeSet
);
185 CPPUNIT_TEST( TestTimeJDN
);
186 CPPUNIT_TEST( TestTimeWNumber
);
187 CPPUNIT_TEST( TestTimeWDays
);
188 CPPUNIT_TEST( TestTimeDST
);
189 CPPUNIT_TEST( TestTimeFormat
);
190 CPPUNIT_TEST( TestTimeSpanFormat
);
191 CPPUNIT_TEST( TestTimeTicks
);
192 CPPUNIT_TEST( TestParceRFC822
);
193 CPPUNIT_TEST( TestDateParse
);
194 CPPUNIT_TEST( TestDateParseISO
);
195 CPPUNIT_TEST( TestDateTimeParse
);
196 CPPUNIT_TEST( TestTimeArithmetics
);
197 CPPUNIT_TEST( TestDSTBug
);
198 CPPUNIT_TEST( TestDateOnly
);
199 CPPUNIT_TEST_SUITE_END();
201 void TestLeapYears();
204 void TestTimeWNumber();
205 void TestTimeWDays();
207 void TestTimeFormat();
208 void TestTimeSpanFormat();
209 void TestTimeTicks();
210 void TestParceRFC822();
211 void TestDateParse();
212 void TestDateParseISO();
213 void TestDateTimeParse();
214 void TestTimeArithmetics();
218 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
221 // register in the unnamed registry so that these tests are run by default
222 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
224 // also include in it's own registry so that these tests can be run alone
225 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
227 // ============================================================================
229 // ============================================================================
231 // test leap years detection
232 void DateTimeTestCase::TestLeapYears()
234 static const struct LeapYearTestData
250 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
252 const LeapYearTestData
& y
= years
[n
];
254 CPPUNIT_ASSERT( wxDateTime::IsLeapYear(y
.year
) == y
.isLeap
);
258 // test constructing wxDateTime objects
259 void DateTimeTestCase::TestTimeSet()
261 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
263 const Date
& d1
= testDates
[n
];
264 wxDateTime dt
= d1
.DT();
269 wxString s1
= d1
.Format(),
272 CPPUNIT_ASSERT( s1
== s2
);
276 // test conversions to JDN &c
277 void DateTimeTestCase::TestTimeJDN()
279 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
281 const Date
& d
= testDates
[n
];
282 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
284 // JDNs must be computed for UTC times
285 double jdn
= dt
.FromUTC().GetJulianDayNumber();
287 CPPUNIT_ASSERT_EQUAL( d
.jdn
, jdn
);
290 CPPUNIT_ASSERT_EQUAL( jdn
, dt
.GetJulianDayNumber() );
294 // test week days computation
295 void DateTimeTestCase::TestTimeWDays()
299 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
301 const Date
& d
= testDates
[n
];
302 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
304 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
305 CPPUNIT_ASSERT( wday
== d
.wday
);
308 // test SetToWeekDay()
309 struct WeekDateTestData
311 Date date
; // the real date (precomputed)
312 int nWeek
; // its week index in the month
313 wxDateTime::WeekDay wday
; // the weekday
314 wxDateTime::Month month
; // the month
315 int year
; // and the year
317 wxString
Format() const
320 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
322 case 1: which
= _T("first"); break;
323 case 2: which
= _T("second"); break;
324 case 3: which
= _T("third"); break;
325 case 4: which
= _T("fourth"); break;
326 case 5: which
= _T("fifth"); break;
328 case -1: which
= _T("last"); break;
333 which
+= _T(" from end");
336 s
.Printf(_T("The %s %s of %s in %d"),
338 wxDateTime::GetWeekDayName(wday
).c_str(),
339 wxDateTime::GetMonthName(month
).c_str(),
346 // the array data was generated by the following python program
348 from DateTime import *
349 from whrandom import *
352 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
353 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
355 week = DateTimeDelta(7)
358 year = randint(1900, 2100)
359 month = randint(1, 12)
361 dt = DateTime(year, month, day)
362 wday = dt.day_of_week
364 countFromEnd = choice([-1, 1])
367 while dt.month is month:
368 dt = dt - countFromEnd * week
369 weekNum = weekNum + countFromEnd
371 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
373 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
374 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
377 static const WeekDateTestData weekDatesTestData
[] =
379 { { 20, wxDateTime::Mar
, 2045, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
380 { { 5, wxDateTime::Jun
, 1985, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
381 { { 12, wxDateTime::Nov
, 1961, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
382 { { 27, wxDateTime::Feb
, 2093, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
383 { { 4, wxDateTime::Jul
, 2070, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
384 { { 2, wxDateTime::Apr
, 1906, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
385 { { 19, wxDateTime::Jul
, 2023, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
386 { { 5, wxDateTime::May
, 1958, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
387 { { 11, wxDateTime::Aug
, 1900, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
388 { { 14, wxDateTime::Feb
, 1945, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
389 { { 25, wxDateTime::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
390 { { 9, wxDateTime::May
, 1916, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
391 { { 20, wxDateTime::Jun
, 1927, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
392 { { 2, wxDateTime::Aug
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
393 { { 20, wxDateTime::Apr
, 2044, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
394 { { 20, wxDateTime::Feb
, 1932, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
395 { { 25, wxDateTime::Jul
, 2069, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
396 { { 3, wxDateTime::Apr
, 1925, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
397 { { 21, wxDateTime::Mar
, 2093, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
398 { { 3, wxDateTime::Dec
, 2074, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 }
402 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
404 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
406 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
408 const Date
& d
= wd
.date
;
409 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
413 // test the computation of (ISO) week numbers
414 void DateTimeTestCase::TestTimeWNumber()
416 struct WeekNumberTestData
418 Date date
; // the date
419 wxDateTime::wxDateTime_t week
; // the week number in the year
420 wxDateTime::wxDateTime_t wmon
; // the week number in the month
421 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
422 wxDateTime::wxDateTime_t dnum
; // day number in the year
425 // data generated with the following python script:
427 from DateTime import *
428 from whrandom import *
431 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
432 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
434 def GetMonthWeek(dt):
435 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
437 weekNumMonth = weekNumMonth + 53
440 def GetLastSundayBefore(dt):
441 if dt.iso_week[2] == 7:
444 return dt - DateTimeDelta(dt.iso_week[2])
447 year = randint(1900, 2100)
448 month = randint(1, 12)
450 dt = DateTime(year, month, day)
451 dayNum = dt.day_of_year
452 weekNum = dt.iso_week[1]
453 weekNumMonth = GetMonthWeek(dt)
456 dtSunday = GetLastSundayBefore(dt)
458 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
459 weekNumMonth2 = weekNumMonth2 + 1
460 dtSunday = dtSunday - DateTimeDelta(7)
462 data = { 'day': rjust(`day`, 2), \
463 'month': monthNames[month - 1], \
465 'weekNum': rjust(`weekNum`, 2), \
466 'weekNumMonth': weekNumMonth, \
467 'weekNumMonth2': weekNumMonth2, \
468 'dayNum': rjust(`dayNum`, 3) }
470 print " { { %(day)s, "\
471 "wxDateTime::%(month)s, "\
474 "%(weekNumMonth)s, "\
475 "%(weekNumMonth2)s, "\
476 "%(dayNum)s }," % data
479 static const WeekNumberTestData weekNumberTestDates
[] =
481 { { 27, wxDateTime::Dec
, 1966, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 52, 5, 5, 361 },
482 { { 22, wxDateTime::Jul
, 1926, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 29, 4, 4, 203 },
483 { { 22, wxDateTime::Oct
, 2076, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 43, 4, 4, 296 },
484 { { 1, wxDateTime::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 26, 1, 1, 182 },
485 { { 8, wxDateTime::Nov
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 46, 2, 2, 313 },
486 { { 21, wxDateTime::Mar
, 1920, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 12, 3, 4, 81 },
487 { { 7, wxDateTime::Jan
, 1965, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 2, 2, 7 },
488 { { 19, wxDateTime::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 42, 4, 4, 292 },
489 { { 13, wxDateTime::Aug
, 1955, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 32, 2, 2, 225 },
490 { { 18, wxDateTime::Jul
, 2087, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 29, 3, 3, 199 },
491 { { 2, wxDateTime::Sep
, 2028, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 35, 1, 1, 246 },
492 { { 28, wxDateTime::Jul
, 1945, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 30, 5, 4, 209 },
493 { { 15, wxDateTime::Jun
, 1901, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 24, 3, 3, 166 },
494 { { 10, wxDateTime::Oct
, 1939, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 41, 3, 2, 283 },
495 { { 3, wxDateTime::Dec
, 1965, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 48, 1, 1, 337 },
496 { { 23, wxDateTime::Feb
, 1940, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 8, 4, 4, 54 },
497 { { 2, wxDateTime::Jan
, 1987, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
498 { { 11, wxDateTime::Aug
, 2079, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 32, 2, 2, 223 },
499 { { 2, wxDateTime::Feb
, 2063, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 5, 1, 1, 33 },
500 { { 16, wxDateTime::Oct
, 1942, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 42, 3, 3, 289 },
501 { { 30, wxDateTime::Dec
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 5, 5, 364 },
502 { { 2, wxDateTime::Jan
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
505 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
507 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
508 const Date
& d
= wn
.date
;
510 wxDateTime dt
= d
.DT();
512 wxDateTime::wxDateTime_t
513 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
514 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
515 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
516 dnum
= dt
.GetDayOfYear();
518 CPPUNIT_ASSERT( dnum
== wn
.dnum
);
519 CPPUNIT_ASSERT( wmon
== wn
.wmon
);
520 CPPUNIT_ASSERT( wmon2
== wn
.wmon2
);
521 CPPUNIT_ASSERT( week
== wn
.week
);
524 if ( week
== 1 && d
.month
!= wxDateTime::Jan
)
526 // this means we're in the first week of the next year
531 dt2
= wxDateTime::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
532 CPPUNIT_ASSERT( dt2
== dt
);
536 // test DST applicability
537 void DateTimeTestCase::TestTimeDST()
539 // taken from http://www.energy.ca.gov/daylightsaving.html
540 static const Date datesDST
[2][2009 - 1990 + 1] =
543 { 1, wxDateTime::Apr
, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
544 { 7, wxDateTime::Apr
, 1991, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
545 { 5, wxDateTime::Apr
, 1992, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
546 { 4, wxDateTime::Apr
, 1993, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
547 { 3, wxDateTime::Apr
, 1994, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
548 { 2, wxDateTime::Apr
, 1995, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
549 { 7, wxDateTime::Apr
, 1996, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
550 { 6, wxDateTime::Apr
, 1997, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
551 { 5, wxDateTime::Apr
, 1998, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
552 { 4, wxDateTime::Apr
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
553 { 2, wxDateTime::Apr
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
554 { 1, wxDateTime::Apr
, 2001, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
555 { 7, wxDateTime::Apr
, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
556 { 6, wxDateTime::Apr
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
557 { 4, wxDateTime::Apr
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
558 { 3, wxDateTime::Apr
, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
559 { 2, wxDateTime::Apr
, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
560 {11, wxDateTime::Mar
, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
561 { 9, wxDateTime::Mar
, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
562 { 8, wxDateTime::Mar
, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
565 { 28, wxDateTime::Oct
, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
566 { 27, wxDateTime::Oct
, 1991, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
567 { 25, wxDateTime::Oct
, 1992, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
568 { 31, wxDateTime::Oct
, 1993, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
569 { 30, wxDateTime::Oct
, 1994, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
570 { 29, wxDateTime::Oct
, 1995, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
571 { 27, wxDateTime::Oct
, 1996, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
572 { 26, wxDateTime::Oct
, 1997, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
573 { 25, wxDateTime::Oct
, 1998, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
574 { 31, wxDateTime::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
575 { 29, wxDateTime::Oct
, 2000, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
576 { 28, wxDateTime::Oct
, 2001, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
577 { 27, wxDateTime::Oct
, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
578 { 26, wxDateTime::Oct
, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
579 { 31, wxDateTime::Oct
, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
580 { 30, wxDateTime::Oct
, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
581 { 29, wxDateTime::Oct
, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
582 { 4, wxDateTime::Nov
, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
583 { 2, wxDateTime::Nov
, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
584 { 1, wxDateTime::Nov
, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay
, 0 },
589 for ( size_t n
= 0; n
< WXSIZEOF(datesDST
[0]); n
++ )
591 const int year
= 1990 + n
;
592 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
593 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
595 const Date
& dBegin
= datesDST
[0][n
];
596 const Date
& dEnd
= datesDST
[1][n
];
598 CPPUNIT_ASSERT_EQUAL( dBegin
.DT().FormatDate(), dtBegin
.FormatDate() );
599 CPPUNIT_ASSERT_EQUAL( dEnd
.DT().FormatDate(), dtEnd
.FormatDate() );
603 // test wxDateTime -> text conversion
604 void DateTimeTestCase::TestTimeFormat()
606 // some information may be lost during conversion, so store what kind
607 // of info should we recover after a round trip
610 CompareNone
, // don't try comparing
611 CompareBoth
, // dates and times should be identical
612 CompareYear
, // don't compare centuries (fails for 2 digit years)
613 CompareDate
, // dates only
614 CompareTime
// time only
619 CompareKind compareKind
;
621 } formatTestFormats
[] =
623 { CompareYear
, "---> %c" }, // %c could use 2 digit years
624 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
625 { CompareYear
, "Date is %x, time is %X" }, // %x could use 2 digits
626 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
627 { CompareNone
, "The day of year: %j, the week of year: %W" },
628 { CompareDate
, "ISO date without separators: %Y%m%d" },
631 static const Date formatTestDates
[] =
633 { 29, wxDateTime::May
, 1976, 18, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
634 { 31, wxDateTime::Dec
, 1999, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
635 { 6, wxDateTime::Feb
, 1937, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
636 { 6, wxDateTime::Feb
, 1856, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
637 { 6, wxDateTime::Feb
, 1857, 23, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
638 { 29, wxDateTime::May
, 2076, 18, 30, 00, 0.0, wxDateTime::Inv_WeekDay
},
639 { 29, wxDateTime::Feb
, 2400, 02, 15, 25, 0.0, wxDateTime::Inv_WeekDay
},
641 // Need to add support for BCE dates.
642 { 01, wxDateTime::Jan
, -52, 03, 16, 47, 0.0, wxDateTime::Inv_WeekDay
},
646 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
); d
++ )
648 wxDateTime dt
= formatTestDates
[d
].DT();
649 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
651 const char *fmt
= formatTestFormats
[n
].format
;
653 // skip the check with %p for those locales which have empty AM/PM strings:
654 // for those locales it's impossible to pass the test with %p...
656 wxDateTime::GetAmPmStrings(&am
, &pm
);
657 if (am
.empty() && pm
.empty() && wxStrstr(fmt
, "%p") != NULL
)
660 wxString s
= dt
.Format(fmt
);
662 // what can we recover?
663 CompareKind kind
= formatTestFormats
[n
].compareKind
;
667 const char *result
= dt2
.ParseFormat(s
, fmt
);
670 // conversion failed - should it have?
671 CPPUNIT_ASSERT( kind
== CompareNone
);
673 else // conversion succeeded
675 // ParseFormat() should have parsed the entire string or left
676 // some final useless strings (e.g. with Italian locale the
677 // 's' string for the first test date looks like
678 // "---> sab 29 mag 1976 18:30:00 CET"
679 // so we just need to ignore CET)
680 CPPUNIT_ASSERT( !*result
|| strcmp(result
, "CET") == 0 );
685 if ( dt2
.GetCentury() != dt
.GetCentury() )
687 CPPUNIT_ASSERT_EQUAL(dt
.GetYear() % 100,
688 dt2
.GetYear() % 100);
690 dt2
.SetYear(dt
.GetYear());
692 // fall through and compare everything
695 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
699 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
703 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
707 wxFAIL_MSG( _T("unexpected") );
716 // test partially specified dates too
717 wxDateTime
dtDef(26, wxDateTime::Sep
, 2008);
718 CPPUNIT_ASSERT( dt
.ParseFormat("17", "%d") );
719 CPPUNIT_ASSERT_EQUAL( 17, dt
.GetDay() );
721 // test compilation of some calls which should compile (and not result in
722 // ambiguity because of char*<->wxCStrData<->wxString conversions)
724 CPPUNIT_ASSERT( !dt
.ParseFormat("foo") );
725 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo")) );
726 CPPUNIT_ASSERT( !dt
.ParseFormat(s
) );
727 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str()) );
729 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", "%c") );
730 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), "%c") );
731 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
732 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), "%c") );
734 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", wxT("%c")) );
735 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), wxT("%c")) );
736 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
737 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), wxT("%c")) );
740 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", spec
) );
741 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), spec
) );
742 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, spec
) );
743 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), spec
) );
746 void DateTimeTestCase::TestTimeSpanFormat()
748 static const struct TimeSpanFormatTestData
750 long h
, min
, sec
, msec
;
755 { 12, 34, 56, 789, "%H:%M:%S.%l", "12:34:56.789" },
756 { 1, 2, 3, 0, "%H:%M:%S", "01:02:03" },
757 { 1, 2, 3, 0, "%S", "3723" },
758 { -1, -2, -3, 0, "%S", "-3723" },
759 { -1, -2, -3, 0, "%H:%M:%S", "-01:02:03" },
760 { 26, 0, 0, 0, "%H", "26" },
761 { 26, 0, 0, 0, "%D, %H", "1, 02" },
762 { -26, 0, 0, 0, "%H", "-26" },
763 { -26, 0, 0, 0, "%D, %H", "-1, 02" },
764 { 219, 0, 0, 0, "%H", "219" },
765 { 219, 0, 0, 0, "%D, %H", "9, 03" },
766 { 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
767 { 0, -1, 0, 0, "%H:%M:%S", "-00:01:00" },
768 { 0, 0, -1, 0, "%H:%M:%S", "-00:00:01" },
771 for ( size_t n
= 0; n
< WXSIZEOF(testSpans
); n
++ )
773 const TimeSpanFormatTestData
& td
= testSpans
[n
];
774 wxTimeSpan
ts(td
.h
, td
.min
, td
.sec
, td
.msec
);
775 CPPUNIT_ASSERT_EQUAL( td
.result
, ts
.Format(td
.fmt
) );
779 void DateTimeTestCase::TestTimeTicks()
781 static const wxDateTime::TimeZone
TZ_LOCAL(wxDateTime::Local
);
782 static const wxDateTime::TimeZone
TZ_TEST(wxDateTime::NZST
);
784 // this offset is needed to make the test work in any time zone when we
785 // only have expected test results in UTC in testDates
786 static const long tzOffset
= TZ_LOCAL
.GetOffset() - TZ_TEST
.GetOffset();
788 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
790 const Date
& d
= testDates
[n
];
791 if ( d
.gmticks
== -1 )
794 wxDateTime dt
= d
.DT().MakeTimezone(TZ_TEST
, true /* no DST */);
796 // GetValue() returns internal UTC-based representation, we need to
797 // convert it to local TZ before comparing
798 time_t ticks
= (dt
.GetValue() / 1000).ToLong() + TZ_LOCAL
.GetOffset();
801 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
+ tzOffset
);
803 dt
= d
.DT().FromTimezone(wxDateTime::UTC
);
804 ticks
= (dt
.GetValue() / 1000).ToLong();
805 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
);
809 // test parsing dates in RFC822 format
810 void DateTimeTestCase::TestParceRFC822()
812 static const struct ParseTestData
815 Date date
; // NB: this should be in UTC
820 "Sat, 18 Dec 1999 00:46:40 +0100",
821 { 17, wxDateTime::Dec
, 1999, 23, 46, 40 },
825 "Wed, 1 Dec 1999 05:17:20 +0300",
826 { 1, wxDateTime::Dec
, 1999, 2, 17, 20 },
830 "Sun, 28 Aug 2005 03:31:30 +0200",
831 { 28, wxDateTime::Aug
, 2005, 1, 31, 30 },
836 "Sat, 18 Dec 1999 10:48:30 -0500",
837 { 18, wxDateTime::Dec
, 1999, 15, 48, 30 },
841 // seconds are optional according to the RFC
843 "Sun, 01 Jun 2008 16:30 +0200",
844 { 1, wxDateTime::Jun
, 2008, 14, 30, 00 },
848 // try some bogus ones too
850 "Sun, 01 Jun 2008 16:30: +0200",
856 for ( unsigned n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
858 const char * const datestr
= parseTestDates
[n
].rfc822
;
861 if ( dt
.ParseRfc822Date(datestr
) )
864 ("Erroneously parsed \"%s\"", datestr
),
865 parseTestDates
[n
].good
868 wxDateTime dtReal
= parseTestDates
[n
].date
.DT().FromUTC();
869 CPPUNIT_ASSERT_EQUAL( dtReal
, dt
);
871 else // failed to parse
874 ("Failed to parse \"%s\"", datestr
),
875 !parseTestDates
[n
].good
881 // test parsing dates in free format
882 void DateTimeTestCase::TestDateParse()
884 static const struct ParseTestData
887 Date date
; // NB: this should be in UTC
891 { "21 Mar 2006", { 21, wxDateTime::Mar
, 2006 }, true },
892 { "29 Feb 1976", { 29, wxDateTime::Feb
, 1976 }, true },
893 { "Feb 29 1976", { 29, wxDateTime::Feb
, 1976 }, true },
894 { "31/03/06", { 31, wxDateTime::Mar
, 6 }, true },
895 { "31/03/2006", { 31, wxDateTime::Mar
, 2006 }, true },
897 // some invalid ones too
905 CPPUNIT_ASSERT( dt
.ParseDate(_T("today")) );
906 CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), dt
);
908 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
910 if ( dt
.ParseDate(parseTestDates
[n
].str
) )
912 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
914 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
916 else // failed to parse
918 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
923 void DateTimeTestCase::TestDateParseISO()
928 Date date
; // NB: this should be in UTC
932 { "2006-03-21", { 21, wxDateTime::Mar
, 2006 }, true },
933 { "1976-02-29", { 29, wxDateTime::Feb
, 1976 }, true },
934 { "0006-03-31", { 31, wxDateTime::Mar
, 6 }, true },
936 // some invalid ones too
946 wxDateTime::wxDateTime_t hour
, min
, sec
;
950 { "13:42:17", 13, 42, 17, true },
951 { "02:17:01", 2, 17, 1, true },
953 // some invalid ones too
960 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
963 if ( dt
.ParseISODate(parseTestDates
[n
].str
) )
965 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
967 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
969 for ( size_t m
= 0; m
< WXSIZEOF(parseTestTimes
); m
++ )
972 dtCombined
<< parseTestDates
[n
].str
974 << parseTestTimes
[m
].str
;
976 if ( dt
.ParseISOCombined(dtCombined
) )
978 CPPUNIT_ASSERT( parseTestTimes
[m
].good
);
980 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].hour
, dt
.GetHour()) ;
981 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].min
, dt
.GetMinute()) ;
982 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].sec
, dt
.GetSecond()) ;
984 else // failed to parse combined date/time
986 CPPUNIT_ASSERT( !parseTestTimes
[m
].good
);
990 else // failed to parse
992 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
997 void DateTimeTestCase::TestDateTimeParse()
999 static const struct ParseTestData
1002 Date date
; // NB: this should be in UTC
1004 } parseTestDates
[] =
1006 { "Thu 22 Nov 2007 07:40:00 PM",
1007 { 22, wxDateTime::Nov
, 2007, 19, 40, 0}, true },
1012 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1014 if ( dt
.ParseDateTime(parseTestDates
[n
].str
) )
1016 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
1018 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1020 else // failed to parse
1022 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1027 void DateTimeTestCase::TestTimeArithmetics()
1029 static const wxDateSpan testArithmData
[] =
1033 wxDateSpan::Month(),
1037 // the test will *not* work with arbitrary date!
1038 wxDateTime
dt(2, wxDateTime::Dec
, 1999),
1042 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
1044 const wxDateSpan
& span
= testArithmData
[n
];
1048 CPPUNIT_ASSERT( dt1
- span
== dt
);
1049 CPPUNIT_ASSERT( dt2
+ span
== dt
);
1050 CPPUNIT_ASSERT( dt2
+ 2*span
== dt1
);
1054 void DateTimeTestCase::TestDSTBug()
1056 /////////////////////////
1058 wxDateTime dt
= wxDateTime::GetEndDST(2004, wxDateTime::France
);
1059 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1060 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1061 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1062 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1063 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1064 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1065 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1067 /////////////////////////
1070 CPPUNIT_ASSERT_EQUAL(5, (int)dt
.GetHour());
1072 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1073 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1074 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1075 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1076 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1077 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1078 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1081 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1083 /////////////////////////
1085 #ifdef CHANGE_SYSTEM_DATE
1087 DateChanger
change(2004, 10, 31, 5, 0, 0);
1088 dt
= wxDateTime::Today();
1091 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1092 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1093 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1094 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1095 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1096 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1097 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1099 /////////////////////////
1100 // Test Set(hour, minute, second, milli)
1103 DateChanger
change(2004, 10, 31, 5, 0, 0);
1104 dt
.Set(1, 30, 0, 0);
1105 dt2
.Set(5, 30, 0, 0);
1108 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1109 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt
.GetMonth());
1110 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1111 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1112 CPPUNIT_ASSERT_EQUAL(30, (int)dt
.GetMinute());
1113 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1114 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1116 CPPUNIT_ASSERT_EQUAL(31, (int)dt2
.GetDay());
1117 CPPUNIT_ASSERT_EQUAL(wxDateTime::Oct
, dt2
.GetMonth());
1118 CPPUNIT_ASSERT_EQUAL(2004, (int)dt2
.GetYear());
1119 CPPUNIT_ASSERT_EQUAL(5, (int)dt2
.GetHour());
1120 CPPUNIT_ASSERT_EQUAL(30, (int)dt2
.GetMinute());
1121 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetSecond());
1122 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetMillisecond());
1123 #endif // CHANGE_SYSTEM_DATE
1126 void DateTimeTestCase::TestDateOnly()
1128 wxDateTime
dt(19, wxDateTime::Jan
, 2007, 15, 01, 00);
1130 static const wxDateTime::wxDateTime_t DATE_ZERO
= 0;
1131 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetHour() );
1132 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMinute() );
1133 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetSecond() );
1134 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMillisecond() );
1137 CPPUNIT_ASSERT_EQUAL( wxDateTime(19, wxDateTime::Jan
, 2007), dt
);
1139 CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), wxDateTime::Now().GetDateOnly() );
1142 #endif // wxUSE_DATETIME