Chris@16: #ifndef DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__ Chris@16: #define DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__ Chris@16: Chris@16: /* Copyright (c) 2002,2003 CrystalClear Software, Inc. Chris@16: * Use, modification and distribution is subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying Chris@16: * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Author: Jeff Garland Chris@101: * $Date$ Chris@16: */ Chris@16: Chris@16: #include "boost/date_time/dst_rules.hpp" Chris@16: Chris@16: namespace boost { Chris@16: namespace date_time { Chris@16: Chris@16: // Configurations for common dst rules cases: Chris@16: // See http://www.wharton.co.uk/Support/sup_dst.htm for more Chris@16: // information on how various locales use dst rules Chris@16: Chris@16: //! Specification for daylight savings start rules in US Chris@16: /*! This class is used to configure dst_calc_engine template typically Chris@16: as follows: Chris@16: @code Chris@16: using namespace boost::gregorian; Chris@16: using namespace boost::posix_time; Chris@16: typedef us_dst_trait us_dst_traits; Chris@16: typedef boost::date_time::dst_calc_engine Chris@16: us_dst_calc; Chris@16: //calculate the 2002 transition day of USA April 7 2002 Chris@16: date dst_start = us_dst_calc::local_dst_start_day(2002); Chris@16: Chris@16: //calculate the 2002 transition day of USA Oct 27 2002 Chris@16: date dst_end = us_dst_calc::local_dst_end_day(2002); Chris@16: Chris@16: //check if a local time is in dst or not -- posible answers Chris@16: //are yes, no, invalid time label, ambiguous Chris@16: ptime t(...some time...); Chris@16: if (us_dst::local_is_dst(t.date(), t.time_of_day()) Chris@16: == boost::date_time::is_not_in_dst) Chris@16: { Chris@16: Chris@16: } Chris@16: Chris@16: @endcode Chris@16: This generates a type suitable for the calculation of dst Chris@16: transitions for the United States. Of course other templates Chris@16: can be used for other locales. Chris@16: Chris@16: */ Chris@16: Chris@16: template Chris@16: struct us_dst_trait Chris@16: { Chris@16: typedef typename date_type::day_of_week_type day_of_week_type; Chris@16: typedef typename date_type::month_type month_type; Chris@16: typedef typename date_type::year_type year_type; Chris@16: typedef date_time::nth_kday_of_month start_rule_functor; Chris@16: typedef date_time::first_kday_of_month end_rule_functor; Chris@16: typedef date_time::first_kday_of_month start_rule_functor_pre2007; Chris@16: typedef date_time::last_kday_of_month end_rule_functor_pre2007; Chris@16: static day_of_week_type start_day(year_type) {return Sunday;} Chris@16: static month_type start_month(year_type y) Chris@16: { Chris@16: if (y < 2007) return Apr; Chris@16: return Mar; Chris@16: } Chris@16: static day_of_week_type end_day(year_type) {return Sunday;} Chris@16: static month_type end_month(year_type y) Chris@16: { Chris@16: if (y < 2007) return Oct; Chris@16: return Nov; Chris@16: } Chris@16: static date_type local_dst_start_day(year_type year) Chris@16: { Chris@16: if (year < 2007) { Chris@16: start_rule_functor_pre2007 start1(start_day(year), Chris@16: start_month(year)); Chris@16: return start1.get_date(year); Chris@16: } Chris@16: start_rule_functor start(start_rule_functor::second, Chris@16: start_day(year), Chris@16: start_month(year)); Chris@16: return start.get_date(year); Chris@16: Chris@16: } Chris@16: static date_type local_dst_end_day(year_type year) Chris@16: { Chris@16: if (year < 2007) { Chris@16: end_rule_functor_pre2007 end_rule(end_day(year), Chris@16: end_month(year)); Chris@16: return end_rule.get_date(year); Chris@16: } Chris@16: end_rule_functor end(end_day(year), Chris@16: end_month(year)); Chris@16: return end.get_date(year); Chris@16: } Chris@16: static int dst_start_offset_minutes() { return 120;} Chris@16: static int dst_end_offset_minutes() { return 120; } Chris@16: static int dst_shift_length_minutes() { return 60; } Chris@16: }; Chris@16: Chris@16: //!Rules for daylight savings start in the EU (Last Sun in Mar) Chris@16: /*!These amount to the following: Chris@16: - Start of dst day is last Sunday in March Chris@16: - End day of dst is last Sunday in Oct Chris@16: - Going forward switch time is 2:00 am (offset 120 minutes) Chris@16: - Going back switch time is 3:00 am (off set 180 minutes) Chris@16: - Shift duration is one hour (60 minutes) Chris@16: */ Chris@16: template Chris@16: struct eu_dst_trait Chris@16: { Chris@16: typedef typename date_type::day_of_week_type day_of_week_type; Chris@16: typedef typename date_type::month_type month_type; Chris@16: typedef typename date_type::year_type year_type; Chris@16: typedef date_time::last_kday_of_month start_rule_functor; Chris@16: typedef date_time::last_kday_of_month end_rule_functor; Chris@16: static day_of_week_type start_day(year_type) {return Sunday;} Chris@16: static month_type start_month(year_type) {return Mar;} Chris@16: static day_of_week_type end_day(year_type) {return Sunday;} Chris@16: static month_type end_month(year_type) {return Oct;} Chris@16: static int dst_start_offset_minutes() { return 120;} Chris@16: static int dst_end_offset_minutes() { return 180; } Chris@16: static int dst_shift_length_minutes() { return 60; } Chris@16: static date_type local_dst_start_day(year_type year) Chris@16: { Chris@16: start_rule_functor start(start_day(year), Chris@16: start_month(year)); Chris@16: return start.get_date(year); Chris@16: } Chris@16: static date_type local_dst_end_day(year_type year) Chris@16: { Chris@16: end_rule_functor end(end_day(year), Chris@16: end_month(year)); Chris@16: return end.get_date(year); Chris@16: } Chris@16: }; Chris@16: Chris@16: //! Alternative dst traits for some parts of the United Kingdom Chris@16: /* Several places in the UK use EU start and end rules for the Chris@16: day, but different local conversion times (eg: forward change at 1:00 Chris@16: am local and backward change at 2:00 am dst instead of 2:00am Chris@16: forward and 3:00am back for the EU). Chris@16: */ Chris@16: template Chris@16: struct uk_dst_trait : public eu_dst_trait Chris@16: { Chris@16: static int dst_start_offset_minutes() { return 60;} Chris@16: static int dst_end_offset_minutes() { return 120; } Chris@16: static int dst_shift_length_minutes() { return 60; } Chris@16: }; Chris@16: Chris@16: //Rules for Adelaide Australia Chris@16: template Chris@16: struct acst_dst_trait Chris@16: { Chris@16: typedef typename date_type::day_of_week_type day_of_week_type; Chris@16: typedef typename date_type::month_type month_type; Chris@16: typedef typename date_type::year_type year_type; Chris@16: typedef date_time::last_kday_of_month start_rule_functor; Chris@16: typedef date_time::last_kday_of_month end_rule_functor; Chris@16: static day_of_week_type start_day(year_type) {return Sunday;} Chris@16: static month_type start_month(year_type) {return Oct;} Chris@16: static day_of_week_type end_day(year_type) {return Sunday;} Chris@16: static month_type end_month(year_type) {return Mar;} Chris@16: static int dst_start_offset_minutes() { return 120;} Chris@16: static int dst_end_offset_minutes() { return 180; } Chris@16: static int dst_shift_length_minutes() { return 60; } Chris@16: static date_type local_dst_start_day(year_type year) Chris@16: { Chris@16: start_rule_functor start(start_day(year), Chris@16: start_month(year)); Chris@16: return start.get_date(year); Chris@16: } Chris@16: static date_type local_dst_end_day(year_type year) Chris@16: { Chris@16: end_rule_functor end(end_day(year), Chris@16: end_month(year)); Chris@16: return end.get_date(year); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: } } //namespace boost::date_time Chris@16: Chris@16: Chris@16: #endif