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 class setting the locale to "C" for its lifetime
90 CLocaleSetter() : m_locOld(setlocale(LC_ALL
, "C")) { }
91 ~CLocaleSetter() { setlocale(LC_ALL
, m_locOld
); }
94 const char * const m_locOld
;
96 wxDECLARE_NO_COPY_CLASS(CLocaleSetter
);
99 // ----------------------------------------------------------------------------
100 // broken down date representation used for testing
101 // ----------------------------------------------------------------------------
105 wxDateTime
::wxDateTime_t day
;
106 wxDateTime
::Month month
;
108 wxDateTime
::wxDateTime_t hour
, min
, sec
;
110 wxDateTime
::WeekDay wday
;
113 void Init(const wxDateTime
::Tm
& tm
)
125 wxDateTime
DT() const
126 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
128 bool SameDay(const wxDateTime
::Tm
& tm
) const
130 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
133 wxString
Format() const
136 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
138 wxDateTime
::GetMonthName(month
).c_str(),
140 abs(wxDateTime
::ConvertYearToBC(year
)),
141 year
> 0 ?
_T("AD") : _T("BC"));
145 wxString
FormatDate() const
148 s
.Printf(_T("%02d-%s-%4d%s"),
150 wxDateTime
::GetMonthName(month
, wxDateTime
::Name_Abbr
).c_str(),
151 abs(wxDateTime
::ConvertYearToBC(year
)),
152 year
> 0 ?
_T("AD") : _T("BC"));
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 static const Date testDates
[] =
163 { 1, wxDateTime
::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime
::Thu
, 0 },
164 { 7, wxDateTime
::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime
::Thu
, -1 },
165 { 8, wxDateTime
::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime
::Fri
, -1 },
166 { 1, wxDateTime
::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime
::Thu
, -1 },
167 { 1, wxDateTime
::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime
::Fri
, -1 },
168 { 21, wxDateTime
::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime
::Mon
, -1 },
169 { 29, wxDateTime
::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime
::Sat
, 202219200 },
170 { 29, wxDateTime
::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime
::Sun
, 194400000 },
171 { 1, wxDateTime
::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime
::Mon
, -1 },
172 { 1, wxDateTime
::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime
::Mon
, -1 },
173 { 15, wxDateTime
::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime
::Fri
, -1 },
174 { 4, wxDateTime
::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime
::Mon
, -1 },
175 { 1, wxDateTime
::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime
::Thu
, -1 },
176 { 1, wxDateTime
::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime
::Mon
, -1 },
177 { 31, wxDateTime
::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime
::Sun
, -1 },
178 { 1, wxDateTime
::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime
::Sat
, -1 },
179 { 12, wxDateTime
::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime
::Fri
, -1 },
180 { 12, wxDateTime
::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime
::Sat
, -1 },
181 { 24, wxDateTime
::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime
::Mon
, -1 },
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 class DateTimeTestCase
: public CppUnit
::TestCase
192 DateTimeTestCase() { }
195 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
196 CPPUNIT_TEST( TestLeapYears
);
197 CPPUNIT_TEST( TestTimeSet
);
198 CPPUNIT_TEST( TestTimeJDN
);
199 CPPUNIT_TEST( TestTimeWNumber
);
200 CPPUNIT_TEST( TestTimeWDays
);
201 CPPUNIT_TEST( TestTimeDST
);
202 CPPUNIT_TEST( TestTimeFormat
);
203 CPPUNIT_TEST( TestTimeSpanFormat
);
204 CPPUNIT_TEST( TestTimeTicks
);
205 CPPUNIT_TEST( TestParceRFC822
);
206 CPPUNIT_TEST( TestDateParse
);
207 CPPUNIT_TEST( TestDateParseISO
);
208 CPPUNIT_TEST( TestDateTimeParse
);
209 CPPUNIT_TEST( TestTimeArithmetics
);
210 CPPUNIT_TEST( TestDSTBug
);
211 CPPUNIT_TEST( TestDateOnly
);
212 CPPUNIT_TEST_SUITE_END();
214 void TestLeapYears();
217 void TestTimeWNumber();
218 void TestTimeWDays();
220 void TestTimeFormat();
221 void TestTimeSpanFormat();
222 void TestTimeTicks();
223 void TestParceRFC822();
224 void TestDateParse();
225 void TestDateParseISO();
226 void TestDateTimeParse();
227 void TestTimeArithmetics();
231 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
234 // register in the unnamed registry so that these tests are run by default
235 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
237 // also include in it's own registry so that these tests can be run alone
238 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
240 // ============================================================================
242 // ============================================================================
244 // test leap years detection
245 void DateTimeTestCase
::TestLeapYears()
247 static const struct LeapYearTestData
263 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
265 const LeapYearTestData
& y
= years
[n
];
267 CPPUNIT_ASSERT( wxDateTime
::IsLeapYear(y
.year
) == y
.isLeap
);
271 // test constructing wxDateTime objects
272 void DateTimeTestCase
::TestTimeSet()
274 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
276 const Date
& d1
= testDates
[n
];
277 wxDateTime dt
= d1
.DT();
282 wxString s1
= d1
.Format(),
285 CPPUNIT_ASSERT( s1
== s2
);
289 // test conversions to JDN &c
290 void DateTimeTestCase
::TestTimeJDN()
292 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
294 const Date
& d
= testDates
[n
];
295 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
297 // JDNs must be computed for UTC times
298 double jdn
= dt
.FromUTC().GetJulianDayNumber();
300 CPPUNIT_ASSERT_EQUAL( d
.jdn
, jdn
);
303 CPPUNIT_ASSERT_EQUAL( jdn
, dt
.GetJulianDayNumber() );
307 // test week days computation
308 void DateTimeTestCase
::TestTimeWDays()
312 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
314 const Date
& d
= testDates
[n
];
315 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
317 wxDateTime
::WeekDay wday
= dt
.GetWeekDay();
318 CPPUNIT_ASSERT( wday
== d
.wday
);
321 // test SetToWeekDay()
322 struct WeekDateTestData
324 Date date
; // the real date (precomputed)
325 int nWeek
; // its week index in the month
326 wxDateTime
::WeekDay wday
; // the weekday
327 wxDateTime
::Month month
; // the month
328 int year
; // and the year
330 wxString
Format() const
333 switch ( nWeek
< -1 ?
-nWeek
: nWeek
)
335 case 1: which
= _T("first"); break;
336 case 2: which
= _T("second"); break;
337 case 3: which
= _T("third"); break;
338 case 4: which
= _T("fourth"); break;
339 case 5: which
= _T("fifth"); break;
341 case -1: which
= _T("last"); break;
346 which
+= _T(" from end");
349 s
.Printf(_T("The %s %s of %s in %d"),
351 wxDateTime
::GetWeekDayName(wday
).c_str(),
352 wxDateTime
::GetMonthName(month
).c_str(),
359 // the array data was generated by the following python program
361 from DateTime import *
362 from whrandom import *
365 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
366 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
368 week = DateTimeDelta(7)
371 year = randint(1900, 2100)
372 month = randint(1, 12)
374 dt = DateTime(year, month, day)
375 wday = dt.day_of_week
377 countFromEnd = choice([-1, 1])
380 while dt.month is month:
381 dt = dt - countFromEnd * week
382 weekNum = weekNum + countFromEnd
384 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
386 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
387 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
390 static const WeekDateTestData weekDatesTestData
[] =
392 { { 20, wxDateTime
::Mar
, 2045, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Mon
, wxDateTime
::Mar
, 2045 },
393 { { 5, wxDateTime
::Jun
, 1985, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Wed
, wxDateTime
::Jun
, 1985 },
394 { { 12, wxDateTime
::Nov
, 1961, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -3, wxDateTime
::Sun
, wxDateTime
::Nov
, 1961 },
395 { { 27, wxDateTime
::Feb
, 2093, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -1, wxDateTime
::Fri
, wxDateTime
::Feb
, 2093 },
396 { { 4, wxDateTime
::Jul
, 2070, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Fri
, wxDateTime
::Jul
, 2070 },
397 { { 2, wxDateTime
::Apr
, 1906, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -5, wxDateTime
::Mon
, wxDateTime
::Apr
, 1906 },
398 { { 19, wxDateTime
::Jul
, 2023, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -2, wxDateTime
::Wed
, wxDateTime
::Jul
, 2023 },
399 { { 5, wxDateTime
::May
, 1958, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Mon
, wxDateTime
::May
, 1958 },
400 { { 11, wxDateTime
::Aug
, 1900, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 2, wxDateTime
::Sat
, wxDateTime
::Aug
, 1900 },
401 { { 14, wxDateTime
::Feb
, 1945, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 2, wxDateTime
::Wed
, wxDateTime
::Feb
, 1945 },
402 { { 25, wxDateTime
::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -1, wxDateTime
::Tue
, wxDateTime
::Jul
, 1967 },
403 { { 9, wxDateTime
::May
, 1916, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Tue
, wxDateTime
::May
, 1916 },
404 { { 20, wxDateTime
::Jun
, 1927, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Mon
, wxDateTime
::Jun
, 1927 },
405 { { 2, wxDateTime
::Aug
, 2000, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, wxDateTime
::Wed
, wxDateTime
::Aug
, 2000 },
406 { { 20, wxDateTime
::Apr
, 2044, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Wed
, wxDateTime
::Apr
, 2044 },
407 { { 20, wxDateTime
::Feb
, 1932, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -2, wxDateTime
::Sat
, wxDateTime
::Feb
, 1932 },
408 { { 25, wxDateTime
::Jul
, 2069, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 4, wxDateTime
::Thu
, wxDateTime
::Jul
, 2069 },
409 { { 3, wxDateTime
::Apr
, 1925, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, wxDateTime
::Fri
, wxDateTime
::Apr
, 1925 },
410 { { 21, wxDateTime
::Mar
, 2093, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Sat
, wxDateTime
::Mar
, 2093 },
411 { { 3, wxDateTime
::Dec
, 2074, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -5, wxDateTime
::Mon
, wxDateTime
::Dec
, 2074 }
415 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
417 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
419 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
421 const Date
& d
= wd
.date
;
422 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
426 // test the computation of (ISO) week numbers
427 void DateTimeTestCase
::TestTimeWNumber()
429 struct WeekNumberTestData
431 Date date
; // the date
432 wxDateTime
::wxDateTime_t week
; // the week number in the year
433 wxDateTime
::wxDateTime_t wmon
; // the week number in the month
434 wxDateTime
::wxDateTime_t wmon2
; // same but week starts with Sun
435 wxDateTime
::wxDateTime_t dnum
; // day number in the year
438 // data generated with the following python script:
440 from DateTime import *
441 from whrandom import *
444 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
445 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
447 def GetMonthWeek(dt):
448 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
450 weekNumMonth = weekNumMonth + 53
453 def GetLastSundayBefore(dt):
454 if dt.iso_week[2] == 7:
457 return dt - DateTimeDelta(dt.iso_week[2])
460 year = randint(1900, 2100)
461 month = randint(1, 12)
463 dt = DateTime(year, month, day)
464 dayNum = dt.day_of_year
465 weekNum = dt.iso_week[1]
466 weekNumMonth = GetMonthWeek(dt)
469 dtSunday = GetLastSundayBefore(dt)
471 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
472 weekNumMonth2 = weekNumMonth2 + 1
473 dtSunday = dtSunday - DateTimeDelta(7)
475 data = { 'day': rjust(`day`, 2), \
476 'month': monthNames[month - 1], \
478 'weekNum': rjust(`weekNum`, 2), \
479 'weekNumMonth': weekNumMonth, \
480 'weekNumMonth2': weekNumMonth2, \
481 'dayNum': rjust(`dayNum`, 3) }
483 print " { { %(day)s, "\
484 "wxDateTime::%(month)s, "\
487 "%(weekNumMonth)s, "\
488 "%(weekNumMonth2)s, "\
489 "%(dayNum)s }," % data
492 static const WeekNumberTestData weekNumberTestDates
[] =
494 { { 27, wxDateTime
::Dec
, 1966, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 52, 5, 5, 361 },
495 { { 22, wxDateTime
::Jul
, 1926, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 29, 4, 4, 203 },
496 { { 22, wxDateTime
::Oct
, 2076, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 43, 4, 4, 296 },
497 { { 1, wxDateTime
::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 26, 1, 1, 182 },
498 { { 8, wxDateTime
::Nov
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 46, 2, 2, 313 },
499 { { 21, wxDateTime
::Mar
, 1920, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 12, 3, 4, 81 },
500 { { 7, wxDateTime
::Jan
, 1965, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 2, 2, 7 },
501 { { 19, wxDateTime
::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 42, 4, 4, 292 },
502 { { 13, wxDateTime
::Aug
, 1955, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 32, 2, 2, 225 },
503 { { 18, wxDateTime
::Jul
, 2087, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 29, 3, 3, 199 },
504 { { 2, wxDateTime
::Sep
, 2028, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 35, 1, 1, 246 },
505 { { 28, wxDateTime
::Jul
, 1945, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 30, 5, 4, 209 },
506 { { 15, wxDateTime
::Jun
, 1901, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 24, 3, 3, 166 },
507 { { 10, wxDateTime
::Oct
, 1939, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 41, 3, 2, 283 },
508 { { 3, wxDateTime
::Dec
, 1965, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 48, 1, 1, 337 },
509 { { 23, wxDateTime
::Feb
, 1940, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 8, 4, 4, 54 },
510 { { 2, wxDateTime
::Jan
, 1987, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
511 { { 11, wxDateTime
::Aug
, 2079, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 32, 2, 2, 223 },
512 { { 2, wxDateTime
::Feb
, 2063, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 5, 1, 1, 33 },
513 { { 16, wxDateTime
::Oct
, 1942, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 42, 3, 3, 289 },
514 { { 30, wxDateTime
::Dec
, 2003, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 5, 5, 364 },
515 { { 2, wxDateTime
::Jan
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
518 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
520 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
521 const Date
& d
= wn
.date
;
523 wxDateTime dt
= d
.DT();
525 wxDateTime
::wxDateTime_t
526 week
= dt
.GetWeekOfYear(wxDateTime
::Monday_First
),
527 wmon
= dt
.GetWeekOfMonth(wxDateTime
::Monday_First
),
528 wmon2
= dt
.GetWeekOfMonth(wxDateTime
::Sunday_First
),
529 dnum
= dt
.GetDayOfYear();
531 CPPUNIT_ASSERT( dnum
== wn
.dnum
);
532 CPPUNIT_ASSERT( wmon
== wn
.wmon
);
533 CPPUNIT_ASSERT( wmon2
== wn
.wmon2
);
534 CPPUNIT_ASSERT( week
== wn
.week
);
537 if ( week
== 1 && d
.month
!= wxDateTime
::Jan
)
539 // this means we're in the first week of the next year
544 dt2
= wxDateTime
::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
545 CPPUNIT_ASSERT( dt2
== dt
);
549 // test DST applicability
550 void DateTimeTestCase
::TestTimeDST()
552 // taken from http://www.energy.ca.gov/daylightsaving.html
553 static const Date datesDST
[2][2009 - 1990 + 1] =
556 { 1, wxDateTime
::Apr
, 1990, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
557 { 7, wxDateTime
::Apr
, 1991, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
558 { 5, wxDateTime
::Apr
, 1992, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
559 { 4, wxDateTime
::Apr
, 1993, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
560 { 3, wxDateTime
::Apr
, 1994, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
561 { 2, wxDateTime
::Apr
, 1995, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
562 { 7, wxDateTime
::Apr
, 1996, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
563 { 6, wxDateTime
::Apr
, 1997, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
564 { 5, wxDateTime
::Apr
, 1998, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
565 { 4, wxDateTime
::Apr
, 1999, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
566 { 2, wxDateTime
::Apr
, 2000, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
567 { 1, wxDateTime
::Apr
, 2001, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
568 { 7, wxDateTime
::Apr
, 2002, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
569 { 6, wxDateTime
::Apr
, 2003, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
570 { 4, wxDateTime
::Apr
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
571 { 3, wxDateTime
::Apr
, 2005, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
572 { 2, wxDateTime
::Apr
, 2006, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
573 {11, wxDateTime
::Mar
, 2007, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
574 { 9, wxDateTime
::Mar
, 2008, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
575 { 8, wxDateTime
::Mar
, 2009, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
578 { 28, wxDateTime
::Oct
, 1990, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
579 { 27, wxDateTime
::Oct
, 1991, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
580 { 25, wxDateTime
::Oct
, 1992, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
581 { 31, wxDateTime
::Oct
, 1993, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
582 { 30, wxDateTime
::Oct
, 1994, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
583 { 29, wxDateTime
::Oct
, 1995, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
584 { 27, wxDateTime
::Oct
, 1996, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
585 { 26, wxDateTime
::Oct
, 1997, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
586 { 25, wxDateTime
::Oct
, 1998, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
587 { 31, wxDateTime
::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
588 { 29, wxDateTime
::Oct
, 2000, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
589 { 28, wxDateTime
::Oct
, 2001, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
590 { 27, wxDateTime
::Oct
, 2002, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
591 { 26, wxDateTime
::Oct
, 2003, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
592 { 31, wxDateTime
::Oct
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
593 { 30, wxDateTime
::Oct
, 2005, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
594 { 29, wxDateTime
::Oct
, 2006, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
595 { 4, wxDateTime
::Nov
, 2007, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
596 { 2, wxDateTime
::Nov
, 2008, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
597 { 1, wxDateTime
::Nov
, 2009, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
602 for ( size_t n
= 0; n
< WXSIZEOF(datesDST
[0]); n
++ )
604 const int year
= 1990 + n
;
605 wxDateTime dtBegin
= wxDateTime
::GetBeginDST(year
, wxDateTime
::USA
),
606 dtEnd
= wxDateTime
::GetEndDST(year
, wxDateTime
::USA
);
608 const Date
& dBegin
= datesDST
[0][n
];
609 const Date
& dEnd
= datesDST
[1][n
];
611 CPPUNIT_ASSERT_EQUAL( dBegin
.DT().FormatDate(), dtBegin
.FormatDate() );
612 CPPUNIT_ASSERT_EQUAL( dEnd
.DT().FormatDate(), dtEnd
.FormatDate() );
616 // test wxDateTime -> text conversion
617 void DateTimeTestCase
::TestTimeFormat()
619 // some information may be lost during conversion, so store what kind
620 // of info should we recover after a round trip
623 CompareNone
, // don't try comparing
624 CompareBoth
, // dates and times should be identical
625 CompareYear
, // don't compare centuries (fails for 2 digit years)
626 CompareDate
, // dates only
627 CompareTime
// time only
632 CompareKind compareKind
;
634 } formatTestFormats
[] =
636 { CompareYear
, "---> %c" }, // %c could use 2 digit years
637 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
638 { CompareYear
, "Date is %x, time is %X" }, // %x could use 2 digits
639 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
640 { CompareNone
, "The day of year: %j, the week of year: %W" },
641 { CompareDate
, "ISO date without separators: %Y%m%d" },
644 static const Date formatTestDates
[] =
646 { 29, wxDateTime
::May
, 1976, 18, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
647 { 31, wxDateTime
::Dec
, 1999, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
648 { 6, wxDateTime
::Feb
, 1937, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
649 { 6, wxDateTime
::Feb
, 1856, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
650 { 6, wxDateTime
::Feb
, 1857, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
651 { 29, wxDateTime
::May
, 2076, 18, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
652 { 29, wxDateTime
::Feb
, 2400, 02, 15, 25, 0.0, wxDateTime
::Inv_WeekDay
},
654 // Need to add support for BCE dates.
655 { 01, wxDateTime
::Jan
, -52, 03, 16, 47, 0.0, wxDateTime
::Inv_WeekDay
},
659 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
); d
++ )
661 wxDateTime dt
= formatTestDates
[d
].DT();
662 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
664 const char *fmt
= formatTestFormats
[n
].format
;
666 // skip the check with %p for those locales which have empty AM/PM strings:
667 // for those locales it's impossible to pass the test with %p...
669 wxDateTime
::GetAmPmStrings(&am
, &pm
);
670 if (am
.empty() && pm
.empty() && wxStrstr(fmt
, "%p") != NULL
)
673 wxString s
= dt
.Format(fmt
);
675 // what can we recover?
676 CompareKind kind
= formatTestFormats
[n
].compareKind
;
680 const char *result
= dt2
.ParseFormat(s
, fmt
);
683 // conversion failed - should it have?
684 CPPUNIT_ASSERT( kind
== CompareNone
);
686 else // conversion succeeded
688 // ParseFormat() should have parsed the entire string or left
689 // some final useless strings (e.g. with Italian locale the
690 // 's' string for the first test date looks like
691 // "---> sab 29 mag 1976 18:30:00 CET"
692 // so we just need to ignore CET)
693 CPPUNIT_ASSERT( !*result
|| strcmp(result
, "CET") == 0 );
698 if ( dt2
.GetCentury() != dt
.GetCentury() )
700 CPPUNIT_ASSERT_EQUAL(dt
.GetYear() % 100,
701 dt2
.GetYear() % 100);
703 dt2
.SetYear(dt
.GetYear());
705 // fall through and compare everything
708 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
712 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
716 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
720 wxFAIL_MSG( _T("unexpected") );
729 // test partially specified dates too
730 wxDateTime
dtDef(26, wxDateTime
::Sep
, 2008);
731 CPPUNIT_ASSERT( dt
.ParseFormat("17", "%d") );
732 CPPUNIT_ASSERT_EQUAL( 17, dt
.GetDay() );
734 // test compilation of some calls which should compile (and not result in
735 // ambiguity because of char*<->wxCStrData<->wxString conversions)
737 CPPUNIT_ASSERT( !dt
.ParseFormat("foo") );
738 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo")) );
739 CPPUNIT_ASSERT( !dt
.ParseFormat(s
) );
740 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str()) );
742 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", "%c") );
743 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), "%c") );
744 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
745 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), "%c") );
747 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", wxT("%c")) );
748 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), wxT("%c")) );
749 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
750 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), wxT("%c")) );
753 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", spec
) );
754 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), spec
) );
755 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, spec
) );
756 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), spec
) );
759 void DateTimeTestCase
::TestTimeSpanFormat()
761 static const struct TimeSpanFormatTestData
763 long h
, min
, sec
, msec
;
768 { 12, 34, 56, 789, "%H:%M:%S.%l", "12:34:56.789" },
769 { 1, 2, 3, 0, "%H:%M:%S", "01:02:03" },
770 { 1, 2, 3, 0, "%S", "3723" },
771 { -1, -2, -3, 0, "%S", "-3723" },
772 { -1, -2, -3, 0, "%H:%M:%S", "-01:02:03" },
773 { 26, 0, 0, 0, "%H", "26" },
774 { 26, 0, 0, 0, "%D, %H", "1, 02" },
775 { -26, 0, 0, 0, "%H", "-26" },
776 { -26, 0, 0, 0, "%D, %H", "-1, 02" },
777 { 219, 0, 0, 0, "%H", "219" },
778 { 219, 0, 0, 0, "%D, %H", "9, 03" },
779 { 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
780 { 0, -1, 0, 0, "%H:%M:%S", "-00:01:00" },
781 { 0, 0, -1, 0, "%H:%M:%S", "-00:00:01" },
784 for ( size_t n
= 0; n
< WXSIZEOF(testSpans
); n
++ )
786 const TimeSpanFormatTestData
& td
= testSpans
[n
];
787 wxTimeSpan
ts(td
.h
, td
.min
, td
.sec
, td
.msec
);
788 CPPUNIT_ASSERT_EQUAL( td
.result
, ts
.Format(td
.fmt
) );
792 void DateTimeTestCase
::TestTimeTicks()
794 static const wxDateTime
::TimeZone
TZ_LOCAL(wxDateTime
::Local
);
795 static const wxDateTime
::TimeZone
TZ_TEST(wxDateTime
::NZST
);
797 // this offset is needed to make the test work in any time zone when we
798 // only have expected test results in UTC in testDates
799 static const long tzOffset
= TZ_LOCAL
.GetOffset() - TZ_TEST
.GetOffset();
801 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
803 const Date
& d
= testDates
[n
];
804 if ( d
.gmticks
== -1 )
807 wxDateTime dt
= d
.DT().MakeTimezone(TZ_TEST
, true /* no DST */);
809 // GetValue() returns internal UTC-based representation, we need to
810 // convert it to local TZ before comparing
811 time_t ticks
= (dt
.GetValue() / 1000).ToLong() + TZ_LOCAL
.GetOffset();
814 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
+ tzOffset
);
816 dt
= d
.DT().FromTimezone(wxDateTime
::UTC
);
817 ticks
= (dt
.GetValue() / 1000).ToLong();
818 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
);
822 // test parsing dates in RFC822 format
823 void DateTimeTestCase
::TestParceRFC822()
825 static const struct ParseTestData
828 Date date
; // NB: this should be in UTC
833 "Sat, 18 Dec 1999 00:46:40 +0100",
834 { 17, wxDateTime
::Dec
, 1999, 23, 46, 40 },
838 "Wed, 1 Dec 1999 05:17:20 +0300",
839 { 1, wxDateTime
::Dec
, 1999, 2, 17, 20 },
843 "Sun, 28 Aug 2005 03:31:30 +0200",
844 { 28, wxDateTime
::Aug
, 2005, 1, 31, 30 },
849 "Sat, 18 Dec 1999 10:48:30 -0500",
850 { 18, wxDateTime
::Dec
, 1999, 15, 48, 30 },
854 // seconds are optional according to the RFC
856 "Sun, 01 Jun 2008 16:30 +0200",
857 { 1, wxDateTime
::Jun
, 2008, 14, 30, 00 },
861 // try some bogus ones too
863 "Sun, 01 Jun 2008 16:30: +0200",
869 for ( unsigned n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
871 const char * const datestr
= parseTestDates
[n
].rfc822
;
874 if ( dt
.ParseRfc822Date(datestr
) )
877 ("Erroneously parsed \"%s\"", datestr
),
878 parseTestDates
[n
].good
881 wxDateTime dtReal
= parseTestDates
[n
].date
.DT().FromUTC();
882 CPPUNIT_ASSERT_EQUAL( dtReal
, dt
);
884 else // failed to parse
887 ("Failed to parse \"%s\"", datestr
),
888 !parseTestDates
[n
].good
894 // test parsing dates in free format
895 void DateTimeTestCase
::TestDateParse()
897 static const struct ParseTestData
900 Date date
; // NB: this should be in UTC
904 { "21 Mar 2006", { 21, wxDateTime
::Mar
, 2006 }, true },
905 { "29 Feb 1976", { 29, wxDateTime
::Feb
, 1976 }, true },
906 { "Feb 29 1976", { 29, wxDateTime
::Feb
, 1976 }, true },
907 { "31/03/06", { 31, wxDateTime
::Mar
, 6 }, true },
908 { "31/03/2006", { 31, wxDateTime
::Mar
, 2006 }, true },
910 // some invalid ones too
918 CPPUNIT_ASSERT( dt
.ParseDate(_T("today")) );
919 CPPUNIT_ASSERT_EQUAL( wxDateTime
::Today(), dt
);
921 // the other test strings use "C" locale so set it for the duration of this
925 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
927 const char * const datestr
= parseTestDates
[n
].str
;
929 const char * const end
= dt
.ParseDate(datestr
);
933 ("Erroneously parsed \"%s\"", datestr
),
934 parseTestDates
[n
].good
937 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
939 else // failed to parse
942 ("Failed to parse \"%s\"", datestr
),
943 !parseTestDates
[n
].good
949 void DateTimeTestCase
::TestDateParseISO()
954 Date date
; // NB: this should be in UTC
958 { "2006-03-21", { 21, wxDateTime
::Mar
, 2006 }, true },
959 { "1976-02-29", { 29, wxDateTime
::Feb
, 1976 }, true },
960 { "0006-03-31", { 31, wxDateTime
::Mar
, 6 }, true },
962 // some invalid ones too
972 wxDateTime
::wxDateTime_t hour
, min
, sec
;
976 { "13:42:17", 13, 42, 17, true },
977 { "02:17:01", 2, 17, 1, true },
979 // some invalid ones too
986 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
989 if ( dt
.ParseISODate(parseTestDates
[n
].str
) )
991 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
993 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
995 for ( size_t m
= 0; m
< WXSIZEOF(parseTestTimes
); m
++ )
998 dtCombined
<< parseTestDates
[n
].str
1000 << parseTestTimes
[m
].str
;
1002 if ( dt
.ParseISOCombined(dtCombined
) )
1004 CPPUNIT_ASSERT( parseTestTimes
[m
].good
);
1006 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].hour
, dt
.GetHour()) ;
1007 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].min
, dt
.GetMinute()) ;
1008 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].sec
, dt
.GetSecond()) ;
1010 else // failed to parse combined date/time
1012 CPPUNIT_ASSERT( !parseTestTimes
[m
].good
);
1016 else // failed to parse
1018 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1023 void DateTimeTestCase
::TestDateTimeParse()
1025 static const struct ParseTestData
1028 Date date
; // NB: this should be in UTC
1030 } parseTestDates
[] =
1032 { "Thu 22 Nov 2007 07:40:00 PM",
1033 { 22, wxDateTime
::Nov
, 2007, 19, 40, 0}, true },
1036 // the test strings use "C" locale so set it for the duration of this test
1040 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1042 const char * const datestr
= parseTestDates
[n
].str
;
1044 if ( dt
.ParseDateTime(datestr
) )
1047 ("Erroneously parsed \"%s\"", datestr
),
1048 parseTestDates
[n
].good
1051 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1053 else // failed to parse
1056 ("Failed to parse \"%s\"", datestr
),
1057 !parseTestDates
[n
].good
1060 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1065 void DateTimeTestCase
::TestTimeArithmetics()
1067 static const wxDateSpan testArithmData
[] =
1071 wxDateSpan
::Month(),
1075 // the test will *not* work with arbitrary date!
1076 wxDateTime
dt(2, wxDateTime
::Dec
, 1999),
1080 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
1082 const wxDateSpan
& span
= testArithmData
[n
];
1086 CPPUNIT_ASSERT( dt1
- span
== dt
);
1087 CPPUNIT_ASSERT( dt2
+ span
== dt
);
1088 CPPUNIT_ASSERT( dt2
+ 2*span
== dt1
);
1092 void DateTimeTestCase
::TestDSTBug()
1094 /////////////////////////
1096 wxDateTime dt
= wxDateTime
::GetEndDST(2004, wxDateTime
::France
);
1097 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1098 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1099 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1100 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1101 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1102 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1103 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1105 /////////////////////////
1108 CPPUNIT_ASSERT_EQUAL(5, (int)dt
.GetHour());
1110 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1111 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1112 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1113 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1114 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1115 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1116 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1119 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1121 /////////////////////////
1123 #ifdef CHANGE_SYSTEM_DATE
1125 DateChanger
change(2004, 10, 31, 5, 0, 0);
1126 dt
= wxDateTime
::Today();
1129 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1130 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1131 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1132 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1133 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1134 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1135 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1137 /////////////////////////
1138 // Test Set(hour, minute, second, milli)
1141 DateChanger
change(2004, 10, 31, 5, 0, 0);
1142 dt
.Set(1, 30, 0, 0);
1143 dt2
.Set(5, 30, 0, 0);
1146 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1147 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1148 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1149 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1150 CPPUNIT_ASSERT_EQUAL(30, (int)dt
.GetMinute());
1151 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1152 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1154 CPPUNIT_ASSERT_EQUAL(31, (int)dt2
.GetDay());
1155 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt2
.GetMonth());
1156 CPPUNIT_ASSERT_EQUAL(2004, (int)dt2
.GetYear());
1157 CPPUNIT_ASSERT_EQUAL(5, (int)dt2
.GetHour());
1158 CPPUNIT_ASSERT_EQUAL(30, (int)dt2
.GetMinute());
1159 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetSecond());
1160 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetMillisecond());
1161 #endif // CHANGE_SYSTEM_DATE
1164 void DateTimeTestCase
::TestDateOnly()
1166 wxDateTime
dt(19, wxDateTime
::Jan
, 2007, 15, 01, 00);
1168 static const wxDateTime
::wxDateTime_t DATE_ZERO
= 0;
1169 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetHour() );
1170 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMinute() );
1171 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetSecond() );
1172 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMillisecond() );
1175 CPPUNIT_ASSERT_EQUAL( wxDateTime(19, wxDateTime
::Jan
, 2007), dt
);
1177 CPPUNIT_ASSERT_EQUAL( wxDateTime
::Today(), wxDateTime
::Now().GetDateOnly() );
1180 #endif // wxUSE_DATETIME