source: NonGTP/Boost/boost/date_time/local_timezone_defs.hpp @ 857

Revision 857, 5.3 KB checked in by igarcia, 19 years ago (diff)
Line 
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: 2003/11/23 03:29:56 $
10 */
11
12#include "boost/date_time/dst_rules.hpp"
13
14namespace 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 date_time::first_kday_of_month<date_type> start_rule_functor;
59       typedef date_time::last_kday_of_month<date_type> end_rule_functor;
60       static day_of_week_type start_day() {return Sunday;}
61       static month_type start_month() {return Apr;}
62       static day_of_week_type end_day() {return Sunday;}
63       static month_type end_month() {return Oct;}
64       static int dst_start_offset_minutes() { return 120;}
65       static int dst_end_offset_minutes() { return 120; }
66       static int dst_shift_length_minutes() { return 60; }
67     };
68
69    //!Rules for daylight savings start in the EU (Last Sun in Mar)
70    /*!These amount to the following:
71      - Start of dst day is last Sunday in March
72      - End day of dst is last Sunday in Oct
73      - Going forward switch time is 2:00 am (offset 120 minutes)
74      - Going back switch time is 3:00 am (off set 180 minutes)
75      - Shift duration is one hour (60 minutes)
76    */
77    template<class date_type>
78    struct eu_dst_trait
79    {
80      typedef typename date_type::day_of_week_type day_of_week_type;
81      typedef typename date_type::month_type month_type;
82      typedef date_time::last_kday_of_month<date_type> start_rule_functor;
83      typedef date_time::last_kday_of_month<date_type> end_rule_functor;
84      static day_of_week_type start_day() {return Sunday;}
85      static month_type start_month() {return Mar;}
86      static day_of_week_type end_day() {return Sunday;}
87      static month_type end_month() {return Oct;}
88      static int dst_start_offset_minutes() { return 120;}
89      static int dst_end_offset_minutes() { return 180; }
90      static int dst_shift_length_minutes() { return 60; }
91    };
92
93    //! Alternative dst traits for some parts of the United Kingdom
94    /* Several places in the UK use EU start and end rules for the
95       day, but different local conversion times (eg: forward change at 1:00
96       am local and  backward change at 2:00 am dst instead of 2:00am
97       forward and 3:00am back for the EU).
98    */
99    template<class date_type>
100    struct uk_dst_trait : public eu_dst_trait<date_type>
101    {
102      static int dst_start_offset_minutes() { return 60;}
103      static int dst_end_offset_minutes() { return 120; }
104      static int dst_shift_length_minutes() { return 60; }
105    };
106
107    //Rules for Adelaide Australia
108    template<class date_type>
109    struct acst_dst_trait
110    {
111      typedef typename date_type::day_of_week_type day_of_week_type;
112      typedef typename date_type::month_type month_type;
113      typedef date_time::last_kday_of_month<date_type> start_rule_functor;
114      typedef date_time::last_kday_of_month<date_type> end_rule_functor;
115      static day_of_week_type start_day() {return Sunday;}
116      static month_type start_month() {return Oct;}
117      static day_of_week_type end_day() {return Sunday;}
118      static month_type end_month() {return Mar;}
119      static int dst_start_offset_minutes() { return 120;}
120      static int dst_end_offset_minutes() { return 120; }
121      static int dst_shift_length_minutes() { return 60; }
122    };
123   
124   
125
126
127
128
129} } //namespace boost::date_time
130
131
132#endif
Note: See TracBrowser for help on using the repository browser.