testdst_transition_day_rule.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (c) 2003-2004 CrystalClear Software, Inc.
  2. * Subject to the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  4. * Author: Jeff Garland, Bart Garst
  5. * $Date$
  6. */
  7. #include "boost/date_time/gregorian/gregorian.hpp"
  8. #include "boost/date_time/local_time/dst_transition_day_rules.hpp"
  9. #include "boost/shared_ptr.hpp"
  10. #include "../testfrmwk.hpp"
  11. // see http://www.timeanddate.com/time/aboutdst.html for some info
  12. // also
  13. int
  14. main()
  15. {
  16. // using namespace boost::posix_time;
  17. using namespace boost::local_time;
  18. using namespace boost::gregorian;
  19. boost::shared_ptr<dst_calc_rule>
  20. rule1(new partial_date_dst_rule(partial_date(30,Apr),
  21. partial_date(30,Oct)));
  22. check("partial date rule", rule1->start_day(2001) == date(2001, Apr, 30));
  23. check("partial date rule", rule1->end_day(2001) == date(2001, Oct, 30));
  24. boost::shared_ptr<dst_calc_rule>
  25. rule2(new first_last_dst_rule(first_last_dst_rule::start_rule(Sunday,Apr),
  26. first_last_dst_rule::end_rule(Sunday,Oct)));
  27. check("first last rule", rule2->start_day(2001) == date(2001, Apr, 1));
  28. check("first last rule", rule2->end_day(2001) == date(2001, Oct, 28));
  29. boost::shared_ptr<dst_calc_rule>
  30. rule3(new last_last_dst_rule(last_last_dst_rule::start_rule(Sunday,Mar),
  31. last_last_dst_rule::end_rule(Sunday,Oct)));
  32. check("last last rule", rule3->start_day(2001) == date(2001, Mar, 25));
  33. check("last last rule", rule3->end_day(2001) == date(2001, Oct, 28));
  34. typedef nth_kday_of_month nkday;
  35. boost::shared_ptr<dst_calc_rule>
  36. rule4(new nth_last_dst_rule(nth_last_dst_rule::start_rule(nkday::first,Sunday,Mar),
  37. nth_last_dst_rule::end_rule(Sunday,Oct)));
  38. check("nth Last rule", rule4->start_day(2001) == date(2001, Mar, 4));
  39. check("nth Last rule", rule4->end_day(2001) == date(2001, Oct, 28));
  40. boost::shared_ptr<dst_calc_rule>
  41. rule5(new nth_kday_dst_rule(nth_kday_dst_rule::start_rule(nkday::first,Sunday,Mar),
  42. nth_kday_dst_rule::end_rule(nkday::fourth,Sunday,Oct)));
  43. check("nth_kday rule", rule5->start_day(2001) == date(2001, Mar, 4));
  44. check("nth_kday rule", rule5->end_day(2001) == date(2001, Oct, 28));
  45. return printTestStats();
  46. }