Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:38

0001 #ifndef DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__
0002 #define DATE_TIME_LOCAL_TIMEZONE_DEFS_HPP__
0003 
0004 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland 
0009  * $Date$
0010  */
0011 
0012 #include "boost/date_time/dst_rules.hpp"
0013 
0014 namespace boost {
0015   namespace date_time {
0016 
0017     // Configurations for common dst rules cases:
0018     // See http://www.wharton.co.uk/Support/sup_dst.htm for more
0019     // information on how various locales use dst rules
0020 
0021     //! Specification for daylight savings start rules in US
0022     /*! This class is used to configure dst_calc_engine template typically
0023         as follows:
0024         @code
0025           using namespace boost::gregorian;
0026           using namespace boost::posix_time;
0027           typedef us_dst_trait<date> us_dst_traits;
0028           typedef boost::date_time::dst_calc_engine<date, time_duration, 
0029                                                     us_dst_traits>  
0030                                                     us_dst_calc;
0031           //calculate the 2002 transition day of USA April 7 2002
0032           date dst_start = us_dst_calc::local_dst_start_day(2002); 
0033 
0034           //calculate the 2002 transition day of USA Oct 27 2002
0035           date dst_end = us_dst_calc::local_dst_end_day(2002); 
0036                                                     
0037           //check if a local time is in dst or not -- posible answers
0038           //are yes, no, invalid time label, ambiguous
0039           ptime t(...some time...);  
0040           if (us_dst::local_is_dst(t.date(), t.time_of_day()) 
0041               == boost::date_time::is_not_in_dst) 
0042           {
0043 
0044           }
0045 
0046         @endcode
0047         This generates a type suitable for the calculation of dst 
0048         transitions for the United States.  Of course other templates
0049         can be used for other locales.
0050 
0051     */
0052 
0053      template<class date_type>
0054      struct us_dst_trait
0055      {
0056        typedef typename date_type::day_of_week_type day_of_week_type;
0057        typedef typename date_type::month_type month_type;
0058        typedef typename date_type::year_type year_type;
0059        typedef date_time::nth_kday_of_month<date_type> start_rule_functor;
0060        typedef date_time::first_kday_of_month<date_type> end_rule_functor;
0061        typedef date_time::first_kday_of_month<date_type> start_rule_functor_pre2007;
0062        typedef date_time::last_kday_of_month<date_type> end_rule_functor_pre2007;
0063        static day_of_week_type start_day(year_type) {return Sunday;}
0064        static month_type start_month(year_type y) 
0065        {
0066          if (y < 2007) return Apr;
0067          return Mar;
0068        }
0069        static day_of_week_type end_day(year_type) {return Sunday;}
0070        static month_type end_month(year_type y) 
0071        {
0072          if (y < 2007) return Oct;
0073          return Nov;
0074        }
0075        static date_type local_dst_start_day(year_type year)
0076        {
0077          if (year < 2007) {
0078            start_rule_functor_pre2007 start1(start_day(year), 
0079                                              start_month(year));
0080            return start1.get_date(year);
0081          }
0082          start_rule_functor start(start_rule_functor::second,
0083                                   start_day(year), 
0084                                   start_month(year));
0085          return start.get_date(year);
0086           
0087        }
0088        static date_type local_dst_end_day(year_type year)
0089        {
0090          if (year < 2007) {
0091            end_rule_functor_pre2007 end_rule(end_day(year), 
0092                                              end_month(year));
0093            return end_rule.get_date(year);
0094          }
0095          end_rule_functor end(end_day(year), 
0096                               end_month(year));
0097          return end.get_date(year);      
0098        }
0099        static int dst_start_offset_minutes() { return 120;}
0100        static int dst_end_offset_minutes() { return 120; }
0101        static int dst_shift_length_minutes() { return 60; }
0102      };
0103 
0104     //!Rules for daylight savings start in the EU (Last Sun in Mar)
0105     /*!These amount to the following:
0106       - Start of dst day is last Sunday in March
0107       - End day of dst is last Sunday in Oct
0108       - Going forward switch time is 2:00 am (offset 120 minutes)
0109       - Going back switch time is 3:00 am (off set 180 minutes)
0110       - Shift duration is one hour (60 minutes)
0111     */
0112     template<class date_type>
0113     struct eu_dst_trait
0114     {
0115       typedef typename date_type::day_of_week_type day_of_week_type;
0116       typedef typename date_type::month_type month_type;
0117       typedef typename date_type::year_type year_type;
0118       typedef date_time::last_kday_of_month<date_type> start_rule_functor;
0119       typedef date_time::last_kday_of_month<date_type> end_rule_functor;
0120       static day_of_week_type start_day(year_type) {return Sunday;}
0121       static month_type start_month(year_type) {return Mar;}
0122       static day_of_week_type end_day(year_type) {return Sunday;}
0123       static month_type end_month(year_type) {return Oct;}
0124       static int dst_start_offset_minutes() { return 120;}
0125       static int dst_end_offset_minutes() { return 180; }
0126       static int dst_shift_length_minutes() { return 60; }
0127       static date_type local_dst_start_day(year_type year)
0128       {
0129         start_rule_functor start(start_day(year), 
0130                                  start_month(year));
0131         return start.get_date(year);      
0132       }
0133       static date_type local_dst_end_day(year_type year)
0134       {
0135         end_rule_functor end(end_day(year), 
0136                              end_month(year));
0137         return end.get_date(year);      
0138       }
0139     };
0140 
0141     //! Alternative dst traits for some parts of the United Kingdom
0142     /* Several places in the UK use EU start and end rules for the 
0143        day, but different local conversion times (eg: forward change at 1:00 
0144        am local and  backward change at 2:00 am dst instead of 2:00am 
0145        forward and 3:00am back for the EU).
0146     */
0147     template<class date_type>
0148     struct uk_dst_trait : public eu_dst_trait<date_type>
0149     {
0150       static int dst_start_offset_minutes() { return 60;}
0151       static int dst_end_offset_minutes() { return 120; }
0152       static int dst_shift_length_minutes() { return 60; }
0153     };
0154 
0155     //Rules for Adelaide Australia
0156     template<class date_type>
0157     struct acst_dst_trait
0158     {
0159       typedef typename date_type::day_of_week_type day_of_week_type;
0160       typedef typename date_type::month_type month_type;
0161       typedef typename date_type::year_type year_type;
0162       typedef date_time::last_kday_of_month<date_type> start_rule_functor;
0163       typedef date_time::last_kday_of_month<date_type> end_rule_functor;
0164       static day_of_week_type start_day(year_type) {return Sunday;}
0165       static month_type start_month(year_type) {return Oct;}
0166       static day_of_week_type end_day(year_type) {return Sunday;}
0167       static month_type end_month(year_type) {return Mar;}
0168       static int dst_start_offset_minutes() { return 120;}
0169       static int dst_end_offset_minutes() { return 180; }
0170       static int dst_shift_length_minutes() { return 60; }
0171       static date_type local_dst_start_day(year_type year)
0172       {
0173         start_rule_functor start(start_day(year), 
0174                                  start_month(year));
0175         return start.get_date(year);      
0176       }
0177       static date_type local_dst_end_day(year_type year)
0178       {
0179         end_rule_functor end(end_day(year), 
0180                              end_month(year));
0181         return end.get_date(year);      
0182       }
0183     };
0184     
0185     
0186 
0187 
0188 
0189 
0190 } } //namespace boost::date_time
0191 
0192 
0193 #endif