versadac  1
versadac - Scalable Recorder Firmware
am_timezone.h
1 /*****************************************************************************
2 FILE : am_timezone.h
3 VERSION : $Id: am_timezone.h 4938 2006-10-10 14:20:18Z martinto $
4 AUTHOR : Sandra Herring
5 SYSTEM : GNU C++ for Power PC
6 DESCRIPTION : Header file for archive manager timezone classes.
7 *****************************************************************************/
8 
9 #if !defined __AM_TIMEZONE_H
10 #define __AM_TIMEZONE_H
11 
12 extern "C"
13 {
14 #include <string.h>
15 #include "stdtypes.h"
16 }
17 
18 
20 {
21  public :
22  // DST values unpacked from DST rule string
23  uint16 m_Month; // January = 1
24  uint16 m_DayOfWeek; // Sunday = 0
25  sint16 m_WhichOne; // 1st in month to 4th in month = 1 to 4, last = -1, second last = -2
26  sint32 m_OffsetIntoDay; // in seconds, in 'not DST'
27 
28 /*------------------------------------------------------------------------------
29 FUNCTION : AM_DSTData getNoOfDaysInMonth
30 DESCRIPTION : static service to return the number of days in the specified
31  month and year
32 ARGUMENTS : year
33  month jan = 1
34 RETURN : number of days
35 NOTES :
36 ------------------------------------------------------------------------------*/
37  uint8 getNoOfDaysInMonth( uint16 year, uint8 month );
38 
39 /*------------------------------------------------------------------------------
40 FUNCTION : AM_DSTData::compareWithTime
41 
42 DESCRIPTION : compares the dst time change point with a given time_date_t value
43  for efficiency the user can provide a pointer to a time_date_t
44  that also contains the datetime. If the users will make multiple
45  calls with the same time (but presumably to different AM_DSTData
46  objects) then he should do this.
47 ARGUMENTS : DateTime time_date_t object
48  pSystemTime optional pointer to time_date_t object, may be null
49 
50 RETURN : <0 if system time < dst point
51  0 if system time == dst point
52  >0 if system time > dst point
53 NOTES :
54 ------------------------------------------------------------------------------*/
55  sint16 compareWithTime( time_t compareTime );
56 
57 /*------------------------------------------------------------------------------
58 FUNCTION : AM_DSTData::unpackFromString
59 
60 DESCRIPTION : Unpacks from a string into the member variables, converting from java format
61 ARGUMENTS : pString csv string consisting of following values
62  month : January = 0
63  whichone : 1 for 1st, -1 for last as above
64  day : Sunday = 1
65  offsetintoday : in milliseconds
66  Offset an offset as a fraction of a day to be added to the offset in the string
67  this is to allow for the fact that in the string, when
68  it is specifying a DST end then the offset is in DST
69 RETURN : None
70 NOTES :
71 ------------------------------------------------------------------------------*/
72  void unpackFromString( const char *pString, sint32 offset );
73 };
74 
76 {
77  public:
78 
79 /*------------------------------------------------------------------------------
80 FUNCTION : AM_Timezone Constructor
81 DESCRIPTION :
82 ARGUMENTS :
83 RETURN :
84 NOTES :
85 ------------------------------------------------------------------------------*/
86  AM_Timezone();
87 
88 /*------------------------------------------------------------------------------
89 FUNCTION : AM_Timezone expandDSTRules
90 DESCRIPTION : Interprets the DST rule strings, expanding them into member data.
91  Call this after setting up timezone data
92 ARGUMENTS :
93 RETURN :
94 NOTES :
95 ------------------------------------------------------------------------------*/
96  void expandDSTRules();
97 
98 /*------------------------------------------------------------------------------
99 FUNCTION : AM_Timezone::getId
100 DESCRIPTION : returns the time zone descriptor
101 ARGUMENTS : None.
102 RETURN : time zone description
103 NOTES :
104 ------------------------------------------------------------------------------*/
105  const char * getId();
106 
107 /*------------------------------------------------------------------------------
108 FUNCTION : AM_Timezone::setId
109 DESCRIPTION : sets the time zone descriptor
110 ARGUMENTS : time zone description
111 RETURN : None.
112 NOTES :
113 ------------------------------------------------------------------------------*/
114  void setId( const char * id );
115 
116 /*------------------------------------------------------------------------------
117 FUNCTION : AM_Timezone::setTimezoneOffset
118 DESCRIPTION : sets the offset from GMT
119 ARGUMENTS : offset from GMT in seconds
120 RETURN : None.
121 NOTES :
122 ------------------------------------------------------------------------------*/
123  void setTimezoneOffset( sint32 offsetSecs );
124 
125 /*------------------------------------------------------------------------------
126 FUNCTION : AM_Timezone::setDSTStartRule
127 DESCRIPTION : sets the time zone start rule
128 ARGUMENTS : rule string
129 RETURN : None.
130 NOTES :
131 ------------------------------------------------------------------------------*/
132  void setDSTStartRule( const char * rule );
133 
134 /*------------------------------------------------------------------------------
135 FUNCTION : AM_Timezone::setDSTEndRule
136 DESCRIPTION : sets the time zone end rule
137 ARGUMENTS : rule string
138 RETURN : None.
139 NOTES :
140 ------------------------------------------------------------------------------*/
141  void setDSTEndRule( const char * rule );
142 
143 /*------------------------------------------------------------------------------
144 FUNCTION : AM_Timezone::setUseDST
145 DESCRIPTION : sets whether to apply daylight saving time
146 ARGUMENTS : non-zero if to use DST
147 RETURN : None.
148 NOTES :
149 ------------------------------------------------------------------------------*/
150  void setUseDST( uint8 useDST );
151 
152 /*------------------------------------------------------------------------------
153 FUNCTION : AM_Timezone utcToLocal
154 DESCRIPTION : Applies the timezone and dst settings to a given time_t
155 ARGUMENTS : utcTimestamp UTC time to apply to
156 RETURN : adjusted timestamp in local time
157 NOTES :
158 ------------------------------------------------------------------------------*/
159  time_t utcToLocal( time_t utcTimeStamp );
160 
161  private:
162  sint32 m_TimezoneOffset; // in time_t format
163  char m_Id[6];
164  char m_DSTStartRule[21];
165  char m_DSTEndRule[21];
166  uint8 m_UseDST; // treated as a bool
167 
168  // DST values unpacked from strings and adjusted to be more useful
169  AM_DSTData m_DSTStartData;
170  AM_DSTData m_DSTEndData;
171  sint32 m_DSTAdjustment; // seconds to adjust by (+ve)
172  bool m_bStartLessEnd; // indicates dst start date earlier in year than end
173 };
174 
175 
176 // *************************************
177 // inline services for class AM_Timezone
178 // *************************************
179 
180 /*------------------------------------------------------------------------------
181 FUNCTION : AM_Timezone::getId
182 DESCRIPTION : returns the time zone descriptor
183 ARGUMENTS : None.
184 RETURN : time zone description
185 NOTES :
186 ------------------------------------------------------------------------------*/
187 inline const char * AM_Timezone::getId()
188 {
189  return m_Id;
190 }
191 
192 /*------------------------------------------------------------------------------
193 FUNCTION : AM_Timezone::setId
194 DESCRIPTION : sets the time zone descriptor
195 ARGUMENTS : time zone description
196 RETURN : None.
197 NOTES :
198 ------------------------------------------------------------------------------*/
199 inline void AM_Timezone::setId( const char * id )
200 {
201  strcpy(m_Id, id);
202 }
203 
204 /*------------------------------------------------------------------------------
205 FUNCTION : AM_Timezone::setTimezoneOffset
206 DESCRIPTION : sets the offset from GMT
207 ARGUMENTS : offset from GMT in seconds
208 RETURN : None.
209 NOTES :
210 ------------------------------------------------------------------------------*/
211 inline void AM_Timezone::setTimezoneOffset( sint32 offsetSecs )
212 {
213  // convert to fractions of a day
214  m_TimezoneOffset = offsetSecs;
215 }
216 
217 /*------------------------------------------------------------------------------
218 FUNCTION : AM_Timezone::setDSTStartRule
219 DESCRIPTION : sets the time zone start rule
220 ARGUMENTS : rule string
221 RETURN : None.
222 NOTES :
223 ------------------------------------------------------------------------------*/
224 inline void AM_Timezone::setDSTStartRule( const char * rule )
225 {
226  strcpy(m_DSTStartRule, rule);
227 }
228 
229 /*------------------------------------------------------------------------------
230 FUNCTION : AM_Timezone::setDSTEndRule
231 DESCRIPTION : sets the time zone end rule
232 ARGUMENTS : rule string
233 RETURN : None.
234 NOTES :
235 ------------------------------------------------------------------------------*/
236 inline void AM_Timezone::setDSTEndRule( const char * rule )
237 {
238  strcpy(m_DSTEndRule, rule);
239 }
240 
241 /*------------------------------------------------------------------------------
242 FUNCTION : AM_Timezone::setUseDST
243 DESCRIPTION : sets whether to apply daylight saving time
244 ARGUMENTS : non-zero if to use DST
245 RETURN : None.
246 NOTES :
247 ------------------------------------------------------------------------------*/
248 inline void AM_Timezone::setUseDST( uint8 useDST )
249 {
250  m_UseDST = useDST;
251 }
252 
253 #endif
254 
Definition: am_timezone.h:19
Definition: am_timezone.h:75