Update of /cvsroot/boost/boost/boost/date_time
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19896/boost/date_time

Modified Files:
      Tag: RC_1_34_0
        local_timezone_defs.hpp dst_rules.hpp 
Log Message:
Changes to fix the compile-time dst rules engines for 2007 US and Canada dst 
changes

Index: local_timezone_defs.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/date_time/local_timezone_defs.hpp,v
retrieving revision 1.2
retrieving revision 1.2.16.1
diff -u -d -r1.2 -r1.2.16.1
--- local_timezone_defs.hpp     23 Nov 2003 03:29:56 -0000      1.2
+++ local_timezone_defs.hpp     2 Mar 2007 01:54:49 -0000       1.2.16.1
@@ -55,12 +55,47 @@
      {
        typedef typename date_type::day_of_week_type day_of_week_type;
        typedef typename date_type::month_type month_type;
-       typedef date_time::first_kday_of_month<date_type> start_rule_functor;
-       typedef date_time::last_kday_of_month<date_type> end_rule_functor;
-       static day_of_week_type start_day() {return Sunday;}
-       static month_type start_month() {return Apr;}
-       static day_of_week_type end_day() {return Sunday;}
-       static month_type end_month() {return Oct;}
+       typedef typename date_type::year_type year_type;
+       typedef date_time::nth_kday_of_month<date_type> start_rule_functor;
+       typedef date_time::first_kday_of_month<date_type> end_rule_functor;
+       typedef date_time::first_kday_of_month<date_type> 
start_rule_functor_pre2007;
+       typedef date_time::last_kday_of_month<date_type> 
end_rule_functor_pre2007;
+       static day_of_week_type start_day(year_type) {return Sunday;}
+       static month_type start_month(year_type y) 
+       {
+         if (y < 2007) return Apr;
+         return Mar;
+       }
+       static day_of_week_type end_day(year_type y) {return Sunday;}
+       static month_type end_month(year_type y) 
+       {
+         if (y < 2007) return Oct;
+         return Nov;
+       }
+       static date_type local_dst_start_day(year_type year)
+       {
+         if (year < 2007) {
+           start_rule_functor_pre2007 start1(start_day(year), 
+                                             start_month(year));
+           return start1.get_date(year);
+         }
+         start_rule_functor start(start_rule_functor::second,
+                                  start_day(year), 
+                                  start_month(year));
+         return start.get_date(year);
+          
+       }
+       static date_type local_dst_end_day(year_type year)
+       {
+         if (year < 2007) {
+           end_rule_functor_pre2007 end_rule(end_day(year), 
+                                             end_month(year));
+           return end_rule.get_date(year);
+         }
+         end_rule_functor end(end_day(year), 
+                              end_month(year));
+         return end.get_date(year);      
+       }
        static int dst_start_offset_minutes() { return 120;}
        static int dst_end_offset_minutes() { return 120; }
        static int dst_shift_length_minutes() { return 60; }
@@ -79,15 +114,28 @@
     {
       typedef typename date_type::day_of_week_type day_of_week_type;
       typedef typename date_type::month_type month_type;
+      typedef typename date_type::year_type year_type;
       typedef date_time::last_kday_of_month<date_type> start_rule_functor;
       typedef date_time::last_kday_of_month<date_type> end_rule_functor;
-      static day_of_week_type start_day() {return Sunday;}
-      static month_type start_month() {return Mar;}
-      static day_of_week_type end_day() {return Sunday;}
-      static month_type end_month() {return Oct;}
+      static day_of_week_type start_day(year_type) {return Sunday;}
+      static month_type start_month(year_type) {return Mar;}
+      static day_of_week_type end_day(year_type) {return Sunday;}
+      static month_type end_month(year_type) {return Oct;}
       static int dst_start_offset_minutes() { return 120;}
       static int dst_end_offset_minutes() { return 180; }
       static int dst_shift_length_minutes() { return 60; }
+      static date_type local_dst_start_day(year_type year)
+      {
+        start_rule_functor start(start_day(year), 
+                                 start_month(year));
+        return start.get_date(year);      
+      }
+      static date_type local_dst_end_day(year_type year)
+      {
+        end_rule_functor end(end_day(year), 
+                             end_month(year));
+        return end.get_date(year);      
+      }
     };
 
     //! Alternative dst traits for some parts of the United Kingdom
@@ -110,15 +158,28 @@
     {
       typedef typename date_type::day_of_week_type day_of_week_type;
       typedef typename date_type::month_type month_type;
+      typedef typename date_type::year_type year_type;
       typedef date_time::last_kday_of_month<date_type> start_rule_functor;
       typedef date_time::last_kday_of_month<date_type> end_rule_functor;
-      static day_of_week_type start_day() {return Sunday;}
-      static month_type start_month() {return Oct;}
-      static day_of_week_type end_day() {return Sunday;}
-      static month_type end_month() {return Mar;}
+      static day_of_week_type start_day(year_type) {return Sunday;}
+      static month_type start_month(year_type) {return Oct;}
+      static day_of_week_type end_day(year_type) {return Sunday;}
+      static month_type end_month(year_type) {return Mar;}
       static int dst_start_offset_minutes() { return 120;}
       static int dst_end_offset_minutes() { return 120; }
       static int dst_shift_length_minutes() { return 60; }
+      static date_type local_dst_start_day(year_type year)
+      {
+        start_rule_functor start(start_day(year), 
+                                 start_month(year));
+        return start.get_date(year);      
+      }
+      static date_type local_dst_end_day(year_type year)
+      {
+        end_rule_functor end(end_day(year), 
+                             end_month(year));
+        return end.get_date(year);      
+      }
     };
     
     

Index: dst_rules.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/date_time/dst_rules.hpp,v
retrieving revision 1.5
retrieving revision 1.5.10.1
diff -u -d -r1.5 -r1.5.10.1
--- dst_rules.hpp       2 Oct 2004 18:49:16 -0000       1.5
+++ dst_rules.hpp       2 Mar 2007 01:54:49 -0000       1.5.10.1
@@ -1,7 +1,7 @@
 #ifndef DATE_TIME_DST_RULES_HPP__
 #define DATE_TIME_DST_RULES_HPP__
 
-/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
+/* Copyright (c) 2002,2003, 2007 CrystalClear Software, Inc.
  * Use, modification and distribution is subject to the 
  * Boost Software License, Version 1.0. (See accompanying
  * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
@@ -251,18 +251,12 @@
 
       static date_type local_dst_start_day(year_type year)
       {
-        typedef typename dst_traits::start_rule_functor start_rule;
-        start_rule start(dst_traits::start_day(), 
-                         dst_traits::start_month());
-        return start.get_date(year);      
+        return dst_traits::local_dst_start_day(year);      
       }
 
       static date_type local_dst_end_day(year_type year)
       {
-        typedef typename dst_traits::end_rule_functor end_rule;
-        end_rule end(dst_traits::end_day(), 
-                     dst_traits::end_month());
-        return end.get_date(year);      
+        return dst_traits::local_dst_end_day(year);
       }
 
 
@@ -270,6 +264,8 @@
 
     //! Depricated: Class to calculate dst boundaries for US time zones
     /* Use dst_calc_engine instead.
+     * In 2007 US/Canada DST rules changed
+     * 
(http://en.wikipedia.org/wiki/Energy_Policy_Act_of_2005#Change_to_daylight_saving_time).
      */
     template<class date_type_, 
              class time_duration_type_,
@@ -284,6 +280,7 @@
       typedef typename date_type::calendar_type calendar_type;
       typedef date_time::last_kday_of_month<date_type> lkday;
       typedef date_time::first_kday_of_month<date_type> fkday;
+      typedef date_time::nth_kday_of_month<date_type> nkday;
       typedef dst_calculator<date_type, time_duration_type> dstcalc;
 
       //! Calculates if the given local time is dst or not
@@ -315,16 +312,28 @@
 
       static date_type local_dst_start_day(year_type year)
       {
-        //first sunday in april
-        fkday fsia(Sunday, gregorian::Apr);
-        return fsia.get_date(year);      
+        if (year >= year_type(2007)) {
+          //second sunday in march
+          nkday ssim(nkday::second, Sunday, gregorian::Mar);
+          return ssim.get_date(year);      
+        } else {
+          //first sunday in april
+          fkday fsia(Sunday, gregorian::Apr);
+          return fsia.get_date(year);      
+        }
       }
 
       static date_type local_dst_end_day(year_type year)
       {
-        //last sunday in october
-        lkday lsio(Sunday, gregorian::Oct);
-        return lsio.get_date(year);
+        if (year >= year_type(2007)) {
+          //first sunday in november
+          fkday fsin(Sunday, gregorian::Nov);
+          return fsin.get_date(year);      
+        } else {
+          //last sunday in october
+          lkday lsio(Sunday, gregorian::Oct);
+          return lsio.get_date(year);
+        }
       }
 
       static time_duration_type dst_offset()
@@ -332,6 +341,8 @@
         return time_duration_type(0,dst_length_minutes,0);
       }
 
+     private:
+
 
     };
 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to