1/* Copyright (c) 2002,2003 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
6 */
7
8#include "boost/date_time/posix_time/posix_time.hpp"
9#include "boost/date_time/local_timezone_defs.hpp"
10#include "../testfrmwk.hpp"
11
12// Define dst rule for Paraguay which is transitions forward on Oct 1 and
13// back Mar 1
14
15struct paraguay_dst_traits {
16 typedef boost::gregorian::date date_type;
17 typedef boost::gregorian::date::day_type day_type;
18 typedef boost::gregorian::date::month_type month_type;
19 typedef boost::gregorian::date::year_type year_type;
20 typedef boost::date_time::partial_date<boost::gregorian::date> start_rule_functor;
21 typedef boost::date_time::partial_date<boost::gregorian::date> end_rule_functor;
22 static day_type start_day(year_type) {return 1;}
23 static month_type start_month(year_type) {return boost::date_time::Oct;}
24 static day_type end_day(year_type) {return 1;}
25 static month_type end_month(year_type) {return boost::date_time::Mar;}
26 static int dst_start_offset_minutes() { return 120;}
27 static int dst_end_offset_minutes() { return 120; }
28 static int dst_shift_length_minutes() { return 60; }
29 static date_type local_dst_start_day(year_type year)
30 {
31 start_rule_functor start(start_day(year),
32 start_month(year));
33 return start.get_date(y: year);
34 }
35 static date_type local_dst_end_day(year_type year)
36 {
37 end_rule_functor end(end_day(year),
38 end_month(year));
39 return end.get_date(y: year);
40 }
41
42
43};
44
45
46// see http://www.timeanddate.com/time/aboutdst.html for some info
47// also
48int
49main()
50{
51 using namespace boost::posix_time;
52 using namespace boost::gregorian;
53 date d(2002,Feb,1);
54 ptime t(d);
55
56 //The following defines the US dst boundaries, except that the
57 //start and end dates are hard coded.
58 typedef boost::date_time::us_dst_rules<date, time_duration, 120, 60> us_dst_local;
59 date dst_start(2002,Apr, 7);
60 date dst_end(2002,Oct, 27);
61
62 ptime t3a(dst_start, time_duration(2,0,0)); //invalid time label
63 ptime t3b(dst_start, time_duration(2,59,59)); //invalid time label
64 ptime t4(dst_start, time_duration(1,59,59)); //not ds
65 ptime t5(dst_start, time_duration(3,0,0)); //always dst
66 ptime t6(dst_end, time_duration(0,59,59)); //is dst
67 ptime t7(dst_end, time_duration(1,0,0)); //ambiguous
68 ptime t8(dst_end, time_duration(1,59,59)); //ambiguous
69 ptime t9(dst_end, time_duration(2,0,0)); //always not dst
70
71 check(testname: "dst start", testcond: us_dst_local::local_dst_start_day(year: 2002) == dst_start);
72 check(testname: "dst end", testcond: us_dst_local::local_dst_end_day(year: 2002) == dst_end);
73 check(testname: "dst boundary", testcond: us_dst_local::is_dst_boundary_day(d: dst_start));
74 check(testname: "dst boundary", testcond: us_dst_local::is_dst_boundary_day(d: dst_end));
75 check(testname: "check if time is dst -- not",
76 testcond: us_dst_local::local_is_dst(d: t.date(), td: t.time_of_day())==boost::date_time::is_not_in_dst);
77 check(testname: "label on dst boundary invalid",
78 testcond: us_dst_local::local_is_dst(d: t3a.date(),td: t3a.time_of_day())==boost::date_time::invalid_time_label);
79 check(testname: "label on dst boundary invalid",
80 testcond: us_dst_local::local_is_dst(d: t3b.date(),td: t3b.time_of_day())==boost::date_time::invalid_time_label);
81 check(testname: "check if time is dst -- not",
82 testcond: us_dst_local::local_is_dst(d: t4.date(),td: t4.time_of_day())==boost::date_time::is_not_in_dst);
83 check(testname: "check if time is dst -- yes",
84 testcond: us_dst_local::local_is_dst(d: t5.date(),td: t5.time_of_day())==boost::date_time::is_in_dst);
85
86 check(testname: "check if time is dst -- not",
87 testcond: us_dst_local::local_is_dst(d: t6.date(),td: t6.time_of_day())==boost::date_time::is_in_dst);
88 check(testname: "check if time is dst -- ambig",
89 testcond: us_dst_local::local_is_dst(d: t7.date(),td: t7.time_of_day())==boost::date_time::ambiguous);
90 check(testname: "check if time is dst -- ambig",
91 testcond: us_dst_local::local_is_dst(d: t8.date(),td: t8.time_of_day())==boost::date_time::ambiguous);
92 check(testname: "check if time is dst -- not",
93 testcond: us_dst_local::local_is_dst(d: t9.date(),td: t9.time_of_day())==boost::date_time::is_not_in_dst);
94
95
96 //Now try a local without dst
97 typedef boost::date_time::null_dst_rules<date, time_duration> no_dst_adj;
98
99 check(testname: "check null dst rules",
100 testcond: no_dst_adj::local_is_dst(t4.date(),t4.time_of_day())==boost::date_time::is_not_in_dst);
101 check(testname: "check null dst rules",
102 testcond: no_dst_adj::local_is_dst(t5.date(),t5.time_of_day())==boost::date_time::is_not_in_dst);
103 check(testname: "check null dst rules",
104 testcond: no_dst_adj::utc_is_dst(t4.date(),t4.time_of_day())==boost::date_time::is_not_in_dst);
105 check(testname: "check null dst rules",
106 testcond: no_dst_adj::utc_is_dst(t5.date(),t5.time_of_day())==boost::date_time::is_not_in_dst);
107
108
109 //Try a southern hemisphere adjustment calculation
110 //This is following the rules for South Australia as best I can
111 //decipher them. Basically conversion to DST is last Sunday in
112 //October 02:00:00 and conversion off of dst is last sunday in
113 //March 02:00:00.
114 //This stuff uses the dst calculator directly...
115 date dst_start2(2002,Oct,27); //last Sunday in Oct
116 date dst_end2(2002,Mar,31); //last Sunday in March
117
118 typedef boost::date_time::dst_calculator<date,time_duration> dstcalc;
119 //clearly not in dst
120 boost::date_time::time_is_dst_result a1 =
121 dstcalc::local_is_dst(current_day: date(2002,May,1),time_of_day: hours(3),
122 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
123 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
124 dst_length_minutes: 60);
125
126 check(testname: "check southern not dst", testcond: a1==boost::date_time::is_not_in_dst);
127
128 boost::date_time::time_is_dst_result a2 =
129 dstcalc::local_is_dst(current_day: date(2002,Jan,1),time_of_day: hours(3),
130 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
131 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
132 dst_length_minutes: 60);
133
134 check(testname: "check southern is dst", testcond: a2==boost::date_time::is_in_dst);
135
136 boost::date_time::time_is_dst_result a3 =
137 dstcalc::local_is_dst(current_day: date(2002,Oct,28),time_of_day: hours(3),
138 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
139 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
140 dst_length_minutes: 60);
141
142 check(testname: "check southern is dst", testcond: a3==boost::date_time::is_in_dst);
143 boost::date_time::time_is_dst_result a4 =
144 dstcalc::local_is_dst(current_day: date(2002,Oct,27),time_of_day: time_duration(1,59,59),
145 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
146 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
147 dst_length_minutes: 60);
148 check(testname: "check southern boundary-not dst", testcond: a4==boost::date_time::is_not_in_dst);
149 boost::date_time::time_is_dst_result a5 =
150 dstcalc::local_is_dst(current_day: date(2002,Oct,27),time_of_day: hours(3),
151 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
152 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
153 dst_length_minutes: 60);
154 check(testname: "check southern boundary-is dst", testcond: a5==boost::date_time::is_in_dst);
155 boost::date_time::time_is_dst_result a6 =
156 dstcalc::local_is_dst(current_day: date(2002,Oct,27),time_of_day: hours(2),
157 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
158 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
159 dst_length_minutes: 60);
160 check(testname: "check southern boundary-invalid time", testcond: a6==boost::date_time::invalid_time_label);
161 boost::date_time::time_is_dst_result a7 =
162 dstcalc::local_is_dst(current_day: date(2002,Mar,31),time_of_day: time_duration(1,59,59),
163 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
164 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
165 dst_length_minutes: 60);
166 check(testname: "check southern boundary-is dst", testcond: a7==boost::date_time::is_in_dst);
167 boost::date_time::time_is_dst_result a8 =
168 dstcalc::local_is_dst(current_day: date(2002,Mar,31),time_of_day: time_duration(2,0,0),
169 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
170 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
171 dst_length_minutes: 60);
172 check(testname: "check southern boundary-ambiguous", testcond: a8==boost::date_time::ambiguous);
173 boost::date_time::time_is_dst_result a9 =
174 dstcalc::local_is_dst(current_day: date(2002,Mar,31),time_of_day: time_duration(2,59,59),
175 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
176 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
177 dst_length_minutes: 60);
178 check(testname: "check southern boundary-ambiguous", testcond: a9==boost::date_time::ambiguous);
179 boost::date_time::time_is_dst_result a10 =
180 dstcalc::local_is_dst(current_day: date(2002,Mar,31),time_of_day: time_duration(3,0,0),
181 dst_start_day: dst_start2, dst_start_offset_minutes: 120,
182 dst_end_day: dst_end2, dst_end_offset_minutes: 180,
183 dst_length_minutes: 60);
184 check(testname: "check southern boundary-not", testcond: a10==boost::date_time::is_not_in_dst);
185
186 /******************** post release 1 -- new dst calc engine ********/
187
188 typedef boost::date_time::us_dst_trait<date> us_dst_traits;
189 typedef boost::date_time::dst_calc_engine<date, time_duration, us_dst_traits>
190 us_dst_calc2;
191
192 {
193 // us_dst_calc2
194 check(testname: "dst start", testcond: us_dst_calc2::local_dst_start_day(year: 2002) == dst_start);
195 check(testname: "dst end", testcond: us_dst_calc2::local_dst_end_day(year: 2002) == dst_end);
196 // std::cout << us_dst_calc2::local_dst_end_day(2002) << std::endl;
197 check(testname: "dst boundary", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_start));
198 check(testname: "dst boundary", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_end));
199
200 check(testname: "check if time is dst -- not",
201 testcond: us_dst_calc2::local_is_dst(d: t.date(), td: t.time_of_day())==boost::date_time::is_not_in_dst);
202 check(testname: "label on dst boundary invalid",
203 testcond: us_dst_calc2::local_is_dst(d: t3a.date(),td: t3a.time_of_day())==boost::date_time::invalid_time_label);
204 check(testname: "label on dst boundary invalid",
205 testcond: us_dst_calc2::local_is_dst(d: t3b.date(),td: t3b.time_of_day())==boost::date_time::invalid_time_label);
206 check(testname: "check if time is dst -- not",
207 testcond: us_dst_calc2::local_is_dst(d: t4.date(),td: t4.time_of_day())==boost::date_time::is_not_in_dst);
208 check(testname: "check if time is dst -- yes",
209 testcond: us_dst_calc2::local_is_dst(d: t5.date(),td: t5.time_of_day())==boost::date_time::is_in_dst);
210
211 check(testname: "check if time is dst -- not",
212 testcond: us_dst_calc2::local_is_dst(d: t6.date(),td: t6.time_of_day())==boost::date_time::is_in_dst);
213 check(testname: "check if time is dst -- ambig",
214 testcond: us_dst_calc2::local_is_dst(d: t7.date(),td: t7.time_of_day())==boost::date_time::ambiguous);
215 check(testname: "check if time is dst -- ambig",
216 testcond: us_dst_calc2::local_is_dst(d: t8.date(),td: t8.time_of_day())==boost::date_time::ambiguous);
217 check(testname: "check if time is dst -- not",
218 testcond: us_dst_calc2::local_is_dst(d: t9.date(),td: t9.time_of_day())==boost::date_time::is_not_in_dst);
219 }
220 {
221 //some new checks for the new 2007 us dst rules
222 date dst_start07(2007,Mar, 11);
223 date dst_end07(2007,Nov, 4);
224
225 check(testname: "dst start07", testcond: us_dst_calc2::local_dst_start_day(year: 2007) == dst_start07);
226 check(testname: "dst end07", testcond: us_dst_calc2::local_dst_end_day(year: 2007) == dst_end07);
227 check(testname: "dst boundary07", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_start07));
228 check(testname: "dst boundary07", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_end07));
229
230 date dst_start08(2008,Mar, 9);
231 date dst_end08(2008,Nov, 2);
232
233 check(testname: "dst start08", testcond: us_dst_calc2::local_dst_start_day(year: 2008) == dst_start08);
234 check(testname: "dst end08", testcond: us_dst_calc2::local_dst_end_day(year: 2008) == dst_end08);
235 check(testname: "dst boundary08", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_start08));
236 check(testname: "dst boundary08", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_end08));
237
238 date dst_start09(2009,Mar, 8);
239 date dst_end09(2009,Nov, 1);
240
241 check(testname: "dst start09", testcond: us_dst_calc2::local_dst_start_day(year: 2009) == dst_start09);
242 check(testname: "dst end09", testcond: us_dst_calc2::local_dst_end_day(year: 2009) == dst_end09);
243 check(testname: "dst boundary09", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_start09));
244 check(testname: "dst boundary09", testcond: us_dst_calc2::is_dst_boundary_day(d: dst_end09));
245
246 }
247
248
249
250 /******************** post release 1 -- new dst calc engine - eu dst ********/
251
252
253 typedef boost::date_time::eu_dst_trait<date> eu_dst_traits;
254 typedef boost::date_time::dst_calc_engine<date, time_duration, eu_dst_traits>
255 eu_dst_calc;
256 date eu_dst_start(2002,Mar, 31);
257 date eu_dst_end(2002,Oct, 27);
258 ptime eu_invalid1(eu_dst_start, time_duration(2,0,0)); //invalid time label
259 ptime eu_invalid2(eu_dst_start, time_duration(2,59,59)); //invalid time label
260 ptime eu_notdst1(eu_dst_start, time_duration(1,59,59)); //not ds
261 ptime eu_isdst1(eu_dst_start, time_duration(3,0,0)); //always dst
262 ptime eu_isdst2(eu_dst_end, time_duration(1,59,59)); //is dst
263 ptime eu_amgbig1(eu_dst_end, time_duration(2,0,0)); //ambiguous
264 ptime eu_amgbig2(eu_dst_end, time_duration(2,59,59)); //ambiguous
265 ptime eu_notdst2(eu_dst_end, time_duration(3,0,0)); //always not dst
266
267 check(testname: "eu dst start", testcond: eu_dst_calc::local_dst_start_day(year: 2002) == eu_dst_start);
268 check(testname: "eu dst end", testcond: eu_dst_calc::local_dst_end_day(year: 2002) == eu_dst_end);
269 check(testname: "eu dst boundary", testcond: eu_dst_calc::is_dst_boundary_day(d: eu_dst_start));
270 check(testname: "eu dst boundary", testcond: eu_dst_calc::is_dst_boundary_day(d: eu_dst_end));
271 // on forward shift boundaries
272 check(testname: "eu label on dst boundary invalid",
273 testcond: eu_dst_calc::local_is_dst(d: eu_invalid1.date(),td: eu_invalid1.time_of_day())==boost::date_time::invalid_time_label);
274 check(testname: "eu label on dst boundary invalid",
275 testcond: eu_dst_calc::local_is_dst(d: eu_invalid2.date(),td: eu_invalid2.time_of_day())==boost::date_time::invalid_time_label);
276 check(testname: "eu check if time is dst -- not",
277 testcond: eu_dst_calc::local_is_dst(d: eu_notdst1.date(),td: eu_notdst1.time_of_day())==boost::date_time::is_not_in_dst);
278 check(testname: "check if time is dst -- yes",
279 testcond: eu_dst_calc::local_is_dst(d: eu_isdst1.date(),td: eu_isdst1.time_of_day())==boost::date_time::is_in_dst);
280 //backward shift boundary
281 check(testname: "eu check if time is dst -- yes",
282 testcond: eu_dst_calc::local_is_dst(d: eu_isdst2.date(),td: eu_isdst2.time_of_day())==boost::date_time::is_in_dst);
283 check(testname: "eu check if time is dst -- ambig",
284 testcond: eu_dst_calc::local_is_dst(d: eu_amgbig1.date(),td: eu_amgbig1.time_of_day())==boost::date_time::ambiguous);
285 check(testname: "eu check if time is dst -- ambig",
286 testcond: eu_dst_calc::local_is_dst(d: eu_amgbig2.date(),td: eu_amgbig2.time_of_day())==boost::date_time::ambiguous);
287 check(testname: "eu check if time is dst -- not",
288 testcond: eu_dst_calc::local_is_dst(d: eu_notdst2.date(),td: eu_notdst2.time_of_day())==boost::date_time::is_not_in_dst);
289
290/******************** post release 1 -- new dst calc engine - gb dst ********/
291
292
293 /* Several places in Great Britan use eu start and end rules for the
294 day, but different local conversion times (eg: forward change at 1:00
295 am local and backward change at 2:00 am dst instead of 2:00am
296 forward and 3:00am back for the EU).
297 */
298
299 typedef boost::date_time::uk_dst_trait<date> uk_dst_traits;
300
301 typedef boost::date_time::dst_calc_engine<date, time_duration, uk_dst_traits> uk_dst_calc;
302
303
304 date uk_dst_start(2002,Mar, 31);
305 date uk_dst_end(2002,Oct, 27);
306 ptime uk_invalid1(uk_dst_start, time_duration(1,0,0)); //invalid time label
307 ptime uk_invalid2(uk_dst_start, time_duration(1,59,59)); //invalid time label
308 ptime uk_notdst1(uk_dst_start, time_duration(0,59,59)); //not ds
309 ptime uk_isdst1(uk_dst_start, time_duration(2,0,0)); //always dst
310 ptime uk_isdst2(uk_dst_end, time_duration(0,59,59)); //is dst
311 ptime uk_amgbig1(uk_dst_end, time_duration(1,0,0)); //ambiguous
312 ptime uk_amgbig2(uk_dst_end, time_duration(1,59,59)); //ambiguous
313 ptime uk_notdst2(uk_dst_end, time_duration(3,0,0)); //always not dst
314
315 check(testname: "uk dst start", testcond: uk_dst_calc::local_dst_start_day(year: 2002) == uk_dst_start);
316 check(testname: "uk dst end", testcond: uk_dst_calc::local_dst_end_day(year: 2002) == uk_dst_end);
317 check(testname: "uk dst boundary", testcond: uk_dst_calc::is_dst_boundary_day(d: uk_dst_start));
318 check(testname: "uk dst boundary", testcond: uk_dst_calc::is_dst_boundary_day(d: uk_dst_end));
319 // on forward shift boundaries
320 check(testname: "uk label on dst boundary invalid",
321 testcond: uk_dst_calc::local_is_dst(d: uk_invalid1.date(),td: uk_invalid1.time_of_day())==boost::date_time::invalid_time_label);
322 check(testname: "uk label on dst boundary invalid",
323 testcond: uk_dst_calc::local_is_dst(d: uk_invalid2.date(),td: uk_invalid2.time_of_day())==boost::date_time::invalid_time_label);
324 check(testname: "uk check if time is dst -- not",
325 testcond: uk_dst_calc::local_is_dst(d: uk_notdst1.date(),td: uk_notdst1.time_of_day())==boost::date_time::is_not_in_dst);
326 check(testname: "uk check if time is dst -- yes",
327 testcond: uk_dst_calc::local_is_dst(d: uk_isdst1.date(),td: uk_isdst1.time_of_day())==boost::date_time::is_in_dst);
328 //backward shift boundary
329 check(testname: "uk check if time is dst -- yes",
330 testcond: uk_dst_calc::local_is_dst(d: uk_isdst2.date(),td: uk_isdst2.time_of_day())==boost::date_time::is_in_dst);
331 check(testname: "uk check if time is dst -- ambig",
332 testcond: uk_dst_calc::local_is_dst(d: uk_amgbig1.date(),td: uk_amgbig1.time_of_day())==boost::date_time::ambiguous);
333 check(testname: "uk check if time is dst -- ambig",
334 testcond: uk_dst_calc::local_is_dst(d: uk_amgbig2.date(),td: uk_amgbig2.time_of_day())==boost::date_time::ambiguous);
335 check(testname: "uk check if time is dst -- not",
336 testcond: uk_dst_calc::local_is_dst(d: uk_notdst2.date(),td: uk_notdst2.time_of_day())==boost::date_time::is_not_in_dst);
337
338
339// /******************** post release 1 -- new dst calc engine ********/
340
341// //Define dst rule for Paraguay which is transitions forward on Oct 1 and back Mar 1
342
343 typedef boost::date_time::dst_calc_engine<date, time_duration,
344 paraguay_dst_traits> pg_dst_calc;
345
346 {
347
348 date pg_dst_start(2002,Oct, 1);
349 date pg_dst_end(2002,Mar, 1);
350 date pg_indst(2002,Dec, 1);
351 date pg_notdst(2002,Jul, 1);
352 ptime pg_invalid1(pg_dst_start, time_duration(2,0,0)); //invalid time label
353 ptime pg_invalid2(pg_dst_start, time_duration(2,59,59)); //invalid time label
354 ptime pg_notdst1(pg_dst_start, time_duration(1,59,59)); //not ds
355 ptime pg_isdst1(pg_dst_start, time_duration(3,0,0)); //always dst
356 ptime pg_isdst2(pg_dst_end, time_duration(0,59,59)); //is dst
357 ptime pg_amgbig1(pg_dst_end, time_duration(1,0,0)); //ambiguous
358 ptime pg_amgbig2(pg_dst_end, time_duration(1,59,59)); //ambiguous
359 ptime pg_notdst2(pg_dst_end, time_duration(2,0,0)); //always not dst
360
361 check(testname: "pg dst start", testcond: pg_dst_calc::local_dst_start_day(year: 2002) == pg_dst_start);
362 check(testname: "pg dst end", testcond: pg_dst_calc::local_dst_end_day(year: 2002) == pg_dst_end);
363 check(testname: "pg dst boundary", testcond: pg_dst_calc::is_dst_boundary_day(d: pg_dst_start));
364 check(testname: "pg dst boundary", testcond: pg_dst_calc::is_dst_boundary_day(d: pg_dst_end));
365 // on forward shift boundaries
366 check(testname: "pg label on dst boundary invalid",
367 testcond: pg_dst_calc::local_is_dst(d: pg_invalid1.date(),td: pg_invalid1.time_of_day())==boost::date_time::invalid_time_label);
368 check(testname: "pg label on dst boundary invalid",
369 testcond: pg_dst_calc::local_is_dst(d: pg_invalid2.date(),td: pg_invalid2.time_of_day())==boost::date_time::invalid_time_label);
370 check(testname: "pg check if time is dst -- not",
371 testcond: pg_dst_calc::local_is_dst(d: pg_notdst1.date(),td: pg_notdst1.time_of_day())==boost::date_time::is_not_in_dst);
372 check(testname: "check if time is dst -- yes",
373 testcond: pg_dst_calc::local_is_dst(d: pg_isdst1.date(),td: pg_isdst1.time_of_day())==boost::date_time::is_in_dst);
374 //backward shift boundary
375 check(testname: "pg check if time is dst -- yes",
376 testcond: pg_dst_calc::local_is_dst(d: pg_isdst2.date(),td: pg_isdst2.time_of_day())==boost::date_time::is_in_dst);
377 check(testname: "pg check if time is dst -- ambig",
378 testcond: pg_dst_calc::local_is_dst(d: pg_amgbig1.date(),td: pg_amgbig1.time_of_day())==boost::date_time::ambiguous);
379 check(testname: "pg check if time is dst -- ambig",
380 testcond: pg_dst_calc::local_is_dst(d: pg_amgbig2.date(),td: pg_amgbig2.time_of_day())==boost::date_time::ambiguous);
381 check(testname: "pg check if time is dst -- not",
382 testcond: pg_dst_calc::local_is_dst(d: pg_notdst2.date(),td: pg_notdst2.time_of_day())==boost::date_time::is_not_in_dst);
383 // a couple not on the boudnary
384 check(testname: "pg check if time is dst -- yes",
385 testcond: pg_dst_calc::local_is_dst(d: pg_indst,td: time_duration(0,0,0))==boost::date_time::is_in_dst);
386 check(testname: "pg check if time is dst -- not",
387 testcond: pg_dst_calc::local_is_dst(d: pg_notdst,td: time_duration(0,0,0))==boost::date_time::is_not_in_dst);
388
389 }
390
391// /******************** post release 1 -- new dst calc engine ********/
392
393// //Define dst rule for Adelaide australia
394
395 typedef boost::date_time::acst_dst_trait<date> acst_dst_traits;
396 typedef boost::date_time::dst_calc_engine<date, time_duration,
397 acst_dst_traits> acst_dst_calc;
398
399 {
400
401 date acst_dst_start(2002,Oct, 27);
402 date acst_dst_end(2002,Mar, 31);
403 date acst_indst(2002,Dec, 1);
404 date acst_notdst(2002,Jul, 1);
405 ptime acst_invalid1(acst_dst_start, time_duration(2,0,0)); //invalid time label
406 ptime acst_invalid2(acst_dst_start, time_duration(2,59,59)); //invalid time label
407 ptime acst_notdst1(acst_dst_start, time_duration(1,59,59)); //not ds
408 ptime acst_isdst1(acst_dst_start, time_duration(3,0,0)); //always dst
409 ptime acst_isdst2(acst_dst_end, time_duration(1,59,59)); //is dst
410 ptime acst_amgbig1(acst_dst_end, time_duration(2,0,0)); //ambiguous
411 ptime acst_amgbig2(acst_dst_end, time_duration(2,59,59)); //ambiguous
412 ptime acst_notdst2(acst_dst_end, time_duration(3,0,0)); //always not dst
413
414// std::cout << "acst dst_start: " << acst_dst_calc::local_dst_start_day(2002)
415// << std::endl;
416 check(testname: "acst dst start", testcond: acst_dst_calc::local_dst_start_day(year: 2002) == acst_dst_start);
417 check(testname: "acst dst end", testcond: acst_dst_calc::local_dst_end_day(year: 2002) == acst_dst_end);
418 check(testname: "acst dst boundary", testcond: acst_dst_calc::is_dst_boundary_day(d: acst_dst_start));
419 check(testname: "acst dst boundary", testcond: acst_dst_calc::is_dst_boundary_day(d: acst_dst_end));
420 // on forward shift boundaries
421 check(testname: "acst label on dst boundary invalid",
422 testcond: acst_dst_calc::local_is_dst(d: acst_invalid1.date(),td: acst_invalid1.time_of_day())==boost::date_time::invalid_time_label);
423 check(testname: "acst label on dst boundary invalid",
424 testcond: acst_dst_calc::local_is_dst(d: acst_invalid2.date(),td: acst_invalid2.time_of_day())==boost::date_time::invalid_time_label);
425 check(testname: "acst check if time is dst -- not",
426 testcond: acst_dst_calc::local_is_dst(d: acst_notdst1.date(),td: acst_notdst1.time_of_day())==boost::date_time::is_not_in_dst);
427 check(testname: "check if time is dst -- yes",
428 testcond: acst_dst_calc::local_is_dst(d: acst_isdst1.date(),td: acst_isdst1.time_of_day())==boost::date_time::is_in_dst);
429 //backward shift boundary
430 check(testname: "acst check if time is dst -- yes",
431 testcond: acst_dst_calc::local_is_dst(d: acst_isdst2.date(),td: acst_isdst2.time_of_day())==boost::date_time::is_in_dst);
432 check(testname: "acst check if time is dst -- ambig",
433 testcond: acst_dst_calc::local_is_dst(d: acst_amgbig1.date(),td: acst_amgbig1.time_of_day())==boost::date_time::ambiguous);
434 check(testname: "acst check if time is dst -- ambig",
435 testcond: acst_dst_calc::local_is_dst(d: acst_amgbig2.date(),td: acst_amgbig2.time_of_day())==boost::date_time::ambiguous);
436 check(testname: "acst check if time is dst -- not",
437 testcond: acst_dst_calc::local_is_dst(d: acst_notdst2.date(),td: acst_notdst2.time_of_day())==boost::date_time::is_not_in_dst);
438 // a couple not on the boudnary
439 check(testname: "acst check if time is dst -- yes",
440 testcond: acst_dst_calc::local_is_dst(d: acst_indst,td: time_duration(0,0,0))==boost::date_time::is_in_dst);
441 check(testname: "acst check if time is dst -- not",
442 testcond: acst_dst_calc::local_is_dst(d: acst_notdst,td: time_duration(0,0,0))==boost::date_time::is_not_in_dst);
443 // ptime utc_t = ptime(acst_dst_start, hours(2)) - time_duration(16,30,0);
444 // std::cout << "UTC date/time of Adelaide switch over: " << utc_t << std::endl;
445
446 }
447
448 return printTestStats();
449
450}
451
452

source code of boost/libs/date_time/test/posix_time/testdst_rules.cpp