1 #ifndef DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__
2 #define DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__
4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
12 #include "boost/date_time/dst_rules.hpp"
17 // Configurations for common dst rules cases:
18 // See http://www.wharton.co.uk/Support/sup_dst.htm for more
19 // information on how various locales use dst rules
21 //! Specification for daylight savings start rules in US
22 /*! This class is used to configure dst_calc_engine template typically
25 using namespace boost::gregorian;
26 using namespace boost::posix_time;
27 typedef us_dst_trait<date> us_dst_traits;
28 typedef boost::date_time::dst_calc_engine<date, time_duration,
31 //calculate the 2002 transition day of USA April 7 2002
32 date dst_start = us_dst_calc::local_dst_start_day(2002);
34 //calculate the 2002 transition day of USA Oct 27 2002
35 date dst_end = us_dst_calc::local_dst_end_day(2002);
37 //check if a local time is in dst or not -- posible answers
38 //are yes, no, invalid time label, ambiguous
39 ptime t(...some time...);
40 if (us_dst::local_is_dst(t.date(), t.time_of_day())
41 == boost::date_time::is_not_in_dst)
47 This generates a type suitable for the calculation of dst
48 transitions for the United States. Of course other templates
49 can be used for other locales.
53 template<class date_type
>
56 typedef typename
date_type::day_of_week_type day_of_week_type
;
57 typedef typename
date_type::month_type month_type
;
58 typedef typename
date_type::year_type year_type
;
59 typedef date_time::nth_kday_of_month
<date_type
> start_rule_functor
;
60 typedef date_time::first_kday_of_month
<date_type
> end_rule_functor
;
61 typedef date_time::first_kday_of_month
<date_type
> start_rule_functor_pre2007
;
62 typedef date_time::last_kday_of_month
<date_type
> end_rule_functor_pre2007
;
63 static day_of_week_type
start_day(year_type
) {return Sunday
;}
64 static month_type
start_month(year_type y
)
66 if (y
< 2007) return Apr
;
69 static day_of_week_type
end_day(year_type
) {return Sunday
;}
70 static month_type
end_month(year_type y
)
72 if (y
< 2007) return Oct
;
75 static date_type
local_dst_start_day(year_type year
)
78 start_rule_functor_pre2007
start1(start_day(year
),
80 return start1
.get_date(year
);
82 start_rule_functor
start(start_rule_functor::second
,
85 return start
.get_date(year
);
88 static date_type
local_dst_end_day(year_type year
)
91 end_rule_functor_pre2007
end_rule(end_day(year
),
93 return end_rule
.get_date(year
);
95 end_rule_functor
end(end_day(year
),
97 return end
.get_date(year
);
99 static int dst_start_offset_minutes() { return 120;}
100 static int dst_end_offset_minutes() { return 120; }
101 static int dst_shift_length_minutes() { return 60; }
104 //!Rules for daylight savings start in the EU (Last Sun in Mar)
105 /*!These amount to the following:
106 - Start of dst day is last Sunday in March
107 - End day of dst is last Sunday in Oct
108 - Going forward switch time is 2:00 am (offset 120 minutes)
109 - Going back switch time is 3:00 am (off set 180 minutes)
110 - Shift duration is one hour (60 minutes)
112 template<class date_type
>
115 typedef typename
date_type::day_of_week_type day_of_week_type
;
116 typedef typename
date_type::month_type month_type
;
117 typedef typename
date_type::year_type year_type
;
118 typedef date_time::last_kday_of_month
<date_type
> start_rule_functor
;
119 typedef date_time::last_kday_of_month
<date_type
> end_rule_functor
;
120 static day_of_week_type
start_day(year_type
) {return Sunday
;}
121 static month_type
start_month(year_type
) {return Mar
;}
122 static day_of_week_type
end_day(year_type
) {return Sunday
;}
123 static month_type
end_month(year_type
) {return Oct
;}
124 static int dst_start_offset_minutes() { return 120;}
125 static int dst_end_offset_minutes() { return 180; }
126 static int dst_shift_length_minutes() { return 60; }
127 static date_type
local_dst_start_day(year_type year
)
129 start_rule_functor
start(start_day(year
),
131 return start
.get_date(year
);
133 static date_type
local_dst_end_day(year_type year
)
135 end_rule_functor
end(end_day(year
),
137 return end
.get_date(year
);
141 //! Alternative dst traits for some parts of the United Kingdom
142 /* Several places in the UK use EU start and end rules for the
143 day, but different local conversion times (eg: forward change at 1:00
144 am local and backward change at 2:00 am dst instead of 2:00am
145 forward and 3:00am back for the EU).
147 template<class date_type
>
148 struct uk_dst_trait
: public eu_dst_trait
<date_type
>
150 static int dst_start_offset_minutes() { return 60;}
151 static int dst_end_offset_minutes() { return 120; }
152 static int dst_shift_length_minutes() { return 60; }
155 //Rules for Adelaide Australia
156 template<class date_type
>
157 struct acst_dst_trait
159 typedef typename
date_type::day_of_week_type day_of_week_type
;
160 typedef typename
date_type::month_type month_type
;
161 typedef typename
date_type::year_type year_type
;
162 typedef date_time::last_kday_of_month
<date_type
> start_rule_functor
;
163 typedef date_time::last_kday_of_month
<date_type
> end_rule_functor
;
164 static day_of_week_type
start_day(year_type
) {return Sunday
;}
165 static month_type
start_month(year_type
) {return Oct
;}
166 static day_of_week_type
end_day(year_type
) {return Sunday
;}
167 static month_type
end_month(year_type
) {return Mar
;}
168 static int dst_start_offset_minutes() { return 120;}
169 static int dst_end_offset_minutes() { return 180; }
170 static int dst_shift_length_minutes() { return 60; }
171 static date_type
local_dst_start_day(year_type year
)
173 start_rule_functor
start(start_day(year
),
175 return start
.get_date(year
);
177 static date_type
local_dst_end_day(year_type year
)
179 end_rule_functor
end(end_day(year
),
181 return end
.get_date(year
);
190 } } //namespace boost::date_time