| 1 | #ifndef DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__ | 
|---|
| 2 | #define DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__ | 
|---|
| 3 |  | 
|---|
| 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 or http://www.boost.org/LICENSE-1.0) | 
|---|
| 8 | * Author: Jeff Garland | 
|---|
| 9 | * $Date: 2007/03/02 05:16:59 $ | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 | #include "boost/date_time/dst_rules.hpp" | 
|---|
| 13 |  | 
|---|
| 14 | namespace boost { | 
|---|
| 15 | namespace date_time { | 
|---|
| 16 |  | 
|---|
| 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 | 
|---|
| 20 |  | 
|---|
| 21 | //! Specification for daylight savings start rules in US | 
|---|
| 22 | /*! This class is used to configure dst_calc_engine template typically | 
|---|
| 23 | as follows: | 
|---|
| 24 | @code | 
|---|
| 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, | 
|---|
| 29 | us_dst_traits> | 
|---|
| 30 | us_dst_calc; | 
|---|
| 31 | //calculate the 2002 transition day of USA April 7 2002 | 
|---|
| 32 | date dst_start = us_dst_calc::local_dst_start_day(2002); | 
|---|
| 33 |  | 
|---|
| 34 | //calculate the 2002 transition day of USA Oct 27 2002 | 
|---|
| 35 | date dst_end = us_dst_calc::local_dst_end_day(2002); | 
|---|
| 36 |  | 
|---|
| 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) | 
|---|
| 42 | { | 
|---|
| 43 |  | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | @endcode | 
|---|
| 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. | 
|---|
| 50 |  | 
|---|
| 51 | */ | 
|---|
| 52 |  | 
|---|
| 53 | template<class date_type> | 
|---|
| 54 | struct us_dst_trait | 
|---|
| 55 | { | 
|---|
| 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) | 
|---|
| 65 | { | 
|---|
| 66 | if (y < 2007) return Apr; | 
|---|
| 67 | return Mar; | 
|---|
| 68 | } | 
|---|
| 69 | static day_of_week_type end_day(year_type y) {return Sunday;} | 
|---|
| 70 | static month_type end_month(year_type y) | 
|---|
| 71 | { | 
|---|
| 72 | if (y < 2007) return Oct; | 
|---|
| 73 | return Nov; | 
|---|
| 74 | } | 
|---|
| 75 | static date_type local_dst_start_day(year_type year) | 
|---|
| 76 | { | 
|---|
| 77 | if (year < 2007) { | 
|---|
| 78 | start_rule_functor_pre2007 start1(start_day(year), | 
|---|
| 79 | start_month(year)); | 
|---|
| 80 | return start1.get_date(year); | 
|---|
| 81 | } | 
|---|
| 82 | start_rule_functor start(start_rule_functor::second, | 
|---|
| 83 | start_day(year), | 
|---|
| 84 | start_month(year)); | 
|---|
| 85 | return start.get_date(year); | 
|---|
| 86 |  | 
|---|
| 87 | } | 
|---|
| 88 | static date_type local_dst_end_day(year_type year) | 
|---|
| 89 | { | 
|---|
| 90 | if (year < 2007) { | 
|---|
| 91 | end_rule_functor_pre2007 end_rule(end_day(year), | 
|---|
| 92 | end_month(year)); | 
|---|
| 93 | return end_rule.get_date(year); | 
|---|
| 94 | } | 
|---|
| 95 | end_rule_functor end(end_day(year), | 
|---|
| 96 | end_month(year)); | 
|---|
| 97 | return end.get_date(year); | 
|---|
| 98 | } | 
|---|
| 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; } | 
|---|
| 102 | }; | 
|---|
| 103 |  | 
|---|
| 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) | 
|---|
| 111 | */ | 
|---|
| 112 | template<class date_type> | 
|---|
| 113 | struct eu_dst_trait | 
|---|
| 114 | { | 
|---|
| 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) | 
|---|
| 128 | { | 
|---|
| 129 | start_rule_functor start(start_day(year), | 
|---|
| 130 | start_month(year)); | 
|---|
| 131 | return start.get_date(year); | 
|---|
| 132 | } | 
|---|
| 133 | static date_type local_dst_end_day(year_type year) | 
|---|
| 134 | { | 
|---|
| 135 | end_rule_functor end(end_day(year), | 
|---|
| 136 | end_month(year)); | 
|---|
| 137 | return end.get_date(year); | 
|---|
| 138 | } | 
|---|
| 139 | }; | 
|---|
| 140 |  | 
|---|
| 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). | 
|---|
| 146 | */ | 
|---|
| 147 | template<class date_type> | 
|---|
| 148 | struct uk_dst_trait : public eu_dst_trait<date_type> | 
|---|
| 149 | { | 
|---|
| 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; } | 
|---|
| 153 | }; | 
|---|
| 154 |  | 
|---|
| 155 | //Rules for Adelaide Australia | 
|---|
| 156 | template<class date_type> | 
|---|
| 157 | struct acst_dst_trait | 
|---|
| 158 | { | 
|---|
| 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) | 
|---|
| 172 | { | 
|---|
| 173 | start_rule_functor start(start_day(year), | 
|---|
| 174 | start_month(year)); | 
|---|
| 175 | return start.get_date(year); | 
|---|
| 176 | } | 
|---|
| 177 | static date_type local_dst_end_day(year_type year) | 
|---|
| 178 | { | 
|---|
| 179 | end_rule_functor end(end_day(year), | 
|---|
| 180 | end_month(year)); | 
|---|
| 181 | return end.get_date(year); | 
|---|
| 182 | } | 
|---|
| 183 | }; | 
|---|
| 184 |  | 
|---|
| 185 |  | 
|---|
| 186 |  | 
|---|
| 187 |  | 
|---|
| 188 |  | 
|---|
| 189 |  | 
|---|
| 190 | } } //namespace boost::date_time | 
|---|
| 191 |  | 
|---|
| 192 |  | 
|---|
| 193 | #endif | 
|---|