]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/test/gregorian/testgenerators.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / date_time / test / gregorian / testgenerators.cpp
1 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
2 * Use, modification and distribution is subject to the
3 * Boost Software License, Version 1.0. (See accompanying
4 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5 * Author: Jeff Garland, Bart Garst
6 */
7
8 #include "boost/date_time/gregorian/gregorian.hpp"
9 #include "../testfrmwk.hpp"
10 #include <iostream>
11 #include <string>
12 #include <sstream>
13
14 int
15 main()
16 {
17
18 using namespace boost::gregorian;
19
20 partial_date pd1(1,Jan);
21 date d = pd1.get_date(2000);
22 check("Partial date to_string()", pd1.to_string() == std::string("0"));
23 check("Partial date getdate", date(2000,1,1) == d);
24 d = pd1.get_date(2001);
25 check("Partial date getdate", date(2001,1,1) == d);
26 partial_date pd2(1,Feb);
27 check("Partial date to_string()", pd2.to_string() == std::string("31"));
28 check("Partial date operator==", pd1 == pd1);
29 check("Partial date operator==", !(pd1 == pd2));
30 check("Partial date operator==", !(pd2 == pd1));
31 check("Partial date operator<", !(pd1 < pd1));
32 check("Partial date operator<", pd1 < pd2);
33 check("Partial date operator<", !(pd2 < pd1));
34
35 typedef last_day_of_the_week_in_month lastkday;
36
37 //Find last Sunday in Feb
38 lastkday lsif(Sunday, Feb);
39 std::cout << to_simple_string(lsif.get_date(2002)) << std::endl; //24th
40 check("Last kday", date(2002,Feb,24) == lsif.get_date(2002));
41 check("Last kday to_string()", lsif.to_string() == std::string("M2.5.0"));
42 lastkday ltif(Thursday, Feb);
43 check("Last kday", date(2002,Feb,28) == ltif.get_date(2002));
44 check("Last kday to_string()", ltif.to_string() == std::string("M2.5.4"));
45 lastkday lfif(Friday, Feb);
46 check("Last kday", date(2002,Feb,22) == lfif.get_date(2002));
47 check("Last kday to_string()", lfif.to_string() == std::string("M2.5.5"));
48
49 typedef first_day_of_the_week_in_month firstkday;
50
51 firstkday fsif(Sunday, Feb);
52 std::cout << to_simple_string(fsif.get_date(2002)) << std::endl; //24th
53 check("First kday", date(2002,Feb,3) == fsif.get_date(2002));
54 check("First kday to_string()", fsif.to_string() == std::string("M2.1.0"));
55 firstkday ftif(Thursday, Feb);
56 check("First kday", date(2002,Feb,7) == ftif.get_date(2002));
57 check("First kday to_string()", ftif.to_string() == std::string("M2.1.4"));
58 firstkday ffif(Friday, Feb);
59 check("First kday", date(2002,Feb,1) == ffif.get_date(2002));
60 check("First kday to_string()", ffif.to_string() == std::string("M2.1.5"));
61
62 typedef first_day_of_the_week_after firstkdayafter;
63 firstkdayafter fkaf(Monday);
64 std::cout << to_simple_string(fkaf.get_date(date(2002,Feb,1)))
65 << std::endl; //feb 4
66 check("kday after",date(2002,Feb,4) == fkaf.get_date(date(2002,Feb,1)));
67 firstkdayafter fkaf2(Thursday);
68 check("kday after",date(2002,Feb,7) == fkaf2.get_date(date(2002,Feb,1)));
69 check("kday after",date(2002,Feb,28)== fkaf2.get_date(date(2002,Feb,21)));
70
71 typedef first_day_of_the_week_before firstkdaybefore;
72 firstkdaybefore fkbf(Monday);
73 std::cout << to_simple_string(fkaf.get_date(date(2002,Feb,10)))
74 << std::endl; //feb 4
75 check("kday before",date(2002,Feb,4) == fkbf.get_date(date(2002,Feb,10)));
76 firstkdaybefore fkbf2(Thursday);
77 check("kday before",date(2002,Jan,31) == fkbf2.get_date(date(2002,Feb,1)));
78 check("kday before",date(2002,Feb,7)== fkbf2.get_date(date(2002,Feb,14)));
79
80 typedef nth_day_of_the_week_in_month nthkdayofmonth;
81 nthkdayofmonth nkd1(nthkdayofmonth::third, Sunday, Jul);
82 check("nth_kday 1", date(1969, Jul, 20) == nkd1.get_date(1969));
83 check("Nth kday to_string()", nkd1.to_string() == std::string("M7.3.0"));
84 nthkdayofmonth nkd2(nthkdayofmonth::second, Monday, Dec);
85 check("nth_kday 2", date(1980, Dec, 8) == nkd2.get_date(1980));
86 check("Nth kday to_string()", nkd2.to_string() == std::string("M12.2.1"));
87 nthkdayofmonth nkd3(nthkdayofmonth::fifth, Wednesday, Jan);
88 check("nth_kday fifth wed jan 2003 2003-Jan-29",
89 date(2003, Jan, 29) == nkd3.get_date(2003));
90 check("Nth kday to_string()", nkd3.to_string() == std::string("M1.5.3"));
91 nthkdayofmonth nkd4(nthkdayofmonth::fifth, Monday, Jan);
92 check("nth_kday fifth mon jan 2003 (actaully 4th) 2003-Jan-27",
93 date(2003, Jan, 27) == nkd4.get_date(2003));
94 check("Nth kday to_string()", nkd4.to_string() == std::string("M1.5.1"));
95
96 // greg date_generator functions tests
97 {
98 date sunday(2003,Feb,2),tuesday(2003,Feb,4);
99 date friday(2003,Feb,7),saturday(2003,Feb,8);
100 greg_weekday sat(Saturday), tue(Tuesday), fri(Friday), sund(Sunday);
101
102 check("Days until weekday" , days_until_weekday(saturday, sund) == days(1));
103 check("Days until weekday" , days_until_weekday(friday, tue) == days(4));
104 check("Days until weekday" , days_until_weekday(tuesday, fri) == days(3));
105 check("Days until weekday" , days_until_weekday(sunday, sat) == days(6));
106 check("Days until weekday" , days_until_weekday(sunday, sund) == days(0));
107 check("Days until weekday" , days_until_weekday(tuesday, tue) == days(0));
108
109 check("Days before weekday" , days_before_weekday(saturday, sund) == days(6));
110 check("Days before weekday" , days_before_weekday(friday, tue) == days(3));
111 check("Days before weekday" , days_before_weekday(tuesday, fri) == days(4));
112 check("Days before weekday" , days_before_weekday(sunday, sat) == days(1));
113 check("Days before weekday" , days_before_weekday(sunday, sund) == days(0));
114 check("Days before weekday" , days_before_weekday(tuesday, tue) == days(0));
115
116 check("Date of next weekday", next_weekday(saturday, sund)== date(2003,Feb,9));
117 check("Date of next weekday", next_weekday(friday, tue) == date(2003,Feb,11));
118 check("Date of next weekday", next_weekday(tuesday, fri) == date(2003,Feb,7));
119 check("Date of next weekday", next_weekday(sunday, sat) == date(2003,Feb,8));
120 check("Date of next weekday", next_weekday(sunday, sund) == sunday);
121 check("Date of next weekday", next_weekday(tuesday, tue) == tuesday);
122
123 check("Date of previous weekday", previous_weekday(saturday, sund)== date(2003,Feb,2));
124 check("Date of previous weekday", previous_weekday(friday, tue) == date(2003,Feb,4));
125 check("Date of previous weekday", previous_weekday(tuesday, fri) == date(2003,Jan,31));
126 check("Date of previous weekday", previous_weekday(sunday, sat) == date(2003,Feb,1));
127 check("Date of previous weekday", previous_weekday(sunday, sund) == sunday);
128 check("Date of previous weekday", previous_weekday(tuesday, tue) == tuesday);
129
130 }
131 #ifndef BOOST_DATE_TIME_NO_LOCALE
132 #if !defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
133 //TODO: this is temporary condition -- don't force a failure...
134 // check("no streaming implemented for new facet", false);
135 #else
136 // streaming tests...
137 std::stringstream ss("");
138 std::string s("");
139
140 ss.str("");
141 ss << pd1;
142 s = "01 Jan";
143 check("streaming partial_date", ss.str() == s);
144 std::cout << ss.str() << std::endl;
145
146 ss.str("");
147 ss << lsif;
148 s = "last Sun of Feb";
149 check("streaming last_kday_of_month", ss.str() == s);
150
151 ss.str("");
152 ss << fsif;
153 s = "first Sun of Feb";
154 check("streaming first_kday_of_month", ss.str() == s);
155
156 ss.str("");
157 ss << fkaf;
158 s = "Mon after";
159 check("streaming first_kday_after", ss.str() == s);
160
161 ss.str("");
162 ss << fkbf;
163 s = "Mon before";
164 check("streaming first_kday_before", ss.str() == s);
165
166 ss.str("");
167 ss << nkd1;
168 s = "third Sun of Jul";
169 check("streaming nth_kday", ss.str() == s);
170 #endif // USE_DATE_TIME_PRE_1_33_FACET_IO
171 #endif // NO_LOCAL
172
173 return printTestStats();
174
175 }
176