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