1 /*******************************************************
2 * Unit test for the date class
4 * test the date parser that converts String to date
5 ******************************************************
18 the_date = "20120208";
20 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
21 assert(d0 == date(8, 2, 2012));
23 the_date = "2012-02-08";
25 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
26 assert(d0 == date(8, 2, 2012));
28 the_date = "2012 02 08";
30 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
31 assert(d0 == date(8, 2, 2012));
33 the_date = "08-02-2012";
35 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
36 assert(d0 == date(8, 2, 2012));
38 the_date = "02/08/2012";
40 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
41 assert(d0 == date(8, 2, 2012));
43 the_date = "Feb 8 2012";
45 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
46 assert(d0 == date(8, 2, 2012));
48 the_date = "2012 Feb 8";
50 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
51 assert(d0 == date(8, 2, 2012));
53 the_date = "8 FEB 2012";
55 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
56 assert(d0 == date(8, 2, 2012));
58 the_date = "2012 8 feb";
60 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
61 assert(d0 == date(8, 2, 2012));
63 the_date = "8 February 2012";
65 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
66 assert(d0 == date(8, 2, 2012));
68 the_date = "Sun Jun 16 13:02:56 CEST 2019"; // A UNIX date string
70 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
71 assert(d0 == date(16, 6, 2019));
73 // Without a year: year = -1
74 the_date = "8 February";
76 std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
77 assert(d0 == date(8, 2, -1));
79 // TODO: test for invalid dates and syntax errors