| 1 | /* Copyright (c) 2003-2005 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 | |
| 8 | #include "boost/date_time/local_time/local_time.hpp" |
| 9 | #include "../testfrmwk.hpp" |
| 10 | #include <iostream> |
| 11 | |
| 12 | int |
| 13 | main() |
| 14 | { |
| 15 | |
| 16 | using namespace boost::gregorian; |
| 17 | using namespace boost::posix_time; |
| 18 | using namespace boost::local_time; |
| 19 | |
| 20 | |
| 21 | boost::shared_ptr<dst_calc_rule> |
| 22 | rule1(new partial_date_dst_rule(partial_date(30,Apr), |
| 23 | partial_date(30,Oct))); |
| 24 | |
| 25 | boost::shared_ptr<dst_calc_rule> |
| 26 | rule2(new first_last_dst_rule(first_last_dst_rule::start_rule(Sunday,Apr), |
| 27 | first_last_dst_rule::end_rule(Sunday,Oct))); |
| 28 | boost::shared_ptr<dst_calc_rule> |
| 29 | rule3(new last_last_dst_rule(last_last_dst_rule::start_rule(Sunday,Mar), |
| 30 | last_last_dst_rule::end_rule(Sunday,Oct))); |
| 31 | boost::shared_ptr<dst_calc_rule> rule4; // no daylight savings |
| 32 | |
| 33 | time_zone_names pst("Pacific Standard Time" , |
| 34 | "PST" , |
| 35 | "Pacific Daylight Time" , |
| 36 | "PDT" ); |
| 37 | time_zone_names mst("Mountain Standard Time" , |
| 38 | "MST" , |
| 39 | "" , |
| 40 | "" ); |
| 41 | |
| 42 | dst_adjustment_offsets of(hours(1), hours(2), hours(2)); |
| 43 | dst_adjustment_offsets of2(hours(0), hours(0), hours(0)); // no daylight savings |
| 44 | |
| 45 | time_zone_ptr tz1(new custom_time_zone(pst, hours(-8), of, rule1)); |
| 46 | time_zone_ptr tz2(new custom_time_zone(pst, hours(-8), of, rule2)); |
| 47 | time_zone_ptr tz3(new custom_time_zone(pst, hours(-8), of, rule3)); |
| 48 | time_zone_ptr tz4(new custom_time_zone(mst, hours(-7), of2, rule4)); |
| 49 | |
| 50 | check(testname: "out string" , |
| 51 | testcond: tz1->dst_zone_abbrev() == std::string("PDT" )); |
| 52 | check(testname: "out string" , |
| 53 | testcond: tz1->std_zone_abbrev() == std::string("PST" )); |
| 54 | check(testname: "out string" , |
| 55 | testcond: tz1->std_zone_name() == std::string("Pacific Standard Time" )); |
| 56 | check(testname: "out string" , |
| 57 | testcond: tz1->dst_zone_name() == std::string("Pacific Daylight Time" )); |
| 58 | |
| 59 | check(testname: "dst offset" , testcond: tz1->dst_offset() == hours(1)); |
| 60 | check(testname: "base offset" , testcond: tz1->base_utc_offset() == hours(-8)); |
| 61 | check(testname: "has dst" , testcond: tz1->has_dst()); |
| 62 | |
| 63 | check(testname: "dst start time" , |
| 64 | testcond: tz1->dst_local_start_time(y: 2003) == ptime(date(2003,Apr,30),hours(2))); |
| 65 | check(testname: "dst end time" , |
| 66 | testcond: tz1->dst_local_end_time(y: 2003) == ptime(date(2003,Oct,30),hours(2))); |
| 67 | |
| 68 | check(testname: "tz1 to posix string" , |
| 69 | testcond: tz1->to_posix_string() == std::string("PST-08PDT+01,120/02:00,303/02:00" )); |
| 70 | check(testname: "tz2 to posix string" , |
| 71 | testcond: tz2->to_posix_string() == std::string("PST-08PDT+01,M4.1.0/02:00,M10.5.0/02:00" )); |
| 72 | check(testname: "tz3 to posix string" , |
| 73 | testcond: tz3->to_posix_string() == std::string("PST-08PDT+01,M3.5.0/02:00,M10.5.0/02:00" )); |
| 74 | check(testname: "tz4 to posix string" , |
| 75 | testcond: tz4->to_posix_string() == std::string("MST-07" )); |
| 76 | |
| 77 | // test start/end for non-dst zone |
| 78 | check(testname: "has dst in non-dst zone" , testcond: !tz4->has_dst()); |
| 79 | check(testname: "dst start in non-dst zone" , |
| 80 | testcond: tz4->dst_local_start_time(y: 2005) == ptime(not_a_date_time)); |
| 81 | check(testname: "dst end in non-dst zone" , |
| 82 | testcond: tz4->dst_local_end_time(y: 2005) == ptime(not_a_date_time)); |
| 83 | |
| 84 | |
| 85 | return printTestStats(); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |