3 /// Record parsing class for the timezone database.
7 Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
8 Copyright (C) 2008, Brian Edginton
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_RECORD_TIMEZONE_H__
24 #define __BARRY_RECORD_TIMEZONE_H__
34 // forward declarations
37 class BXEXPORT TimeZone
40 typedef Barry::UnknownsType UnknownsType
;
45 std::string Name
; //< name of time zone
47 int32_t Index
; //< index of entry in time zone table...
48 //< matches Code in hard coded TimeZone
51 int32_t UTCOffset
; //< Timezone offset from UTC in minutes.
52 //< Will be a negative value for west
53 //< of UTC (North America, etc), and
54 //< a positive value for east (Europe).
55 //< i.e. -210 for St. John's, which is
56 //< -3.5 hours from UTC.
58 bool UseDST
; //< true this timezone uses DST
59 uint32_t DSTOffset
; //< minutes of DST, if UseDST is true.
60 //< This value will almost always be 60.
61 uint32_t StartMonth
; //< index, 0-11, of month to start DST
62 uint32_t EndMonth
; //< index, 0-11, of month to end DST
64 uint8_t TZType
; //< unknown
66 UnknownsType Unknowns
;
71 /// Creates a new timezone based on utc_offset minutes.
72 /// Use same semantics as UTCOffset. For example, a -3.5 hour
73 /// timezone (which is west of UTC) would be constructed
74 /// as: TimeZone(-210)
75 explicit TimeZone(int utc_offset
);
77 /// Creates a new timezone based on negative/positive hours,
78 /// and positive minutes. For example, a -3.5 hour timezone
79 /// (which is west of UTC) would be constructed as: TimeZone(-3, 30)
80 TimeZone(int hours
, int minutes
);
85 // TimeZone related utility functions
88 bool IsWest() const { return UTCOffset
< 0; }
90 /// Splits UTCOffset minutes into hours and minutes. hours can be
91 /// negative. minutes is always positive.
92 void Split(int *hours
, int *minutes
) const;
94 /// Splits UTCOffset minutes into absolute values of hours and minutes,
95 /// and sets the west flag appropriately. This is to mimic the
96 /// old behaviour of the Left, Offset and OffsetFraction member
98 void SplitAbsolute(bool *west
,
99 unsigned int *hours
, unsigned int *minutes
) const;
101 /// Creates a timezone string suitable for a Unix / POSIX TZ
102 /// environment variable. Expects a time zone prefix.
103 /// For example, New Zealand Standard/Daylight Time is NZST/NZDT, so
104 /// the prefix would be "NZ". Eastern Standard/Daylight Time
105 /// is EST/EDT, so the prefix would be "E".
107 /// Should be able to use this string to achieve time zone conversions
108 /// using the TzWrapper class.
109 std::string
GetTz(const std::string
&prefix
) const;
112 // common Barry record functions
113 void Validate() const;
114 const unsigned char* ParseField(const unsigned char *begin
,
115 const unsigned char *end
, const IConverter
*ic
= 0);
116 void ParseRecurrenceData(const void *data
);
117 void BuildRecurrenceData(void *data
);
118 uint8_t GetRecType() const { return RecType
; }
119 uint32_t GetUniqueId() const { return RecordId
; }
120 void SetIds(uint8_t Type
, uint32_t Id
) { RecType
= Type
; RecordId
= Id
; }
121 void ParseHeader(const Data
&data
, size_t &offset
);
122 void ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
= 0);
123 void BuildHeader(Data
&data
, size_t &offset
) const;
124 void BuildFields(Data
&data
, size_t &offset
, const IConverter
*ic
= 0) const;
126 // operations (common among record classes)
128 void Dump(std::ostream
&os
) const;
129 std::string
GetDescription() const;
131 bool operator<(const TimeZone
&other
) const { return Name
< other
.Name
; }
134 static const char * GetDBName() { return "Time Zones"; }
135 static uint8_t GetDefaultRecType() { return 2; }
137 // Generic Field Handle support
138 static const FieldHandle
<TimeZone
>::ListT
& GetFieldHandles();
141 BXEXPORT
inline std::ostream
& operator<<(std::ostream
&os
, const TimeZone
&msg
) {
147 #endif /* __BARRY_RECORD_TIMEZONE_H__*/