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"
27 // need this to be able to use CPPUNIT_ASSERT_EQUAL with wxDateTime objects
28 static std
::ostream
& operator<<(std
::ostream
& ostr
, const wxDateTime
& dt
)
30 ostr
<< dt
.FormatISOCombined(' ');
35 WX_CPPUNIT_ALLOW_EQUALS_TO_INT(wxDateTime
::wxDateTime_t
)
37 // to test Today() meaningfully we must be able to change the system date which
38 // is not usually the case, but if we're under Win32 we can try it -- define
39 // the macro below to do it
40 //#define CHANGE_SYSTEM_DATE
43 #undef CHANGE_SYSTEM_DATE
46 #ifdef CHANGE_SYSTEM_DATE
51 DateChanger(int year
, int month
, int day
, int hour
, int min
, int sec
)
62 ::GetSystemTime(&m_savedTime
);
63 ::GetTimeZoneInformation(&m_tzi
);
65 m_changed
= ::SetSystemTime(&st
) != 0;
72 ::SetSystemTime(&m_savedTime
);
73 ::SetTimeZoneInformation(&m_tzi
);
78 SYSTEMTIME m_savedTime
;
79 TIME_ZONE_INFORMATION m_tzi
;
83 #endif // CHANGE_SYSTEM_DATE
85 // ----------------------------------------------------------------------------
86 // broken down date representation used for testing
87 // ----------------------------------------------------------------------------
91 wxDateTime
::wxDateTime_t day
;
92 wxDateTime
::Month month
;
94 wxDateTime
::wxDateTime_t hour
, min
, sec
;
96 wxDateTime
::WeekDay wday
;
99 void Init(const wxDateTime
::Tm
& tm
)
111 wxDateTime
DT() const
112 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
114 bool SameDay(const wxDateTime
::Tm
& tm
) const
116 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
119 wxString
Format() const
122 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
124 wxDateTime
::GetMonthName(month
).c_str(),
126 abs(wxDateTime
::ConvertYearToBC(year
)),
127 year
> 0 ?
_T("AD") : _T("BC"));
131 wxString
FormatDate() const
134 s
.Printf(_T("%02d-%s-%4d%s"),
136 wxDateTime
::GetMonthName(month
, wxDateTime
::Name_Abbr
).c_str(),
137 abs(wxDateTime
::ConvertYearToBC(year
)),
138 year
> 0 ?
_T("AD") : _T("BC"));
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 static const Date testDates
[] =
149 { 1, wxDateTime
::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime
::Thu
, 0 },
150 { 7, wxDateTime
::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime
::Thu
, -1 },
151 { 8, wxDateTime
::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime
::Fri
, -1 },
152 { 1, wxDateTime
::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime
::Thu
, -1 },
153 { 1, wxDateTime
::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime
::Fri
, -1 },
154 { 21, wxDateTime
::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime
::Mon
, -1 },
155 { 29, wxDateTime
::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime
::Sat
, 202219200 },
156 { 29, wxDateTime
::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime
::Sun
, 194400000 },
157 { 1, wxDateTime
::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime
::Mon
, -1 },
158 { 1, wxDateTime
::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime
::Mon
, -1 },
159 { 15, wxDateTime
::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime
::Fri
, -1 },
160 { 4, wxDateTime
::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime
::Mon
, -1 },
161 { 1, wxDateTime
::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime
::Thu
, -1 },
162 { 1, wxDateTime
::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime
::Mon
, -1 },
163 { 31, wxDateTime
::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime
::Sun
, -1 },
164 { 1, wxDateTime
::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime
::Sat
, -1 },
165 { 12, wxDateTime
::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime
::Fri
, -1 },
166 { 12, wxDateTime
::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime
::Sat
, -1 },
167 { 24, wxDateTime
::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime
::Mon
, -1 },
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 class DateTimeTestCase
: public CppUnit
::TestCase
178 DateTimeTestCase() { }
181 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
182 CPPUNIT_TEST( TestLeapYears
);
183 CPPUNIT_TEST( TestTimeSet
);
184 CPPUNIT_TEST( TestTimeJDN
);
185 CPPUNIT_TEST( TestTimeWNumber
);
186 CPPUNIT_TEST( TestTimeWDays
);
187 CPPUNIT_TEST( TestTimeDST
);
188 CPPUNIT_TEST( TestTimeFormat
);
189 CPPUNIT_TEST( TestTimeSpanFormat
);
190 CPPUNIT_TEST( TestTimeTicks
);
191 CPPUNIT_TEST( TestParceRFC822
);
192 CPPUNIT_TEST( TestDateParse
);
193 CPPUNIT_TEST( TestDateParseISO
);
194 CPPUNIT_TEST( TestDateTimeParse
);
195 CPPUNIT_TEST( TestTimeArithmetics
);
196 CPPUNIT_TEST( TestDSTBug
);
197 CPPUNIT_TEST( TestDateOnly
);
198 CPPUNIT_TEST_SUITE_END();
200 void TestLeapYears();
203 void TestTimeWNumber();
204 void TestTimeWDays();
206 void TestTimeFormat();
207 void TestTimeSpanFormat();
208 void TestTimeTicks();
209 void TestParceRFC822();
210 void TestDateParse();
211 void TestDateParseISO();
212 void TestDateTimeParse();
213 void TestTimeArithmetics();
217 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
220 // register in the unnamed registry so that these tests are run by default
221 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
223 // also include in it's own registry so that these tests can be run alone
224 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
226 // ============================================================================
228 // ============================================================================
230 // test leap years detection
231 void DateTimeTestCase
::TestLeapYears()
233 static const struct LeapYearTestData
249 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
251 const LeapYearTestData
& y
= years
[n
];
253 CPPUNIT_ASSERT( wxDateTime
::IsLeapYear(y
.year
) == y
.isLeap
);
257 // test constructing wxDateTime objects
258 void DateTimeTestCase
::TestTimeSet()
260 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
262 const Date
& d1
= testDates
[n
];
263 wxDateTime dt
= d1
.DT();
268 wxString s1
= d1
.Format(),
271 CPPUNIT_ASSERT( s1
== s2
);
275 // test conversions to JDN &c
276 void DateTimeTestCase
::TestTimeJDN()
278 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
280 const Date
& d
= testDates
[n
];
281 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
283 // JDNs must be computed for UTC times
284 double jdn
= dt
.FromUTC().GetJulianDayNumber();
286 CPPUNIT_ASSERT_EQUAL( d
.jdn
, jdn
);
289 CPPUNIT_ASSERT_EQUAL( jdn
, dt
.GetJulianDayNumber() );
293 // test week days computation
294 void DateTimeTestCase
::TestTimeWDays()
298 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
300 const Date
& d
= testDates
[n
];
301 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
303 wxDateTime
::WeekDay wday
= dt
.GetWeekDay();
304 CPPUNIT_ASSERT( wday
== d
.wday
);
307 // test SetToWeekDay()
308 struct WeekDateTestData
310 Date date
; // the real date (precomputed)
311 int nWeek
; // its week index in the month
312 wxDateTime
::WeekDay wday
; // the weekday
313 wxDateTime
::Month month
; // the month
314 int year
; // and the year
316 wxString
Format() const
319 switch ( nWeek
< -1 ?
-nWeek
: nWeek
)
321 case 1: which
= _T("first"); break;
322 case 2: which
= _T("second"); break;
323 case 3: which
= _T("third"); break;
324 case 4: which
= _T("fourth"); break;
325 case 5: which
= _T("fifth"); break;
327 case -1: which
= _T("last"); break;
332 which
+= _T(" from end");
335 s
.Printf(_T("The %s %s of %s in %d"),
337 wxDateTime
::GetWeekDayName(wday
).c_str(),
338 wxDateTime
::GetMonthName(month
).c_str(),
345 // the array data was generated by the following python program
347 from DateTime import *
348 from whrandom import *
351 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
352 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
354 week = DateTimeDelta(7)
357 year = randint(1900, 2100)
358 month = randint(1, 12)
360 dt = DateTime(year, month, day)
361 wday = dt.day_of_week
363 countFromEnd = choice([-1, 1])
366 while dt.month is month:
367 dt = dt - countFromEnd * week
368 weekNum = weekNum + countFromEnd
370 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
372 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
373 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
376 static const WeekDateTestData weekDatesTestData
[] =
378 { { 20, wxDateTime
::Mar
, 2045, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Mon
, wxDateTime
::Mar
, 2045 },
379 { { 5, wxDateTime
::Jun
, 1985, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Wed
, wxDateTime
::Jun
, 1985 },
380 { { 12, wxDateTime
::Nov
, 1961, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -3, wxDateTime
::Sun
, wxDateTime
::Nov
, 1961 },
381 { { 27, wxDateTime
::Feb
, 2093, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -1, wxDateTime
::Fri
, wxDateTime
::Feb
, 2093 },
382 { { 4, wxDateTime
::Jul
, 2070, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Fri
, wxDateTime
::Jul
, 2070 },
383 { { 2, wxDateTime
::Apr
, 1906, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -5, wxDateTime
::Mon
, wxDateTime
::Apr
, 1906 },
384 { { 19, wxDateTime
::Jul
, 2023, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -2, wxDateTime
::Wed
, wxDateTime
::Jul
, 2023 },
385 { { 5, wxDateTime
::May
, 1958, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Mon
, wxDateTime
::May
, 1958 },
386 { { 11, wxDateTime
::Aug
, 1900, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 2, wxDateTime
::Sat
, wxDateTime
::Aug
, 1900 },
387 { { 14, wxDateTime
::Feb
, 1945, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 2, wxDateTime
::Wed
, wxDateTime
::Feb
, 1945 },
388 { { 25, wxDateTime
::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -1, wxDateTime
::Tue
, wxDateTime
::Jul
, 1967 },
389 { { 9, wxDateTime
::May
, 1916, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -4, wxDateTime
::Tue
, wxDateTime
::May
, 1916 },
390 { { 20, wxDateTime
::Jun
, 1927, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Mon
, wxDateTime
::Jun
, 1927 },
391 { { 2, wxDateTime
::Aug
, 2000, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, wxDateTime
::Wed
, wxDateTime
::Aug
, 2000 },
392 { { 20, wxDateTime
::Apr
, 2044, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Wed
, wxDateTime
::Apr
, 2044 },
393 { { 20, wxDateTime
::Feb
, 1932, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -2, wxDateTime
::Sat
, wxDateTime
::Feb
, 1932 },
394 { { 25, wxDateTime
::Jul
, 2069, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 4, wxDateTime
::Thu
, wxDateTime
::Jul
, 2069 },
395 { { 3, wxDateTime
::Apr
, 1925, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, wxDateTime
::Fri
, wxDateTime
::Apr
, 1925 },
396 { { 21, wxDateTime
::Mar
, 2093, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 3, wxDateTime
::Sat
, wxDateTime
::Mar
, 2093 },
397 { { 3, wxDateTime
::Dec
, 2074, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, -5, wxDateTime
::Mon
, wxDateTime
::Dec
, 2074 }
401 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
403 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
405 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
407 const Date
& d
= wd
.date
;
408 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
412 // test the computation of (ISO) week numbers
413 void DateTimeTestCase
::TestTimeWNumber()
415 struct WeekNumberTestData
417 Date date
; // the date
418 wxDateTime
::wxDateTime_t week
; // the week number in the year
419 wxDateTime
::wxDateTime_t wmon
; // the week number in the month
420 wxDateTime
::wxDateTime_t wmon2
; // same but week starts with Sun
421 wxDateTime
::wxDateTime_t dnum
; // day number in the year
424 // data generated with the following python script:
426 from DateTime import *
427 from whrandom import *
430 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
431 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
433 def GetMonthWeek(dt):
434 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
436 weekNumMonth = weekNumMonth + 53
439 def GetLastSundayBefore(dt):
440 if dt.iso_week[2] == 7:
443 return dt - DateTimeDelta(dt.iso_week[2])
446 year = randint(1900, 2100)
447 month = randint(1, 12)
449 dt = DateTime(year, month, day)
450 dayNum = dt.day_of_year
451 weekNum = dt.iso_week[1]
452 weekNumMonth = GetMonthWeek(dt)
455 dtSunday = GetLastSundayBefore(dt)
457 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
458 weekNumMonth2 = weekNumMonth2 + 1
459 dtSunday = dtSunday - DateTimeDelta(7)
461 data = { 'day': rjust(`day`, 2), \
462 'month': monthNames[month - 1], \
464 'weekNum': rjust(`weekNum`, 2), \
465 'weekNumMonth': weekNumMonth, \
466 'weekNumMonth2': weekNumMonth2, \
467 'dayNum': rjust(`dayNum`, 3) }
469 print " { { %(day)s, "\
470 "wxDateTime::%(month)s, "\
473 "%(weekNumMonth)s, "\
474 "%(weekNumMonth2)s, "\
475 "%(dayNum)s }," % data
478 static const WeekNumberTestData weekNumberTestDates
[] =
480 { { 27, wxDateTime
::Dec
, 1966, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 52, 5, 5, 361 },
481 { { 22, wxDateTime
::Jul
, 1926, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 29, 4, 4, 203 },
482 { { 22, wxDateTime
::Oct
, 2076, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 43, 4, 4, 296 },
483 { { 1, wxDateTime
::Jul
, 1967, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 26, 1, 1, 182 },
484 { { 8, wxDateTime
::Nov
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 46, 2, 2, 313 },
485 { { 21, wxDateTime
::Mar
, 1920, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 12, 3, 4, 81 },
486 { { 7, wxDateTime
::Jan
, 1965, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 2, 2, 7 },
487 { { 19, wxDateTime
::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 42, 4, 4, 292 },
488 { { 13, wxDateTime
::Aug
, 1955, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 32, 2, 2, 225 },
489 { { 18, wxDateTime
::Jul
, 2087, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 29, 3, 3, 199 },
490 { { 2, wxDateTime
::Sep
, 2028, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 35, 1, 1, 246 },
491 { { 28, wxDateTime
::Jul
, 1945, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 30, 5, 4, 209 },
492 { { 15, wxDateTime
::Jun
, 1901, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 24, 3, 3, 166 },
493 { { 10, wxDateTime
::Oct
, 1939, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 41, 3, 2, 283 },
494 { { 3, wxDateTime
::Dec
, 1965, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 48, 1, 1, 337 },
495 { { 23, wxDateTime
::Feb
, 1940, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 8, 4, 4, 54 },
496 { { 2, wxDateTime
::Jan
, 1987, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
497 { { 11, wxDateTime
::Aug
, 2079, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 32, 2, 2, 223 },
498 { { 2, wxDateTime
::Feb
, 2063, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 5, 1, 1, 33 },
499 { { 16, wxDateTime
::Oct
, 1942, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 42, 3, 3, 289 },
500 { { 30, wxDateTime
::Dec
, 2003, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 5, 5, 364 },
501 { { 2, wxDateTime
::Jan
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 }, 1, 1, 1, 2 },
504 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
506 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
507 const Date
& d
= wn
.date
;
509 wxDateTime dt
= d
.DT();
511 wxDateTime
::wxDateTime_t
512 week
= dt
.GetWeekOfYear(wxDateTime
::Monday_First
),
513 wmon
= dt
.GetWeekOfMonth(wxDateTime
::Monday_First
),
514 wmon2
= dt
.GetWeekOfMonth(wxDateTime
::Sunday_First
),
515 dnum
= dt
.GetDayOfYear();
517 CPPUNIT_ASSERT( dnum
== wn
.dnum
);
518 CPPUNIT_ASSERT( wmon
== wn
.wmon
);
519 CPPUNIT_ASSERT( wmon2
== wn
.wmon2
);
520 CPPUNIT_ASSERT( week
== wn
.week
);
523 if ( week
== 1 && d
.month
!= wxDateTime
::Jan
)
525 // this means we're in the first week of the next year
530 dt2
= wxDateTime
::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
531 CPPUNIT_ASSERT( dt2
== dt
);
535 // test DST applicability
536 void DateTimeTestCase
::TestTimeDST()
538 // taken from http://www.energy.ca.gov/daylightsaving.html
539 static const Date datesDST
[2][2009 - 1990 + 1] =
542 { 1, wxDateTime
::Apr
, 1990, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
543 { 7, wxDateTime
::Apr
, 1991, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
544 { 5, wxDateTime
::Apr
, 1992, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
545 { 4, wxDateTime
::Apr
, 1993, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
546 { 3, wxDateTime
::Apr
, 1994, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
547 { 2, wxDateTime
::Apr
, 1995, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
548 { 7, wxDateTime
::Apr
, 1996, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
549 { 6, wxDateTime
::Apr
, 1997, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
550 { 5, wxDateTime
::Apr
, 1998, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
551 { 4, wxDateTime
::Apr
, 1999, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
552 { 2, wxDateTime
::Apr
, 2000, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
553 { 1, wxDateTime
::Apr
, 2001, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
554 { 7, wxDateTime
::Apr
, 2002, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
555 { 6, wxDateTime
::Apr
, 2003, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
556 { 4, wxDateTime
::Apr
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
557 { 3, wxDateTime
::Apr
, 2005, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
558 { 2, wxDateTime
::Apr
, 2006, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
559 {11, wxDateTime
::Mar
, 2007, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
560 { 9, wxDateTime
::Mar
, 2008, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
561 { 8, wxDateTime
::Mar
, 2009, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
564 { 28, wxDateTime
::Oct
, 1990, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
565 { 27, wxDateTime
::Oct
, 1991, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
566 { 25, wxDateTime
::Oct
, 1992, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
567 { 31, wxDateTime
::Oct
, 1993, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
568 { 30, wxDateTime
::Oct
, 1994, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
569 { 29, wxDateTime
::Oct
, 1995, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
570 { 27, wxDateTime
::Oct
, 1996, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
571 { 26, wxDateTime
::Oct
, 1997, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
572 { 25, wxDateTime
::Oct
, 1998, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
573 { 31, wxDateTime
::Oct
, 1999, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
574 { 29, wxDateTime
::Oct
, 2000, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
575 { 28, wxDateTime
::Oct
, 2001, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
576 { 27, wxDateTime
::Oct
, 2002, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
577 { 26, wxDateTime
::Oct
, 2003, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
578 { 31, wxDateTime
::Oct
, 2004, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
579 { 30, wxDateTime
::Oct
, 2005, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
580 { 29, wxDateTime
::Oct
, 2006, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
581 { 4, wxDateTime
::Nov
, 2007, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
582 { 2, wxDateTime
::Nov
, 2008, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
583 { 1, wxDateTime
::Nov
, 2009, 0, 0, 0, 0.0, wxDateTime
::Inv_WeekDay
, 0 },
588 for ( size_t n
= 0; n
< WXSIZEOF(datesDST
[0]); n
++ )
590 const int year
= 1990 + n
;
591 wxDateTime dtBegin
= wxDateTime
::GetBeginDST(year
, wxDateTime
::USA
),
592 dtEnd
= wxDateTime
::GetEndDST(year
, wxDateTime
::USA
);
594 const Date
& dBegin
= datesDST
[0][n
];
595 const Date
& dEnd
= datesDST
[1][n
];
597 CPPUNIT_ASSERT_EQUAL( dBegin
.DT().FormatDate(), dtBegin
.FormatDate() );
598 CPPUNIT_ASSERT_EQUAL( dEnd
.DT().FormatDate(), dtEnd
.FormatDate() );
602 // test wxDateTime -> text conversion
603 void DateTimeTestCase
::TestTimeFormat()
605 // some information may be lost during conversion, so store what kind
606 // of info should we recover after a round trip
609 CompareNone
, // don't try comparing
610 CompareBoth
, // dates and times should be identical
611 CompareYear
, // don't compare centuries (fails for 2 digit years)
612 CompareDate
, // dates only
613 CompareTime
// time only
618 CompareKind compareKind
;
620 } formatTestFormats
[] =
622 { CompareYear
, "---> %c" }, // %c could use 2 digit years
623 { CompareDate
, "Date is %A, %d of %B, in year %Y" },
624 { CompareYear
, "Date is %x, time is %X" }, // %x could use 2 digits
625 { CompareTime
, "Time is %H:%M:%S or %I:%M:%S %p" },
626 { CompareNone
, "The day of year: %j, the week of year: %W" },
627 { CompareDate
, "ISO date without separators: %Y%m%d" },
630 static const Date formatTestDates
[] =
632 { 29, wxDateTime
::May
, 1976, 18, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
633 { 31, wxDateTime
::Dec
, 1999, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
634 { 6, wxDateTime
::Feb
, 1937, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
635 { 6, wxDateTime
::Feb
, 1856, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
636 { 6, wxDateTime
::Feb
, 1857, 23, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
637 { 29, wxDateTime
::May
, 2076, 18, 30, 00, 0.0, wxDateTime
::Inv_WeekDay
},
638 { 29, wxDateTime
::Feb
, 2400, 02, 15, 25, 0.0, wxDateTime
::Inv_WeekDay
},
640 // Need to add support for BCE dates.
641 { 01, wxDateTime
::Jan
, -52, 03, 16, 47, 0.0, wxDateTime
::Inv_WeekDay
},
645 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
); d
++ )
647 wxDateTime dt
= formatTestDates
[d
].DT();
648 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
650 const char *fmt
= formatTestFormats
[n
].format
;
652 // skip the check with %p for those locales which have empty AM/PM strings:
653 // for those locales it's impossible to pass the test with %p...
655 wxDateTime
::GetAmPmStrings(&am
, &pm
);
656 if (am
.empty() && pm
.empty() && wxStrstr(fmt
, "%p") != NULL
)
659 wxString s
= dt
.Format(fmt
);
661 // what can we recover?
662 CompareKind kind
= formatTestFormats
[n
].compareKind
;
666 const char *result
= dt2
.ParseFormat(s
, fmt
);
669 // conversion failed - should it have?
670 CPPUNIT_ASSERT( kind
== CompareNone
);
672 else // conversion succeeded
674 // ParseFormat() should have parsed the entire string or left
675 // some final useless strings (e.g. with Italian locale the
676 // 's' string for the first test date looks like
677 // "---> sab 29 mag 1976 18:30:00 CET"
678 // so we just need to ignore CET)
679 CPPUNIT_ASSERT( !*result
|| strcmp(result
, "CET") == 0 );
684 if ( dt2
.GetCentury() != dt
.GetCentury() )
686 CPPUNIT_ASSERT_EQUAL(dt
.GetYear() % 100,
687 dt2
.GetYear() % 100);
689 dt2
.SetYear(dt
.GetYear());
691 // fall through and compare everything
694 CPPUNIT_ASSERT_EQUAL( dt
, dt2
);
698 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
702 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
706 wxFAIL_MSG( _T("unexpected") );
715 // test partially specified dates too
716 wxDateTime
dtDef(26, wxDateTime
::Sep
, 2008);
717 CPPUNIT_ASSERT( dt
.ParseFormat("17", "%d") );
718 CPPUNIT_ASSERT_EQUAL( 17, dt
.GetDay() );
720 // test compilation of some calls which should compile (and not result in
721 // ambiguity because of char*<->wxCStrData<->wxString conversions)
723 CPPUNIT_ASSERT( !dt
.ParseFormat("foo") );
724 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo")) );
725 CPPUNIT_ASSERT( !dt
.ParseFormat(s
) );
726 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str()) );
728 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", "%c") );
729 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), "%c") );
730 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
731 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), "%c") );
733 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", wxT("%c")) );
734 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), wxT("%c")) );
735 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, "%c") );
736 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), wxT("%c")) );
739 CPPUNIT_ASSERT( !dt
.ParseFormat("foo", spec
) );
740 CPPUNIT_ASSERT( !dt
.ParseFormat(wxT("foo"), spec
) );
741 CPPUNIT_ASSERT( !dt
.ParseFormat(s
, spec
) );
742 CPPUNIT_ASSERT( !dt
.ParseFormat(s
.c_str(), spec
) );
745 void DateTimeTestCase
::TestTimeSpanFormat()
747 static const struct TimeSpanFormatTestData
749 long h
, min
, sec
, msec
;
754 { 12, 34, 56, 789, "%H:%M:%S.%l", "12:34:56.789" },
755 { 1, 2, 3, 0, "%H:%M:%S", "01:02:03" },
756 { 1, 2, 3, 0, "%S", "3723" },
757 { -1, -2, -3, 0, "%S", "-3723" },
758 { -1, -2, -3, 0, "%H:%M:%S", "-01:02:03" },
759 { 26, 0, 0, 0, "%H", "26" },
760 { 26, 0, 0, 0, "%D, %H", "1, 02" },
761 { -26, 0, 0, 0, "%H", "-26" },
762 { -26, 0, 0, 0, "%D, %H", "-1, 02" },
763 { 219, 0, 0, 0, "%H", "219" },
764 { 219, 0, 0, 0, "%D, %H", "9, 03" },
765 { 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
766 { 0, -1, 0, 0, "%H:%M:%S", "-00:01:00" },
767 { 0, 0, -1, 0, "%H:%M:%S", "-00:00:01" },
770 for ( size_t n
= 0; n
< WXSIZEOF(testSpans
); n
++ )
772 const TimeSpanFormatTestData
& td
= testSpans
[n
];
773 wxTimeSpan
ts(td
.h
, td
.min
, td
.sec
, td
.msec
);
774 CPPUNIT_ASSERT_EQUAL( td
.result
, ts
.Format(td
.fmt
) );
778 void DateTimeTestCase
::TestTimeTicks()
780 static const wxDateTime
::TimeZone
TZ_LOCAL(wxDateTime
::Local
);
781 static const wxDateTime
::TimeZone
TZ_TEST(wxDateTime
::NZST
);
783 // this offset is needed to make the test work in any time zone when we
784 // only have expected test results in UTC in testDates
785 static const long tzOffset
= TZ_LOCAL
.GetOffset() - TZ_TEST
.GetOffset();
787 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
789 const Date
& d
= testDates
[n
];
790 if ( d
.gmticks
== -1 )
793 wxDateTime dt
= d
.DT().MakeTimezone(TZ_TEST
, true /* no DST */);
795 // GetValue() returns internal UTC-based representation, we need to
796 // convert it to local TZ before comparing
797 time_t ticks
= (dt
.GetValue() / 1000).ToLong() + TZ_LOCAL
.GetOffset();
800 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
+ tzOffset
);
802 dt
= d
.DT().FromTimezone(wxDateTime
::UTC
);
803 ticks
= (dt
.GetValue() / 1000).ToLong();
804 CPPUNIT_ASSERT_EQUAL( d
.gmticks
, ticks
);
808 // test parsing dates in RFC822 format
809 void DateTimeTestCase
::TestParceRFC822()
811 static const struct ParseTestData
814 Date date
; // NB: this should be in UTC
819 "Sat, 18 Dec 1999 00:46:40 +0100",
820 { 17, wxDateTime
::Dec
, 1999, 23, 46, 40 },
824 "Wed, 1 Dec 1999 05:17:20 +0300",
825 { 1, wxDateTime
::Dec
, 1999, 2, 17, 20 },
829 "Sun, 28 Aug 2005 03:31:30 +0200",
830 { 28, wxDateTime
::Aug
, 2005, 1, 31, 30 },
835 "Sat, 18 Dec 1999 10:48:30 -0500",
836 { 18, wxDateTime
::Dec
, 1999, 15, 48, 30 },
840 // seconds are optional according to the RFC
842 "Sun, 01 Jun 2008 16:30 +0200",
843 { 1, wxDateTime
::Jun
, 2008, 14, 30, 00 },
847 // try some bogus ones too
849 "Sun, 01 Jun 2008 16:30: +0200",
855 for ( unsigned n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
857 const char * const datestr
= parseTestDates
[n
].rfc822
;
860 if ( dt
.ParseRfc822Date(datestr
) )
863 ("Erroneously parsed \"%s\"", datestr
),
864 parseTestDates
[n
].good
867 wxDateTime dtReal
= parseTestDates
[n
].date
.DT().FromUTC();
868 CPPUNIT_ASSERT_EQUAL( dtReal
, dt
);
870 else // failed to parse
873 ("Failed to parse \"%s\"", datestr
),
874 !parseTestDates
[n
].good
880 // test parsing dates in free format
881 void DateTimeTestCase
::TestDateParse()
883 static const struct ParseTestData
886 Date date
; // NB: this should be in UTC
890 { "21 Mar 2006", { 21, wxDateTime
::Mar
, 2006 }, true },
891 { "29 Feb 1976", { 29, wxDateTime
::Feb
, 1976 }, true },
892 { "Feb 29 1976", { 29, wxDateTime
::Feb
, 1976 }, true },
893 { "31/03/06", { 31, wxDateTime
::Mar
, 6 }, true },
894 { "31/03/2006", { 31, wxDateTime
::Mar
, 2006 }, true },
896 // some invalid ones too
904 CPPUNIT_ASSERT( dt
.ParseDate(_T("today")) );
905 CPPUNIT_ASSERT_EQUAL( wxDateTime
::Today(), dt
);
907 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
909 if ( dt
.ParseDate(parseTestDates
[n
].str
) )
911 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
913 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
915 else // failed to parse
917 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
922 void DateTimeTestCase
::TestDateParseISO()
927 Date date
; // NB: this should be in UTC
931 { "2006-03-21", { 21, wxDateTime
::Mar
, 2006 }, true },
932 { "1976-02-29", { 29, wxDateTime
::Feb
, 1976 }, true },
933 { "0006-03-31", { 31, wxDateTime
::Mar
, 6 }, true },
935 // some invalid ones too
945 wxDateTime
::wxDateTime_t hour
, min
, sec
;
949 { "13:42:17", 13, 42, 17, true },
950 { "02:17:01", 2, 17, 1, true },
952 // some invalid ones too
959 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
962 if ( dt
.ParseISODate(parseTestDates
[n
].str
) )
964 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
966 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
968 for ( size_t m
= 0; m
< WXSIZEOF(parseTestTimes
); m
++ )
971 dtCombined
<< parseTestDates
[n
].str
973 << parseTestTimes
[m
].str
;
975 if ( dt
.ParseISOCombined(dtCombined
) )
977 CPPUNIT_ASSERT( parseTestTimes
[m
].good
);
979 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].hour
, dt
.GetHour()) ;
980 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].min
, dt
.GetMinute()) ;
981 CPPUNIT_ASSERT_EQUAL( parseTestTimes
[m
].sec
, dt
.GetSecond()) ;
983 else // failed to parse combined date/time
985 CPPUNIT_ASSERT( !parseTestTimes
[m
].good
);
989 else // failed to parse
991 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
996 void DateTimeTestCase
::TestDateTimeParse()
998 static const struct ParseTestData
1001 Date date
; // NB: this should be in UTC
1003 } parseTestDates
[] =
1005 { "Thu 22 Nov 2007 07:40:00 PM",
1006 { 22, wxDateTime
::Nov
, 2007, 19, 40, 0}, true },
1011 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
1013 if ( dt
.ParseDateTime(parseTestDates
[n
].str
) )
1015 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
1017 CPPUNIT_ASSERT_EQUAL( parseTestDates
[n
].date
.DT(), dt
);
1019 else // failed to parse
1021 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
1026 void DateTimeTestCase
::TestTimeArithmetics()
1028 static const wxDateSpan testArithmData
[] =
1032 wxDateSpan
::Month(),
1036 // the test will *not* work with arbitrary date!
1037 wxDateTime
dt(2, wxDateTime
::Dec
, 1999),
1041 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
1043 const wxDateSpan
& span
= testArithmData
[n
];
1047 CPPUNIT_ASSERT( dt1
- span
== dt
);
1048 CPPUNIT_ASSERT( dt2
+ span
== dt
);
1049 CPPUNIT_ASSERT( dt2
+ 2*span
== dt1
);
1053 void DateTimeTestCase
::TestDSTBug()
1055 /////////////////////////
1057 wxDateTime dt
= wxDateTime
::GetEndDST(2004, wxDateTime
::France
);
1058 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1059 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1060 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1061 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1062 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1063 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1064 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1066 /////////////////////////
1069 CPPUNIT_ASSERT_EQUAL(5, (int)dt
.GetHour());
1071 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1072 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1073 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1074 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1075 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1076 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1077 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1080 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1082 /////////////////////////
1084 #ifdef CHANGE_SYSTEM_DATE
1086 DateChanger
change(2004, 10, 31, 5, 0, 0);
1087 dt
= wxDateTime
::Today();
1090 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1091 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1092 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1093 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetHour());
1094 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMinute());
1095 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1096 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1098 /////////////////////////
1099 // Test Set(hour, minute, second, milli)
1102 DateChanger
change(2004, 10, 31, 5, 0, 0);
1103 dt
.Set(1, 30, 0, 0);
1104 dt2
.Set(5, 30, 0, 0);
1107 CPPUNIT_ASSERT_EQUAL(31, (int)dt
.GetDay());
1108 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt
.GetMonth());
1109 CPPUNIT_ASSERT_EQUAL(2004, (int)dt
.GetYear());
1110 CPPUNIT_ASSERT_EQUAL(1, (int)dt
.GetHour());
1111 CPPUNIT_ASSERT_EQUAL(30, (int)dt
.GetMinute());
1112 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetSecond());
1113 CPPUNIT_ASSERT_EQUAL(0, (int)dt
.GetMillisecond());
1115 CPPUNIT_ASSERT_EQUAL(31, (int)dt2
.GetDay());
1116 CPPUNIT_ASSERT_EQUAL(wxDateTime
::Oct
, dt2
.GetMonth());
1117 CPPUNIT_ASSERT_EQUAL(2004, (int)dt2
.GetYear());
1118 CPPUNIT_ASSERT_EQUAL(5, (int)dt2
.GetHour());
1119 CPPUNIT_ASSERT_EQUAL(30, (int)dt2
.GetMinute());
1120 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetSecond());
1121 CPPUNIT_ASSERT_EQUAL(0, (int)dt2
.GetMillisecond());
1122 #endif // CHANGE_SYSTEM_DATE
1125 void DateTimeTestCase
::TestDateOnly()
1127 wxDateTime
dt(19, wxDateTime
::Jan
, 2007, 15, 01, 00);
1129 static const wxDateTime
::wxDateTime_t DATE_ZERO
= 0;
1130 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetHour() );
1131 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMinute() );
1132 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetSecond() );
1133 CPPUNIT_ASSERT_EQUAL( DATE_ZERO
, dt
.GetDateOnly().GetMillisecond() );
1136 CPPUNIT_ASSERT_EQUAL( wxDateTime(19, wxDateTime
::Jan
, 2007), dt
);
1138 CPPUNIT_ASSERT_EQUAL( wxDateTime
::Today(), wxDateTime
::Now().GetDateOnly() );
1141 #endif // wxUSE_DATETIME