23d344bc01b29ff6300083cb75913d3e3fda14fc
[libacl.git] / test / date_parse.cpp
1 /*******************************************************
2  *  Unit test for the date class
3  *
4  * test the date parser that converts String to date
5  ******************************************************
6  *
7  */
8
9 #include "date.h"
10 #include <assert.h>
11
12 int main()
13 {
14    date   d0;
15    String the_date;
16
17
18    the_date = "20120208";
19    d0 = date(the_date);
20    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
21    assert(d0 == date(8, 2, 2012));
22
23    the_date = "2012-02-08";
24    d0 = date(the_date);
25    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
26    assert(d0 == date(8, 2, 2012));
27
28    the_date = "2012 02 08";
29    d0 = date(the_date);
30    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
31    assert(d0 == date(8, 2, 2012));
32
33    the_date = "08-02-2012";
34    d0 = date(the_date);
35    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
36    assert(d0 == date(8, 2, 2012));
37
38    the_date = "02/08/2012";
39    d0 = date(the_date);
40    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
41    assert(d0 == date(8, 2, 2012));
42
43    the_date = "Feb 8 2012";
44    d0 = date(the_date);
45    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
46    assert(d0 == date(8, 2, 2012));
47
48    the_date = "2012 Feb 8";
49    d0 = date(the_date);
50    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
51    assert(d0 == date(8, 2, 2012));
52
53    the_date = "8 FEB 2012";
54    d0 = date(the_date);
55    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
56    assert(d0 == date(8, 2, 2012));
57
58    the_date = "2012 8 feb";
59    d0 = date(the_date);
60    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
61    assert(d0 == date(8, 2, 2012));
62
63    the_date = "8 February 2012";
64    d0 = date(the_date);
65    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
66    assert(d0 == date(8, 2, 2012));
67
68    the_date = "Sun Jun 16 13:02:56 CEST 2019";   // A UNIX date string
69    d0 = date(the_date);
70    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
71    assert(d0 == date(16, 6, 2019));
72
73    //  Without a year: year = -1
74    the_date = "8 February";
75    d0 = date(the_date);
76    std::cout << "String \"" << the_date << "\" converts to: \"" << d0 << "\"\n";
77    assert(d0 == date(8, 2, -1));
78
79    //  TODO: test for invalid dates and syntax errors
80
81    return 0;
82 }
83