Chris@16
|
1 #ifndef DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__
|
Chris@16
|
2 #define DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__
|
Chris@16
|
3
|
Chris@16
|
4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
|
Chris@16
|
5 * Use, modification and distribution is subject to the
|
Chris@16
|
6 * Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 * Author: Jeff Garland
|
Chris@101
|
9 * $Date$
|
Chris@16
|
10 */
|
Chris@16
|
11
|
Chris@16
|
12 #include "boost/date_time/dst_rules.hpp"
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost {
|
Chris@16
|
15 namespace date_time {
|
Chris@16
|
16
|
Chris@16
|
17 // Configurations for common dst rules cases:
|
Chris@16
|
18 // See http://www.wharton.co.uk/Support/sup_dst.htm for more
|
Chris@16
|
19 // information on how various locales use dst rules
|
Chris@16
|
20
|
Chris@16
|
21 //! Specification for daylight savings start rules in US
|
Chris@16
|
22 /*! This class is used to configure dst_calc_engine template typically
|
Chris@16
|
23 as follows:
|
Chris@16
|
24 @code
|
Chris@16
|
25 using namespace boost::gregorian;
|
Chris@16
|
26 using namespace boost::posix_time;
|
Chris@16
|
27 typedef us_dst_trait<date> us_dst_traits;
|
Chris@16
|
28 typedef boost::date_time::dst_calc_engine<date, time_duration,
|
Chris@16
|
29 us_dst_traits>
|
Chris@16
|
30 us_dst_calc;
|
Chris@16
|
31 //calculate the 2002 transition day of USA April 7 2002
|
Chris@16
|
32 date dst_start = us_dst_calc::local_dst_start_day(2002);
|
Chris@16
|
33
|
Chris@16
|
34 //calculate the 2002 transition day of USA Oct 27 2002
|
Chris@16
|
35 date dst_end = us_dst_calc::local_dst_end_day(2002);
|
Chris@16
|
36
|
Chris@16
|
37 //check if a local time is in dst or not -- posible answers
|
Chris@16
|
38 //are yes, no, invalid time label, ambiguous
|
Chris@16
|
39 ptime t(...some time...);
|
Chris@16
|
40 if (us_dst::local_is_dst(t.date(), t.time_of_day())
|
Chris@16
|
41 == boost::date_time::is_not_in_dst)
|
Chris@16
|
42 {
|
Chris@16
|
43
|
Chris@16
|
44 }
|
Chris@16
|
45
|
Chris@16
|
46 @endcode
|
Chris@16
|
47 This generates a type suitable for the calculation of dst
|
Chris@16
|
48 transitions for the United States. Of course other templates
|
Chris@16
|
49 can be used for other locales.
|
Chris@16
|
50
|
Chris@16
|
51 */
|
Chris@16
|
52
|
Chris@16
|
53 template<class date_type>
|
Chris@16
|
54 struct us_dst_trait
|
Chris@16
|
55 {
|
Chris@16
|
56 typedef typename date_type::day_of_week_type day_of_week_type;
|
Chris@16
|
57 typedef typename date_type::month_type month_type;
|
Chris@16
|
58 typedef typename date_type::year_type year_type;
|
Chris@16
|
59 typedef date_time::nth_kday_of_month<date_type> start_rule_functor;
|
Chris@16
|
60 typedef date_time::first_kday_of_month<date_type> end_rule_functor;
|
Chris@16
|
61 typedef date_time::first_kday_of_month<date_type> start_rule_functor_pre2007;
|
Chris@16
|
62 typedef date_time::last_kday_of_month<date_type> end_rule_functor_pre2007;
|
Chris@16
|
63 static day_of_week_type start_day(year_type) {return Sunday;}
|
Chris@16
|
64 static month_type start_month(year_type y)
|
Chris@16
|
65 {
|
Chris@16
|
66 if (y < 2007) return Apr;
|
Chris@16
|
67 return Mar;
|
Chris@16
|
68 }
|
Chris@16
|
69 static day_of_week_type end_day(year_type) {return Sunday;}
|
Chris@16
|
70 static month_type end_month(year_type y)
|
Chris@16
|
71 {
|
Chris@16
|
72 if (y < 2007) return Oct;
|
Chris@16
|
73 return Nov;
|
Chris@16
|
74 }
|
Chris@16
|
75 static date_type local_dst_start_day(year_type year)
|
Chris@16
|
76 {
|
Chris@16
|
77 if (year < 2007) {
|
Chris@16
|
78 start_rule_functor_pre2007 start1(start_day(year),
|
Chris@16
|
79 start_month(year));
|
Chris@16
|
80 return start1.get_date(year);
|
Chris@16
|
81 }
|
Chris@16
|
82 start_rule_functor start(start_rule_functor::second,
|
Chris@16
|
83 start_day(year),
|
Chris@16
|
84 start_month(year));
|
Chris@16
|
85 return start.get_date(year);
|
Chris@16
|
86
|
Chris@16
|
87 }
|
Chris@16
|
88 static date_type local_dst_end_day(year_type year)
|
Chris@16
|
89 {
|
Chris@16
|
90 if (year < 2007) {
|
Chris@16
|
91 end_rule_functor_pre2007 end_rule(end_day(year),
|
Chris@16
|
92 end_month(year));
|
Chris@16
|
93 return end_rule.get_date(year);
|
Chris@16
|
94 }
|
Chris@16
|
95 end_rule_functor end(end_day(year),
|
Chris@16
|
96 end_month(year));
|
Chris@16
|
97 return end.get_date(year);
|
Chris@16
|
98 }
|
Chris@16
|
99 static int dst_start_offset_minutes() { return 120;}
|
Chris@16
|
100 static int dst_end_offset_minutes() { return 120; }
|
Chris@16
|
101 static int dst_shift_length_minutes() { return 60; }
|
Chris@16
|
102 };
|
Chris@16
|
103
|
Chris@16
|
104 //!Rules for daylight savings start in the EU (Last Sun in Mar)
|
Chris@16
|
105 /*!These amount to the following:
|
Chris@16
|
106 - Start of dst day is last Sunday in March
|
Chris@16
|
107 - End day of dst is last Sunday in Oct
|
Chris@16
|
108 - Going forward switch time is 2:00 am (offset 120 minutes)
|
Chris@16
|
109 - Going back switch time is 3:00 am (off set 180 minutes)
|
Chris@16
|
110 - Shift duration is one hour (60 minutes)
|
Chris@16
|
111 */
|
Chris@16
|
112 template<class date_type>
|
Chris@16
|
113 struct eu_dst_trait
|
Chris@16
|
114 {
|
Chris@16
|
115 typedef typename date_type::day_of_week_type day_of_week_type;
|
Chris@16
|
116 typedef typename date_type::month_type month_type;
|
Chris@16
|
117 typedef typename date_type::year_type year_type;
|
Chris@16
|
118 typedef date_time::last_kday_of_month<date_type> start_rule_functor;
|
Chris@16
|
119 typedef date_time::last_kday_of_month<date_type> end_rule_functor;
|
Chris@16
|
120 static day_of_week_type start_day(year_type) {return Sunday;}
|
Chris@16
|
121 static month_type start_month(year_type) {return Mar;}
|
Chris@16
|
122 static day_of_week_type end_day(year_type) {return Sunday;}
|
Chris@16
|
123 static month_type end_month(year_type) {return Oct;}
|
Chris@16
|
124 static int dst_start_offset_minutes() { return 120;}
|
Chris@16
|
125 static int dst_end_offset_minutes() { return 180; }
|
Chris@16
|
126 static int dst_shift_length_minutes() { return 60; }
|
Chris@16
|
127 static date_type local_dst_start_day(year_type year)
|
Chris@16
|
128 {
|
Chris@16
|
129 start_rule_functor start(start_day(year),
|
Chris@16
|
130 start_month(year));
|
Chris@16
|
131 return start.get_date(year);
|
Chris@16
|
132 }
|
Chris@16
|
133 static date_type local_dst_end_day(year_type year)
|
Chris@16
|
134 {
|
Chris@16
|
135 end_rule_functor end(end_day(year),
|
Chris@16
|
136 end_month(year));
|
Chris@16
|
137 return end.get_date(year);
|
Chris@16
|
138 }
|
Chris@16
|
139 };
|
Chris@16
|
140
|
Chris@16
|
141 //! Alternative dst traits for some parts of the United Kingdom
|
Chris@16
|
142 /* Several places in the UK use EU start and end rules for the
|
Chris@16
|
143 day, but different local conversion times (eg: forward change at 1:00
|
Chris@16
|
144 am local and backward change at 2:00 am dst instead of 2:00am
|
Chris@16
|
145 forward and 3:00am back for the EU).
|
Chris@16
|
146 */
|
Chris@16
|
147 template<class date_type>
|
Chris@16
|
148 struct uk_dst_trait : public eu_dst_trait<date_type>
|
Chris@16
|
149 {
|
Chris@16
|
150 static int dst_start_offset_minutes() { return 60;}
|
Chris@16
|
151 static int dst_end_offset_minutes() { return 120; }
|
Chris@16
|
152 static int dst_shift_length_minutes() { return 60; }
|
Chris@16
|
153 };
|
Chris@16
|
154
|
Chris@16
|
155 //Rules for Adelaide Australia
|
Chris@16
|
156 template<class date_type>
|
Chris@16
|
157 struct acst_dst_trait
|
Chris@16
|
158 {
|
Chris@16
|
159 typedef typename date_type::day_of_week_type day_of_week_type;
|
Chris@16
|
160 typedef typename date_type::month_type month_type;
|
Chris@16
|
161 typedef typename date_type::year_type year_type;
|
Chris@16
|
162 typedef date_time::last_kday_of_month<date_type> start_rule_functor;
|
Chris@16
|
163 typedef date_time::last_kday_of_month<date_type> end_rule_functor;
|
Chris@16
|
164 static day_of_week_type start_day(year_type) {return Sunday;}
|
Chris@16
|
165 static month_type start_month(year_type) {return Oct;}
|
Chris@16
|
166 static day_of_week_type end_day(year_type) {return Sunday;}
|
Chris@16
|
167 static month_type end_month(year_type) {return Mar;}
|
Chris@16
|
168 static int dst_start_offset_minutes() { return 120;}
|
Chris@16
|
169 static int dst_end_offset_minutes() { return 180; }
|
Chris@16
|
170 static int dst_shift_length_minutes() { return 60; }
|
Chris@16
|
171 static date_type local_dst_start_day(year_type year)
|
Chris@16
|
172 {
|
Chris@16
|
173 start_rule_functor start(start_day(year),
|
Chris@16
|
174 start_month(year));
|
Chris@16
|
175 return start.get_date(year);
|
Chris@16
|
176 }
|
Chris@16
|
177 static date_type local_dst_end_day(year_type year)
|
Chris@16
|
178 {
|
Chris@16
|
179 end_rule_functor end(end_day(year),
|
Chris@16
|
180 end_month(year));
|
Chris@16
|
181 return end.get_date(year);
|
Chris@16
|
182 }
|
Chris@16
|
183 };
|
Chris@16
|
184
|
Chris@16
|
185
|
Chris@16
|
186
|
Chris@16
|
187
|
Chris@16
|
188
|
Chris@16
|
189
|
Chris@16
|
190 } } //namespace boost::date_time
|
Chris@16
|
191
|
Chris@16
|
192
|
Chris@16
|
193 #endif
|