Chris@16
|
1 #ifndef _DATE_TIME_TIME_ZONE_BASE__
|
Chris@16
|
2 #define _DATE_TIME_TIME_ZONE_BASE__
|
Chris@16
|
3
|
Chris@16
|
4 /* Copyright (c) 2003-2005 CrystalClear Software, Inc.
|
Chris@16
|
5 * Subject to the Boost Software License, Version 1.0.
|
Chris@16
|
6 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 * Author: Jeff Garland, Bart Garst
|
Chris@101
|
8 * $Date$
|
Chris@16
|
9 */
|
Chris@16
|
10
|
Chris@16
|
11
|
Chris@16
|
12 #include <string>
|
Chris@16
|
13 #include <sstream>
|
Chris@16
|
14
|
Chris@16
|
15 namespace boost {
|
Chris@16
|
16 namespace date_time {
|
Chris@16
|
17
|
Chris@16
|
18
|
Chris@16
|
19
|
Chris@16
|
20 //! Interface class for dynamic time zones.
|
Chris@16
|
21 /*! This class represents the base interface for all timezone
|
Chris@16
|
22 * representations. Subclasses may provide different systems
|
Chris@16
|
23 * for identifying a particular zone. For example some may
|
Chris@16
|
24 * provide a geographical based zone construction while others
|
Chris@16
|
25 * may specify the offset from GMT. Another possible implementation
|
Chris@16
|
26 * would be to convert from POSIX timezone strings. Regardless of
|
Chris@16
|
27 * the construction technique, this is the interface that these
|
Chris@16
|
28 * time zone types must provide.
|
Chris@16
|
29 *
|
Chris@16
|
30 * Note that this class is intended to be used as a shared
|
Chris@16
|
31 * resource (hence the derivation from boost::counted_base.
|
Chris@16
|
32 */
|
Chris@16
|
33 template<typename time_type, typename CharT>
|
Chris@16
|
34 class time_zone_base {
|
Chris@16
|
35 public:
|
Chris@16
|
36 typedef CharT char_type;
|
Chris@16
|
37 typedef std::basic_string<CharT> string_type;
|
Chris@16
|
38 typedef std::basic_ostringstream<CharT> stringstream_type;
|
Chris@16
|
39 typedef typename time_type::date_type::year_type year_type;
|
Chris@16
|
40 typedef typename time_type::time_duration_type time_duration_type;
|
Chris@16
|
41
|
Chris@16
|
42 time_zone_base() {}
|
Chris@16
|
43 virtual ~time_zone_base() {}
|
Chris@16
|
44 //!String for the timezone when in daylight savings (eg: EDT)
|
Chris@16
|
45 virtual string_type dst_zone_abbrev() const=0;
|
Chris@16
|
46 //!String for the zone when not in daylight savings (eg: EST)
|
Chris@16
|
47 virtual string_type std_zone_abbrev() const=0;
|
Chris@16
|
48 //!String for the timezone when in daylight savings (eg: Eastern Daylight Time)
|
Chris@16
|
49 virtual string_type dst_zone_name() const=0;
|
Chris@16
|
50 //!String for the zone when not in daylight savings (eg: Eastern Standard Time)
|
Chris@16
|
51 virtual string_type std_zone_name() const=0;
|
Chris@16
|
52 //! True if zone uses daylight savings adjustments otherwise false
|
Chris@16
|
53 virtual bool has_dst() const=0;
|
Chris@16
|
54 //! Local time that DST starts -- undefined if has_dst is false
|
Chris@16
|
55 virtual time_type dst_local_start_time(year_type y) const=0;
|
Chris@16
|
56 //! Local time that DST ends -- undefined if has_dst is false
|
Chris@16
|
57 virtual time_type dst_local_end_time(year_type y) const=0;
|
Chris@16
|
58 //! Base offset from UTC for zone (eg: -07:30:00)
|
Chris@16
|
59 virtual time_duration_type base_utc_offset() const=0;
|
Chris@16
|
60 //! Adjustment forward or back made while DST is in effect
|
Chris@16
|
61 virtual time_duration_type dst_offset() const=0;
|
Chris@16
|
62 //! Returns a POSIX time_zone string for this object
|
Chris@16
|
63 virtual string_type to_posix_string() const =0;
|
Chris@16
|
64
|
Chris@16
|
65 private:
|
Chris@16
|
66
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69
|
Chris@16
|
70 //! Structure which holds the time offsets associated with daylight savings time
|
Chris@16
|
71 /*!
|
Chris@16
|
72 *@param time_duration_type A type used to represent the offset
|
Chris@16
|
73 */
|
Chris@16
|
74 template<class time_duration_type>
|
Chris@16
|
75 class dst_adjustment_offsets
|
Chris@16
|
76 {
|
Chris@16
|
77 public:
|
Chris@16
|
78 dst_adjustment_offsets(const time_duration_type& dst_adjust,
|
Chris@16
|
79 const time_duration_type& dst_start_offset,
|
Chris@16
|
80 const time_duration_type& dst_end_offset) :
|
Chris@16
|
81 dst_adjust_(dst_adjust),
|
Chris@16
|
82 dst_start_offset_(dst_start_offset),
|
Chris@16
|
83 dst_end_offset_(dst_end_offset)
|
Chris@16
|
84 {}
|
Chris@16
|
85
|
Chris@16
|
86 //! Amount DST adjusts the clock eg: plus one hour
|
Chris@16
|
87 time_duration_type dst_adjust_;
|
Chris@16
|
88 //! Time past midnight on start transition day that dst starts
|
Chris@16
|
89 time_duration_type dst_start_offset_;
|
Chris@16
|
90 //! Time past midnight on end transition day that dst ends
|
Chris@16
|
91 time_duration_type dst_end_offset_;
|
Chris@16
|
92 };
|
Chris@16
|
93
|
Chris@16
|
94
|
Chris@16
|
95 } } //namespace date_time
|
Chris@16
|
96
|
Chris@16
|
97
|
Chris@16
|
98
|
Chris@16
|
99 #endif
|