testdst_rules.cpp 23 KB

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