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 // ----------------------------------------------------------------------------
23 #include "wx/datetime.h"
25 // ----------------------------------------------------------------------------
26 // broken down date representation used for testing
27 // ----------------------------------------------------------------------------
31 wxDateTime::wxDateTime_t day
;
32 wxDateTime::Month month
;
34 wxDateTime::wxDateTime_t hour
, min
, sec
;
36 wxDateTime::WeekDay wday
;
37 time_t gmticks
, ticks
;
39 void Init(const wxDateTime::Tm
& tm
)
52 { return wxDateTime(day
, month
, year
, hour
, min
, sec
); }
54 bool SameDay(const wxDateTime::Tm
& tm
) const
56 return day
== tm
.mday
&& month
== tm
.mon
&& year
== tm
.year
;
59 wxString
Format() const
62 s
.Printf(_T("%02d:%02d:%02d %10s %02d, %4d%s"),
64 wxDateTime::GetMonthName(month
).c_str(),
66 abs(wxDateTime::ConvertYearToBC(year
)),
67 year
> 0 ? _T("AD") : _T("BC"));
71 wxString
FormatDate() const
74 s
.Printf(_T("%02d-%s-%4d%s"),
76 wxDateTime::GetMonthName(month
, wxDateTime::Name_Abbr
).c_str(),
77 abs(wxDateTime::ConvertYearToBC(year
)),
78 year
> 0 ? _T("AD") : _T("BC"));
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 static const Date testDates
[] =
89 { 1, wxDateTime::Jan
, 1970, 00, 00, 00, 2440587.5, wxDateTime::Thu
, 0, -3600 },
90 { 7, wxDateTime::Feb
, 2036, 00, 00, 00, 2464730.5, wxDateTime::Thu
, -1, -1 },
91 { 8, wxDateTime::Feb
, 2036, 00, 00, 00, 2464731.5, wxDateTime::Fri
, -1, -1 },
92 { 1, wxDateTime::Jan
, 2037, 00, 00, 00, 2465059.5, wxDateTime::Thu
, -1, -1 },
93 { 1, wxDateTime::Jan
, 2038, 00, 00, 00, 2465424.5, wxDateTime::Fri
, -1, -1 },
94 { 21, wxDateTime::Jan
, 2222, 00, 00, 00, 2532648.5, wxDateTime::Mon
, -1, -1 },
95 { 29, wxDateTime::May
, 1976, 12, 00, 00, 2442928.0, wxDateTime::Sat
, 202219200, 202212000 },
96 { 29, wxDateTime::Feb
, 1976, 00, 00, 00, 2442837.5, wxDateTime::Sun
, 194400000, 194396400 },
97 { 1, wxDateTime::Jan
, 1900, 12, 00, 00, 2415021.0, wxDateTime::Mon
, -1, -1 },
98 { 1, wxDateTime::Jan
, 1900, 00, 00, 00, 2415020.5, wxDateTime::Mon
, -1, -1 },
99 { 15, wxDateTime::Oct
, 1582, 00, 00, 00, 2299160.5, wxDateTime::Fri
, -1, -1 },
100 { 4, wxDateTime::Oct
, 1582, 00, 00, 00, 2299149.5, wxDateTime::Mon
, -1, -1 },
101 { 1, wxDateTime::Mar
, 1, 00, 00, 00, 1721484.5, wxDateTime::Thu
, -1, -1 },
102 { 1, wxDateTime::Jan
, 1, 00, 00, 00, 1721425.5, wxDateTime::Mon
, -1, -1 },
103 { 31, wxDateTime::Dec
, 0, 00, 00, 00, 1721424.5, wxDateTime::Sun
, -1, -1 },
104 { 1, wxDateTime::Jan
, 0, 00, 00, 00, 1721059.5, wxDateTime::Sat
, -1, -1 },
105 { 12, wxDateTime::Aug
, -1234, 00, 00, 00, 1270573.5, wxDateTime::Fri
, -1, -1 },
106 { 12, wxDateTime::Aug
, -4000, 00, 00, 00, 260313.5, wxDateTime::Sat
, -1, -1 },
107 { 24, wxDateTime::Nov
, -4713, 00, 00, 00, -0.5, wxDateTime::Mon
, -1, -1 },
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 class DateTimeTestCase
: public CppUnit::TestCase
118 DateTimeTestCase() { }
121 CPPUNIT_TEST_SUITE( DateTimeTestCase
);
122 CPPUNIT_TEST( TestLeapYears
);
123 CPPUNIT_TEST( TestTimeSet
);
124 CPPUNIT_TEST( TestTimeJDN
);
125 CPPUNIT_TEST( TestTimeWNumber
);
126 CPPUNIT_TEST( TestTimeWDays
);
127 CPPUNIT_TEST( TestTimeDST
);
128 CPPUNIT_TEST( TestTimeFormat
);
129 CPPUNIT_TEST( TestTimeTicks
);
130 CPPUNIT_TEST( TestTimeParse
);
131 CPPUNIT_TEST( TestTimeArithmetics
);
132 CPPUNIT_TEST_SUITE_END();
134 void TestLeapYears();
137 void TestTimeWNumber();
138 void TestTimeWDays();
140 void TestTimeFormat();
141 void TestTimeTicks();
142 void TestTimeParse();
143 void TestTimeArithmetics();
145 DECLARE_NO_COPY_CLASS(DateTimeTestCase
)
148 // register in the unnamed registry so that these tests are run by default
149 CPPUNIT_TEST_SUITE_REGISTRATION( DateTimeTestCase
);
151 // also include in it's own registry so that these tests can be run alone
152 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DateTimeTestCase
, "DateTimeTestCase" );
154 // ============================================================================
156 // ============================================================================
158 // test leap years detection
159 void DateTimeTestCase::TestLeapYears()
161 static const struct LeapYearTestData
177 for ( size_t n
= 0; n
< WXSIZEOF(years
); n
++ )
179 const LeapYearTestData
& y
= years
[n
];
181 CPPUNIT_ASSERT( wxDateTime::IsLeapYear(y
.year
) == y
.isLeap
);
185 // test constructing wxDateTime objects
186 void DateTimeTestCase::TestTimeSet()
188 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
190 const Date
& d1
= testDates
[n
];
191 wxDateTime dt
= d1
.DT();
196 wxString s1
= d1
.Format(),
199 CPPUNIT_ASSERT( s1
== s2
);
203 // test conversions to JDN &c
204 void DateTimeTestCase::TestTimeJDN()
206 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
208 const Date
& d
= testDates
[n
];
209 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
210 double jdn
= dt
.GetJulianDayNumber();
212 CPPUNIT_ASSERT( jdn
== d
.jdn
);
215 CPPUNIT_ASSERT( dt
.GetJulianDayNumber() == jdn
);
219 // test week days computation
220 void DateTimeTestCase::TestTimeWDays()
224 for ( n
= 0; n
< WXSIZEOF(testDates
); n
++ )
226 const Date
& d
= testDates
[n
];
227 wxDateTime
dt(d
.day
, d
.month
, d
.year
, d
.hour
, d
.min
, d
.sec
);
229 wxDateTime::WeekDay wday
= dt
.GetWeekDay();
230 CPPUNIT_ASSERT( wday
== d
.wday
);
233 // test SetToWeekDay()
234 struct WeekDateTestData
236 Date date
; // the real date (precomputed)
237 int nWeek
; // its week index in the month
238 wxDateTime::WeekDay wday
; // the weekday
239 wxDateTime::Month month
; // the month
240 int year
; // and the year
242 wxString
Format() const
245 switch ( nWeek
< -1 ? -nWeek
: nWeek
)
247 case 1: which
= _T("first"); break;
248 case 2: which
= _T("second"); break;
249 case 3: which
= _T("third"); break;
250 case 4: which
= _T("fourth"); break;
251 case 5: which
= _T("fifth"); break;
253 case -1: which
= _T("last"); break;
258 which
+= _T(" from end");
261 s
.Printf(_T("The %s %s of %s in %d"),
263 wxDateTime::GetWeekDayName(wday
).c_str(),
264 wxDateTime::GetMonthName(month
).c_str(),
271 // the array data was generated by the following python program
273 from DateTime import *
274 from whrandom import *
277 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
278 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
280 week = DateTimeDelta(7)
283 year = randint(1900, 2100)
284 month = randint(1, 12)
286 dt = DateTime(year, month, day)
287 wday = dt.day_of_week
289 countFromEnd = choice([-1, 1])
292 while dt.month is month:
293 dt = dt - countFromEnd * week
294 weekNum = weekNum + countFromEnd
296 data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
298 print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
299 "wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
302 static const WeekDateTestData weekDatesTestData
[] =
304 { { 20, wxDateTime::Mar
, 2045 }, 3, wxDateTime::Mon
, wxDateTime::Mar
, 2045 },
305 { { 5, wxDateTime::Jun
, 1985 }, -4, wxDateTime::Wed
, wxDateTime::Jun
, 1985 },
306 { { 12, wxDateTime::Nov
, 1961 }, -3, wxDateTime::Sun
, wxDateTime::Nov
, 1961 },
307 { { 27, wxDateTime::Feb
, 2093 }, -1, wxDateTime::Fri
, wxDateTime::Feb
, 2093 },
308 { { 4, wxDateTime::Jul
, 2070 }, -4, wxDateTime::Fri
, wxDateTime::Jul
, 2070 },
309 { { 2, wxDateTime::Apr
, 1906 }, -5, wxDateTime::Mon
, wxDateTime::Apr
, 1906 },
310 { { 19, wxDateTime::Jul
, 2023 }, -2, wxDateTime::Wed
, wxDateTime::Jul
, 2023 },
311 { { 5, wxDateTime::May
, 1958 }, -4, wxDateTime::Mon
, wxDateTime::May
, 1958 },
312 { { 11, wxDateTime::Aug
, 1900 }, 2, wxDateTime::Sat
, wxDateTime::Aug
, 1900 },
313 { { 14, wxDateTime::Feb
, 1945 }, 2, wxDateTime::Wed
, wxDateTime::Feb
, 1945 },
314 { { 25, wxDateTime::Jul
, 1967 }, -1, wxDateTime::Tue
, wxDateTime::Jul
, 1967 },
315 { { 9, wxDateTime::May
, 1916 }, -4, wxDateTime::Tue
, wxDateTime::May
, 1916 },
316 { { 20, wxDateTime::Jun
, 1927 }, 3, wxDateTime::Mon
, wxDateTime::Jun
, 1927 },
317 { { 2, wxDateTime::Aug
, 2000 }, 1, wxDateTime::Wed
, wxDateTime::Aug
, 2000 },
318 { { 20, wxDateTime::Apr
, 2044 }, 3, wxDateTime::Wed
, wxDateTime::Apr
, 2044 },
319 { { 20, wxDateTime::Feb
, 1932 }, -2, wxDateTime::Sat
, wxDateTime::Feb
, 1932 },
320 { { 25, wxDateTime::Jul
, 2069 }, 4, wxDateTime::Thu
, wxDateTime::Jul
, 2069 },
321 { { 3, wxDateTime::Apr
, 1925 }, 1, wxDateTime::Fri
, wxDateTime::Apr
, 1925 },
322 { { 21, wxDateTime::Mar
, 2093 }, 3, wxDateTime::Sat
, wxDateTime::Mar
, 2093 },
323 { { 3, wxDateTime::Dec
, 2074 }, -5, wxDateTime::Mon
, wxDateTime::Dec
, 2074 },
328 for ( n
= 0; n
< WXSIZEOF(weekDatesTestData
); n
++ )
330 const WeekDateTestData
& wd
= weekDatesTestData
[n
];
332 dt
.SetToWeekDay(wd
.wday
, wd
.nWeek
, wd
.month
, wd
.year
);
334 const Date
& d
= wd
.date
;
335 CPPUNIT_ASSERT( d
.SameDay(dt
.GetTm()) );
339 // test the computation of (ISO) week numbers
340 void DateTimeTestCase::TestTimeWNumber()
342 struct WeekNumberTestData
344 Date date
; // the date
345 wxDateTime::wxDateTime_t week
; // the week number in the year
346 wxDateTime::wxDateTime_t wmon
; // the week number in the month
347 wxDateTime::wxDateTime_t wmon2
; // same but week starts with Sun
348 wxDateTime::wxDateTime_t dnum
; // day number in the year
351 // data generated with the following python script:
353 from DateTime import *
354 from whrandom import *
357 monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
358 wdayNames = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]
360 def GetMonthWeek(dt):
361 weekNumMonth = dt.iso_week[1] - DateTime(dt.year, dt.month, 1).iso_week[1] + 1
363 weekNumMonth = weekNumMonth + 53
366 def GetLastSundayBefore(dt):
367 if dt.iso_week[2] == 7:
370 return dt - DateTimeDelta(dt.iso_week[2])
373 year = randint(1900, 2100)
374 month = randint(1, 12)
376 dt = DateTime(year, month, day)
377 dayNum = dt.day_of_year
378 weekNum = dt.iso_week[1]
379 weekNumMonth = GetMonthWeek(dt)
382 dtSunday = GetLastSundayBefore(dt)
384 while dtSunday >= GetLastSundayBefore(DateTime(dt.year, dt.month, 1)):
385 weekNumMonth2 = weekNumMonth2 + 1
386 dtSunday = dtSunday - DateTimeDelta(7)
388 data = { 'day': rjust(`day`, 2), \
389 'month': monthNames[month - 1], \
391 'weekNum': rjust(`weekNum`, 2), \
392 'weekNumMonth': weekNumMonth, \
393 'weekNumMonth2': weekNumMonth2, \
394 'dayNum': rjust(`dayNum`, 3) }
396 print " { { %(day)s, "\
397 "wxDateTime::%(month)s, "\
400 "%(weekNumMonth)s, "\
401 "%(weekNumMonth2)s, "\
402 "%(dayNum)s }," % data
405 static const WeekNumberTestData weekNumberTestDates
[] =
407 { { 27, wxDateTime::Dec
, 1966 }, 52, 5, 5, 361 },
408 { { 22, wxDateTime::Jul
, 1926 }, 29, 4, 4, 203 },
409 { { 22, wxDateTime::Oct
, 2076 }, 43, 4, 4, 296 },
410 { { 1, wxDateTime::Jul
, 1967 }, 26, 1, 1, 182 },
411 { { 8, wxDateTime::Nov
, 2004 }, 46, 2, 2, 313 },
412 { { 21, wxDateTime::Mar
, 1920 }, 12, 3, 4, 81 },
413 { { 7, wxDateTime::Jan
, 1965 }, 1, 2, 2, 7 },
414 { { 19, wxDateTime::Oct
, 1999 }, 42, 4, 4, 292 },
415 { { 13, wxDateTime::Aug
, 1955 }, 32, 2, 2, 225 },
416 { { 18, wxDateTime::Jul
, 2087 }, 29, 3, 3, 199 },
417 { { 2, wxDateTime::Sep
, 2028 }, 35, 1, 1, 246 },
418 { { 28, wxDateTime::Jul
, 1945 }, 30, 5, 4, 209 },
419 { { 15, wxDateTime::Jun
, 1901 }, 24, 3, 3, 166 },
420 { { 10, wxDateTime::Oct
, 1939 }, 41, 3, 2, 283 },
421 { { 3, wxDateTime::Dec
, 1965 }, 48, 1, 1, 337 },
422 { { 23, wxDateTime::Feb
, 1940 }, 8, 4, 4, 54 },
423 { { 2, wxDateTime::Jan
, 1987 }, 1, 1, 1, 2 },
424 { { 11, wxDateTime::Aug
, 2079 }, 32, 2, 2, 223 },
425 { { 2, wxDateTime::Feb
, 2063 }, 5, 1, 1, 33 },
426 { { 16, wxDateTime::Oct
, 1942 }, 42, 3, 3, 289 },
427 { { 30, wxDateTime::Dec
, 2003 }, 1, 5, 5, 364 },
428 { { 2, wxDateTime::Jan
, 2004 }, 1, 1, 1, 2 },
431 for ( size_t n
= 0; n
< WXSIZEOF(weekNumberTestDates
); n
++ )
433 const WeekNumberTestData
& wn
= weekNumberTestDates
[n
];
434 const Date
& d
= wn
.date
;
436 wxDateTime dt
= d
.DT();
438 wxDateTime::wxDateTime_t
439 week
= dt
.GetWeekOfYear(wxDateTime::Monday_First
),
440 wmon
= dt
.GetWeekOfMonth(wxDateTime::Monday_First
),
441 wmon2
= dt
.GetWeekOfMonth(wxDateTime::Sunday_First
),
442 dnum
= dt
.GetDayOfYear();
444 CPPUNIT_ASSERT( dnum
== wn
.dnum
);
445 CPPUNIT_ASSERT( wmon
== wn
.wmon
);
446 CPPUNIT_ASSERT( wmon2
== wn
.wmon2
);
447 CPPUNIT_ASSERT( week
== wn
.week
);
450 if ( week
== 1 && d
.month
!= wxDateTime::Jan
)
452 // this means we're in the first week of the next year
457 dt2
= wxDateTime::SetToWeekOfYear(year
, week
, dt
.GetWeekDay());
458 CPPUNIT_ASSERT( dt2
== dt
);
462 // test DST applicability
463 void DateTimeTestCase::TestTimeDST()
465 // taken from http://www.energy.ca.gov/daylightsaving.html
466 static const Date datesDST
[2][2004 - 1900 + 1] =
469 { 1, wxDateTime::Apr
, 1990 },
470 { 7, wxDateTime::Apr
, 1991 },
471 { 5, wxDateTime::Apr
, 1992 },
472 { 4, wxDateTime::Apr
, 1993 },
473 { 3, wxDateTime::Apr
, 1994 },
474 { 2, wxDateTime::Apr
, 1995 },
475 { 7, wxDateTime::Apr
, 1996 },
476 { 6, wxDateTime::Apr
, 1997 },
477 { 5, wxDateTime::Apr
, 1998 },
478 { 4, wxDateTime::Apr
, 1999 },
479 { 2, wxDateTime::Apr
, 2000 },
480 { 1, wxDateTime::Apr
, 2001 },
481 { 7, wxDateTime::Apr
, 2002 },
482 { 6, wxDateTime::Apr
, 2003 },
483 { 4, wxDateTime::Apr
, 2004 },
486 { 28, wxDateTime::Oct
, 1990 },
487 { 27, wxDateTime::Oct
, 1991 },
488 { 25, wxDateTime::Oct
, 1992 },
489 { 31, wxDateTime::Oct
, 1993 },
490 { 30, wxDateTime::Oct
, 1994 },
491 { 29, wxDateTime::Oct
, 1995 },
492 { 27, wxDateTime::Oct
, 1996 },
493 { 26, wxDateTime::Oct
, 1997 },
494 { 25, wxDateTime::Oct
, 1998 },
495 { 31, wxDateTime::Oct
, 1999 },
496 { 29, wxDateTime::Oct
, 2000 },
497 { 28, wxDateTime::Oct
, 2001 },
498 { 27, wxDateTime::Oct
, 2002 },
499 { 26, wxDateTime::Oct
, 2003 },
500 { 31, wxDateTime::Oct
, 2004 },
504 for ( int year
= 1990; year
< 2005; year
++ )
506 wxDateTime dtBegin
= wxDateTime::GetBeginDST(year
, wxDateTime::USA
),
507 dtEnd
= wxDateTime::GetEndDST(year
, wxDateTime::USA
);
509 size_t n
= year
- 1990;
510 const Date
& dBegin
= datesDST
[0][n
];
511 const Date
& dEnd
= datesDST
[1][n
];
513 CPPUNIT_ASSERT( dBegin
.SameDay(dtBegin
.GetTm()) );
514 CPPUNIT_ASSERT( dEnd
.SameDay(dtEnd
.GetTm()) );
518 // test wxDateTime -> text conversion
519 void DateTimeTestCase::TestTimeFormat()
521 // some information may be lost during conversion, so store what kind
522 // of info should we recover after a round trip
525 CompareNone
, // don't try comparing
526 CompareBoth
, // dates and times should be identical
527 CompareDate
, // dates only
528 CompareTime
// time only
533 CompareKind compareKind
;
534 const wxChar
*format
;
535 } formatTestFormats
[] =
537 { CompareBoth
, _T("---> %c") },
538 { CompareDate
, _T("Date is %A, %d of %B, in year %Y") },
539 { CompareBoth
, _T("Date is %x, time is %X") },
540 { CompareTime
, _T("Time is %H:%M:%S or %I:%M:%S %p") },
541 { CompareNone
, _T("The day of year: %j, the week of year: %W") },
542 { CompareDate
, _T("ISO date without separators: %Y%m%d") },
545 static const Date formatTestDates
[] =
547 { 29, wxDateTime::May
, 1976, 18, 30, 00 },
548 { 31, wxDateTime::Dec
, 1999, 23, 30, 00 },
550 // this test can't work for other centuries because it uses two digit
551 // years in formats, so don't even try it
552 { 29, wxDateTime::May
, 2076, 18, 30, 00 },
553 { 29, wxDateTime::Feb
, 2400, 02, 15, 25 },
554 { 01, wxDateTime::Jan
, -52, 03, 16, 47 },
558 for ( size_t d
= 0; d
< WXSIZEOF(formatTestDates
) + 1; d
++ )
560 wxDateTime dt
= d
== 0 ? wxDateTime::Now() : formatTestDates
[d
- 1].DT();
561 for ( size_t n
= 0; n
< WXSIZEOF(formatTestFormats
); n
++ )
563 wxString s
= dt
.Format(formatTestFormats
[n
].format
);
565 // what can we recover?
566 int kind
= formatTestFormats
[n
].compareKind
;
570 const wxChar
*result
= dt2
.ParseFormat(s
, formatTestFormats
[n
].format
);
573 // converion failed - should it have?
574 CPPUNIT_ASSERT( kind
== CompareNone
);
576 else // conversion succeeded
578 // should have parsed the entire string
579 CPPUNIT_ASSERT( !*result
);
584 CPPUNIT_ASSERT( dt2
== dt
);
588 CPPUNIT_ASSERT( dt
.IsSameDate(dt2
) );
592 CPPUNIT_ASSERT( dt
.IsSameTime(dt2
) );
600 void DateTimeTestCase::TestTimeTicks()
602 for ( size_t n
= 0; n
< WXSIZEOF(testDates
); n
++ )
604 const Date
& d
= testDates
[n
];
608 wxDateTime dt
= d
.DT();
609 //RN: Translate according to test's time zone
610 //2nd param is to ignore DST - it's already factored
612 dt
.MakeTimezone(wxDateTime::WEST
, true);
613 long ticks
= (dt
.GetValue() / 1000).ToLong();
614 CPPUNIT_ASSERT( ticks
== d
.ticks
);
616 dt
= d
.DT().ToTimezone(wxDateTime::GMT0
);
617 ticks
= (dt
.GetValue() / 1000).ToLong();
618 CPPUNIT_ASSERT( ticks
== d
.gmticks
);
622 // test text -> wxDateTime conversion
623 void DateTimeTestCase::TestTimeParse()
625 static const struct ParseTestData
627 const wxChar
*format
;
632 { _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec
, 1999, 00, 46, 40 }, true },
633 { _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec
, 1999, 03, 17, 20 }, true },
636 for ( size_t n
= 0; n
< WXSIZEOF(parseTestDates
); n
++ )
638 const wxChar
*format
= parseTestDates
[n
].format
;
641 if ( dt
.ParseRfc822Date(format
) )
643 CPPUNIT_ASSERT( parseTestDates
[n
].good
);
645 wxDateTime dtReal
= parseTestDates
[n
].date
.DT();
646 //RN: We need this because the tests are based on
647 //a non-GMT time zone
648 dtReal
.MakeTimezone(wxDateTime::WEST
, true);
649 CPPUNIT_ASSERT( dt
== dtReal
);
651 else // failed to parse
653 CPPUNIT_ASSERT( !parseTestDates
[n
].good
);
658 void DateTimeTestCase::TestTimeArithmetics()
660 static const wxDateSpan testArithmData
[] =
668 // the test will *not* work with arbitrary date!
669 wxDateTime
dt(2, wxDateTime::Dec
, 1999),
673 for ( size_t n
= 0; n
< WXSIZEOF(testArithmData
); n
++ )
675 const wxDateSpan
& span
= testArithmData
[n
];
679 CPPUNIT_ASSERT( dt1
- span
== dt
);
680 CPPUNIT_ASSERT( dt2
+ span
== dt
);
681 CPPUNIT_ASSERT( dt2
+ 2*span
== dt1
);