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 // ----------------------------------------------------------------------------
14 #include "wx/wxprec.h"
23 #include "wx/datetime.h"
25 #include "wx/cppunit.h"
27 // ----------------------------------------------------------------------------
28 // broken down date representation used for testing
29 // ----------------------------------------------------------------------------
33 wxDateTime::wxDateTime_t day
;
34 wxDateTime::Month month
;
36 wxDateTime::wxDateTime_t hour
, min
, sec
;
38 wxDateTime::WeekDay wday
;
39 time_t gmticks
, ticks
;
41 void Init(const wxDateTime::Tm
& tm
)
54 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
56 bool SameDay(const wxDateTime::Tm
& tm
) const
58 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
61 wxString
Format() const
64 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
66 wxDateTime::GetMonthName(month
).c_str(),
68 abs(wxDateTime::ConvertYearToBC(year
)),
69 year
> 0 ? _T("AD") : _T("BC"));
73 wxString
FormatDate() const
76 s
.Printf(_T("%02d-%s-%4d%s"),
78 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
79 abs(wxDateTime::ConvertYearToBC(year
)),
80 year
> 0 ? _T("AD") : _T("BC"));
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 static const Date testDates
[] =
91 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
92 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1, -1 },
93 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1, -1 },
94 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1, -1 },
95 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1, -1 },
96 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
97 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
98 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
99 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
100 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
101 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
102 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
103 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
104 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
105 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
106 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
107 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
108 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
109 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 class DateTimeTestCase
: public CppUnit::TestCase
120 DateTimeTestCase() { }
123 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
124 CPPUNIT_TEST( TestLeapYears
);
125 CPPUNIT_TEST( TestTimeSet
);
126 CPPUNIT_TEST( TestTimeJDN
);
127 CPPUNIT_TEST( TestTimeWNumber
);
128 CPPUNIT_TEST( TestTimeWDays
);
129 CPPUNIT_TEST( TestTimeDST
);
130 CPPUNIT_TEST( TestTimeFormat
);
131 CPPUNIT_TEST( TestTimeTicks
);
132 CPPUNIT_TEST( TestTimeParse
);
133 CPPUNIT_TEST( TestTimeArithmetics
);
134 CPPUNIT_TEST_SUITE_END();
136 void TestLeapYears();
139 void TestTimeWNumber();
140 void TestTimeWDays();
142 void TestTimeFormat();
143 void TestTimeTicks();
144 void TestTimeParse();
145 void TestTimeArithmetics();
147 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
150 // register in the unnamed registry so that these tests are run by default
151 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
153 // also include in it's own registry so that these tests can be run alone
154 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
156 // ============================================================================
158 // ============================================================================
160 // test leap years detection
161 void DateTimeTestCase::TestLeapYears()
163 static const struct LeapYearTestData
179 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
181 const LeapYearTestData
& y
= years
[n
];
183 CPPUNIT_ASSERT( wxDateTime::IsLeapYear(y
.year
) == y
.isLeap
);
187 // test constructing wxDateTime objects
188 void DateTimeTestCase::TestTimeSet()
190 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
192 const Date
& d1
= testDates
[n
];
193 wxDateTime dt
= d1
.DT();
198 wxString s1
= d1
.Format(),
201 CPPUNIT_ASSERT( s1
== s2
);
205 // test conversions to JDN &c
206 void DateTimeTestCase::TestTimeJDN()
208 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
210 const Date
& d
= testDates
[n
];
211 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
212 double jdn
= dt
.GetJulianDayNumber();
214 CPPUNIT_ASSERT( jdn
== d
.jdn
);
217 CPPUNIT_ASSERT( dt
.GetJulianDayNumber() == jdn
);
221 // test week days computation
222 void DateTimeTestCase::TestTimeWDays()
226 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
228 const Date
& d
= testDates
[n
];
229 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
231 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
232 CPPUNIT_ASSERT( wday
== d
.wday
);
235 // test SetToWeekDay()
236 struct WeekDateTestData
238 Date date
; // the real date (precomputed)
239 int nWeek
; // its week index in the month
240 wxDateTime::WeekDay wday
; // the weekday
241 wxDateTime::Month month
; // the month
242 int year
; // and the year
244 wxString
Format() const
247 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
249 case 1: which
= _T("first"); break;
250 case 2: which
= _T("second"); break;
251 case 3: which
= _T("third"); break;
252 case 4: which
= _T("fourth"); break;
253 case 5: which
= _T("fifth"); break;
255 case -1: which
= _T("last"); break;
260 which
+= _T(" from end");
263 s
.Printf(_T("The %s %s of %s in %d"),
265 wxDateTime::GetWeekDayName(wday
).c_str(),
266 wxDateTime::GetMonthName(month
).c_str(),
273 // the array data was generated by the following python program
275 from DateTime import *
276 from whrandom import *
279 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
280 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
282 week = DateTimeDelta(7)
285 year = randint(1900, 2100)
286 month = randint(1, 12)
288 dt = DateTime(year, month, day)
289 wday = dt.day_of_week
291 countFromEnd = choice([-1, 1])
294 while dt.month is month:
295 dt = dt - countFromEnd * week
296 weekNum = weekNum + countFromEnd
298 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
300 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
301 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
304 static const WeekDateTestData weekDatesTestData
[] =
306 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
307 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
308 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
309 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
310 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
311 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
312 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
313 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
314 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
315 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
316 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
317 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
318 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
319 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
320 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
321 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
322 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
323 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
324 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
325 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
330 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
332 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
334 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
336 const Date
& d
= wd
.date
;
337 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
341 // test the computation of (ISO) week numbers
342 void DateTimeTestCase::TestTimeWNumber()
344 struct WeekNumberTestData
346 Date date
; // the date
347 wxDateTime::wxDateTime_t week
; // the week number in the year
348 wxDateTime::wxDateTime_t wmon
; // the week number in the month
349 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
350 wxDateTime::wxDateTime_t dnum
; // day number in the year
353 // data generated with the following python script:
355 from DateTime import *
356 from whrandom import *
359 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
360 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
362 def GetMonthWeek(dt):
363 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
365 weekNumMonth = weekNumMonth + 53
368 def GetLastSundayBefore(dt):
369 if dt.iso_week[2] == 7:
372 return dt - DateTimeDelta(dt.iso_week[2])
375 year = randint(1900, 2100)
376 month = randint(1, 12)
378 dt = DateTime(year, month, day)
379 dayNum = dt.day_of_year
380 weekNum = dt.iso_week[1]
381 weekNumMonth = GetMonthWeek(dt)
384 dtSunday = GetLastSundayBefore(dt)
386 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
387 weekNumMonth2 = weekNumMonth2 + 1
388 dtSunday = dtSunday - DateTimeDelta(7)
390 data = { 'day': rjust(`day`, 2), \
391 'month': monthNames[month - 1], \
393 'weekNum': rjust(`weekNum`, 2), \
394 'weekNumMonth': weekNumMonth, \
395 'weekNumMonth2': weekNumMonth2, \
396 'dayNum': rjust(`dayNum`, 3) }
398 print " { { %(day)s, "\
399 "wxDateTime::%(month)s, "\
402 "%(weekNumMonth)s, "\
403 "%(weekNumMonth2)s, "\
404 "%(dayNum)s }," % data
407 static const WeekNumberTestData weekNumberTestDates
[] =
409 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
410 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
411 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
412 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
413 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
414 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
415 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
416 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
417 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
418 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
419 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
420 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
421 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
422 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
423 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
424 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
425 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
426 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
427 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
428 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
429 { { 30, wxDateTime::Dec
, 2003 }, 1, 5, 5, 364 },
430 { { 2, wxDateTime::Jan
, 2004 }, 1, 1, 1, 2 },
433 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
435 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
436 const Date
& d
= wn
.date
;
438 wxDateTime dt
= d
.DT();
440 wxDateTime::wxDateTime_t
441 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
442 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
443 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
444 dnum
= dt
.GetDayOfYear();
446 CPPUNIT_ASSERT( dnum
== wn
.dnum
);
447 CPPUNIT_ASSERT( wmon
== wn
.wmon
);
448 CPPUNIT_ASSERT( wmon2
== wn
.wmon2
);
449 CPPUNIT_ASSERT( week
== wn
.week
);
452 if ( week
== 1 && d
.month
!= wxDateTime::Jan
)
454 // this means we're in the first week of the next year
459 dt2
= wxDateTime::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
460 CPPUNIT_ASSERT( dt2
== dt
);
464 // test DST applicability
465 void DateTimeTestCase::TestTimeDST()
467 // taken from http://www.energy.ca.gov/daylightsaving.html
468 static const Date datesDST
[2][2004 - 1900 + 1] =
471 { 1, wxDateTime::Apr
, 1990 },
472 { 7, wxDateTime::Apr
, 1991 },
473 { 5, wxDateTime::Apr
, 1992 },
474 { 4, wxDateTime::Apr
, 1993 },
475 { 3, wxDateTime::Apr
, 1994 },
476 { 2, wxDateTime::Apr
, 1995 },
477 { 7, wxDateTime::Apr
, 1996 },
478 { 6, wxDateTime::Apr
, 1997 },
479 { 5, wxDateTime::Apr
, 1998 },
480 { 4, wxDateTime::Apr
, 1999 },
481 { 2, wxDateTime::Apr
, 2000 },
482 { 1, wxDateTime::Apr
, 2001 },
483 { 7, wxDateTime::Apr
, 2002 },
484 { 6, wxDateTime::Apr
, 2003 },
485 { 4, wxDateTime::Apr
, 2004 },
488 { 28, wxDateTime::Oct
, 1990 },
489 { 27, wxDateTime::Oct
, 1991 },
490 { 25, wxDateTime::Oct
, 1992 },
491 { 31, wxDateTime::Oct
, 1993 },
492 { 30, wxDateTime::Oct
, 1994 },
493 { 29, wxDateTime::Oct
, 1995 },
494 { 27, wxDateTime::Oct
, 1996 },
495 { 26, wxDateTime::Oct
, 1997 },
496 { 25, wxDateTime::Oct
, 1998 },
497 { 31, wxDateTime::Oct
, 1999 },
498 { 29, wxDateTime::Oct
, 2000 },
499 { 28, wxDateTime::Oct
, 2001 },
500 { 27, wxDateTime::Oct
, 2002 },
501 { 26, wxDateTime::Oct
, 2003 },
502 { 31, wxDateTime::Oct
, 2004 },
506 for ( int year
= 1990; year
< 2005; year
++ )
508 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
509 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
511 size_t n
= year
- 1990;
512 const Date
& dBegin
= datesDST
[0][n
];
513 const Date
& dEnd
= datesDST
[1][n
];
515 CPPUNIT_ASSERT( dBegin
.SameDay(dtBegin
.GetTm()) );
516 CPPUNIT_ASSERT( dEnd
.SameDay(dtEnd
.GetTm()) );
520 // test wxDateTime -> text conversion
521 void DateTimeTestCase::TestTimeFormat()
523 // some information may be lost during conversion, so store what kind
524 // of info should we recover after a round trip
527 CompareNone
, // don't try comparing
528 CompareBoth
, // dates and times should be identical
529 CompareDate
, // dates only
530 CompareTime
// time only
535 CompareKind compareKind
;
536 const wxChar
*format
;
537 } formatTestFormats
[] =
539 { CompareBoth
, _T("---> %c") },
540 { CompareDate
, _T("Date is %A, %d of %B, in year %Y") },
541 { CompareBoth
, _T("Date is %x, time is %X") },
542 { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") },
543 { CompareNone
, _T("The day of year: %j, the week of year: %W") },
544 { CompareDate
, _T("ISO date without separators: %Y%m%d") },
547 static const Date formatTestDates
[] =
549 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
550 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
552 // this test can't work for other centuries because it uses two digit
553 // years in formats, so don't even try it
554 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
555 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
556 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
560 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
562 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
563 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
565 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
567 // what can we recover?
568 int kind
= formatTestFormats
[n
].compareKind
;
572 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
575 // converion failed - should it have?
576 CPPUNIT_ASSERT( kind
== CompareNone
);
578 else // conversion succeeded
580 // should have parsed the entire string
581 CPPUNIT_ASSERT( !*result
);
586 CPPUNIT_ASSERT( dt2
== dt
);
590 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
594 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
602 void DateTimeTestCase::TestTimeTicks()
604 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
606 const Date
& d
= testDates
[n
];
610 wxDateTime dt
= d
.DT();
611 long ticks
= (dt
.GetValue() / 1000).ToLong();
612 CPPUNIT_ASSERT( ticks
== d
.ticks
);
614 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
615 ticks
= (dt
.GetValue() / 1000).ToLong();
616 CPPUNIT_ASSERT( ticks
== d
.gmticks
);
620 // test text -> wxDateTime conversion
621 void DateTimeTestCase::TestTimeParse()
623 static const struct ParseTestData
625 const wxChar
*format
;
630 { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true },
631 { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true },
634 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
636 const wxChar
*format
= parseTestDates
[n
].format
;
639 if ( dt
.ParseRfc822Date(format
) )
641 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
643 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
644 CPPUNIT_ASSERT( dt
== dtReal
);
646 else // failed to parse
648 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
653 void DateTimeTestCase::TestTimeArithmetics()
655 static const wxDateSpan testArithmData
[] =
663 // the test will *not* work with arbitrary date!
664 wxDateTime
dt(2, wxDateTime::Dec
, 1999),
668 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
670 const wxDateSpan
& span
= testArithmData
[n
];
674 CPPUNIT_ASSERT( dt1
- span
== dt
);
675 CPPUNIT_ASSERT( dt2
+ span
== dt
);
676 CPPUNIT_ASSERT( dt2
+ 2*span
== dt1
);