williamr@2
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@2
|
4 |
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@2
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
//
|
williamr@2
|
15 |
|
williamr@2
|
16 |
#ifndef __TIMEZONE_H__
|
williamr@2
|
17 |
#define __TIMEZONE_H__
|
williamr@2
|
18 |
|
williamr@2
|
19 |
#include <e32base.h>
|
williamr@2
|
20 |
#include <s32std.h>
|
williamr@2
|
21 |
#include <tzdefines.h>
|
williamr@2
|
22 |
#include <tzupdate.h>
|
williamr@2
|
23 |
|
williamr@2
|
24 |
class CTzChangeNotifier;
|
williamr@2
|
25 |
class CTzRules;
|
williamr@2
|
26 |
class CTzRuleHolder;
|
williamr@2
|
27 |
|
williamr@2
|
28 |
//-------------------------------------------------------------------------
|
williamr@2
|
29 |
/**
|
williamr@2
|
30 |
Encapsulates a time zone identifier.
|
williamr@2
|
31 |
|
williamr@2
|
32 |
The identifier may be either a name or a number.
|
williamr@2
|
33 |
@publishedAll
|
williamr@2
|
34 |
@released
|
williamr@2
|
35 |
@since 9.1
|
williamr@2
|
36 |
*/
|
williamr@2
|
37 |
class CTzId : public CBase
|
williamr@2
|
38 |
{
|
williamr@2
|
39 |
public:
|
williamr@2
|
40 |
|
williamr@2
|
41 |
IMPORT_C ~CTzId();
|
williamr@2
|
42 |
|
williamr@2
|
43 |
/**
|
williamr@2
|
44 |
@internalComponent
|
williamr@2
|
45 |
*/
|
williamr@2
|
46 |
IMPORT_C CTzId* CloneL() const;
|
williamr@2
|
47 |
|
williamr@2
|
48 |
IMPORT_C static CTzId* NewL(TUint aNumericId);
|
williamr@2
|
49 |
|
williamr@2
|
50 |
IMPORT_C static CTzId* NewL(const TDesC8& aNameIdentity);
|
williamr@2
|
51 |
|
williamr@2
|
52 |
/**
|
williamr@2
|
53 |
@internalComponent
|
williamr@2
|
54 |
*/
|
williamr@2
|
55 |
IMPORT_C static CTzId* NewL(RReadStream& aStream);
|
williamr@2
|
56 |
|
williamr@2
|
57 |
/**
|
williamr@2
|
58 |
@internalComponent
|
williamr@2
|
59 |
*/
|
williamr@2
|
60 |
IMPORT_C void SetId(TUint aNumericId);
|
williamr@2
|
61 |
|
williamr@2
|
62 |
/**
|
williamr@2
|
63 |
@internalComponent
|
williamr@2
|
64 |
*/
|
williamr@2
|
65 |
IMPORT_C void SetIdL(const TDesC8& aNameIdentity);
|
williamr@2
|
66 |
|
williamr@2
|
67 |
/**
|
williamr@2
|
68 |
@internalComponent
|
williamr@2
|
69 |
*/
|
williamr@2
|
70 |
IMPORT_C void InternalizeL(RReadStream& aStream);
|
williamr@2
|
71 |
|
williamr@2
|
72 |
/**
|
williamr@2
|
73 |
@internalComponent
|
williamr@2
|
74 |
*/
|
williamr@2
|
75 |
IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
|
williamr@2
|
76 |
|
williamr@2
|
77 |
IMPORT_C const TDesC8& TimeZoneNameID() const;
|
williamr@2
|
78 |
|
williamr@2
|
79 |
IMPORT_C TUint TimeZoneNumericID() const;
|
williamr@2
|
80 |
|
williamr@2
|
81 |
IMPORT_C TBool operator==(const CTzId& aTZId) const;
|
williamr@2
|
82 |
|
williamr@2
|
83 |
inline TBool operator!=(const CTzId& aTZId) const;
|
williamr@2
|
84 |
|
williamr@2
|
85 |
public:
|
williamr@2
|
86 |
static CTzId* NewL(TUint aReferenceId, const TDesC8& aZoneIdentity);
|
williamr@2
|
87 |
void SetIdL(TUint aNumRefId, const TDesC8& aZoneIdentity);
|
williamr@2
|
88 |
|
williamr@2
|
89 |
private:
|
williamr@2
|
90 |
void ConstructL(const TDesC8& aZoneIdentity);
|
williamr@2
|
91 |
CTzId();
|
williamr@2
|
92 |
CTzId(TUint aNumericId);
|
williamr@2
|
93 |
|
williamr@2
|
94 |
private:
|
williamr@2
|
95 |
HBufC8* iZoneId;
|
williamr@2
|
96 |
TUint32 iReferenceId;
|
williamr@2
|
97 |
};
|
williamr@2
|
98 |
|
williamr@2
|
99 |
|
williamr@2
|
100 |
/**
|
williamr@2
|
101 |
The client interface to the time zone server.
|
williamr@2
|
102 |
|
williamr@2
|
103 |
This class performs two basic functions:
|
williamr@2
|
104 |
1. Converts between UTC time and local time.
|
williamr@2
|
105 |
2. Sets the current local time zone.
|
williamr@2
|
106 |
|
williamr@2
|
107 |
NOTE: The presence of a time zone server will alter the behaviour of the
|
williamr@2
|
108 |
time zone related function calls User::SetUTCOffset() and
|
williamr@2
|
109 |
User::SetUTCTimeAndOffset(). The time zone server is shutdown when the
|
williamr@2
|
110 |
last session (RTz) is closed. Therefore, to maintain consistent time related behaviour,
|
williamr@2
|
111 |
licensees may want to keep a system level time zone server session open at all times.
|
williamr@2
|
112 |
|
williamr@2
|
113 |
@see User
|
williamr@2
|
114 |
|
williamr@2
|
115 |
Exceptional cases occur when a user requests conversion
|
williamr@2
|
116 |
for a non-existent local time or a double local time.
|
williamr@2
|
117 |
|
williamr@2
|
118 |
Non-existent local times occur when the local time
|
williamr@2
|
119 |
changes from winter to summer for DST.
|
williamr@2
|
120 |
|
williamr@2
|
121 |
For example, 01:59 local time is non-existent on the day of a change to BST
|
williamr@2
|
122 |
in Europe/London since the time changes directly from 12:59:59 to 2:00.
|
williamr@2
|
123 |
|
williamr@2
|
124 |
A double local time occurs when the local time changes from
|
williamr@2
|
125 |
summer to winter.
|
williamr@2
|
126 |
|
williamr@2
|
127 |
For example, if the time changes at 02:00 AM BST to 01:00 AM GMT
|
williamr@2
|
128 |
then local times between 01:00 and 01:59 occur twice.
|
williamr@2
|
129 |
|
williamr@2
|
130 |
The conversion applies the DST offset if the local time value is double and applies
|
williamr@2
|
131 |
the standard UTC offset if the local time does not exists.
|
williamr@2
|
132 |
|
williamr@2
|
133 |
This decision makes the conversion process asymmetrical around
|
williamr@2
|
134 |
the discontinuity in the local time when there is a DST change.
|
williamr@2
|
135 |
|
williamr@2
|
136 |
An example conversion from a double local time to UTC and
|
williamr@2
|
137 |
from UTC to a double local time is:
|
williamr@2
|
138 |
|
williamr@2
|
139 |
01:59 AM BST => 00:59 AM UTC
|
williamr@2
|
140 |
01:59 AM UTC => 01:59 AM GMT
|
williamr@2
|
141 |
|
williamr@2
|
142 |
An example conversion from a non-existent local time to UTC
|
williamr@2
|
143 |
and from UTC to local time is:
|
williamr@2
|
144 |
|
williamr@2
|
145 |
01:59 AM GMT => 01:59 AM UTC
|
williamr@2
|
146 |
01:59 AM UTC => 02:59 AM BST
|
williamr@2
|
147 |
|
williamr@2
|
148 |
|
williamr@2
|
149 |
@publishedAll
|
williamr@2
|
150 |
@released
|
williamr@2
|
151 |
@since 9.1
|
williamr@2
|
152 |
*/
|
williamr@2
|
153 |
class RTz : public RSessionBase
|
williamr@2
|
154 |
{
|
williamr@2
|
155 |
public:
|
williamr@2
|
156 |
/**
|
williamr@2
|
157 |
These enumerators are to describe different modes of the automatic
|
williamr@2
|
158 |
DST event handling.
|
williamr@2
|
159 |
|
williamr@2
|
160 |
These are used both as arguments for the API SetAutoUpdateBehaviorL,
|
williamr@2
|
161 |
and as notifications for the publish and subscribe.
|
williamr@2
|
162 |
*/
|
williamr@2
|
163 |
enum TTzAutoDSTUpdateModes
|
williamr@2
|
164 |
{
|
williamr@2
|
165 |
/** No auto update notification when a DST event occurs. */
|
williamr@2
|
166 |
ETZAutoDSTUpdateOff = 0,
|
williamr@2
|
167 |
|
williamr@2
|
168 |
/** Automatic time update will occur and the client app will be notified. */
|
williamr@2
|
169 |
ETZAutoDSTUpdateOn,
|
williamr@2
|
170 |
|
williamr@2
|
171 |
/** Client app needs to confirm that the time should be updated whenever a DST event occurs. */
|
williamr@2
|
172 |
ETZAutoDSTNotificationOnly,
|
williamr@2
|
173 |
};
|
williamr@2
|
174 |
|
williamr@2
|
175 |
enum TTzChanges
|
williamr@2
|
176 |
{
|
williamr@2
|
177 |
/** Used for notifying that the timezone database has changed.*/
|
williamr@2
|
178 |
ETZDatabaseChanged = 1,
|
williamr@2
|
179 |
/** Used for notifying that the system timezone database has changed.*/
|
williamr@2
|
180 |
ETZSystemTimeZoneChanged,
|
williamr@2
|
181 |
/** Used for notifying that the DST rule has changed. */
|
williamr@2
|
182 |
ETZDSTRuleChanged,
|
williamr@2
|
183 |
/** Used for notifying that an automatic time update has taken place. */
|
williamr@2
|
184 |
ETZAutomaticTimeUpdate
|
williamr@2
|
185 |
};
|
williamr@2
|
186 |
|
williamr@2
|
187 |
enum TPanic
|
williamr@2
|
188 |
{
|
williamr@2
|
189 |
/** This panic indicates that the time zone server has not been found.*/
|
williamr@2
|
190 |
EPanicServerNotFound = 1,
|
williamr@2
|
191 |
/** This panic indicates that the server has died.*/
|
williamr@2
|
192 |
EPanicServerDead,
|
williamr@2
|
193 |
/** This panic indicates that the time zone ID is not set.*/
|
williamr@2
|
194 |
EPanicTimeZoneNameIdNotSet,
|
williamr@2
|
195 |
/** This panic indicates that an out of range index was accessed.*/
|
williamr@2
|
196 |
EPanicRulesIndexOutofRange,
|
williamr@2
|
197 |
/** This panic indicates that there are no rules present for this time zone.*/
|
williamr@2
|
198 |
EPanicTimeNotCoveredByRules,
|
williamr@2
|
199 |
/** This panic indicates that the time zone rules are unusable.*/
|
williamr@2
|
200 |
EPanicBadTimeZoneRules,
|
williamr@2
|
201 |
/** This panic indicates that an unsupported time reference has been accessed.*/
|
williamr@2
|
202 |
EPanicUnsupportedTimeReference,
|
williamr@2
|
203 |
/** This panic indicates that the time zone ID is not supported.*/
|
williamr@2
|
204 |
EPanicUnsupportedTimeZoneNoId,
|
williamr@2
|
205 |
/** This panic indicates that a request for notification is already pending from the client.*/
|
williamr@2
|
206 |
EPanicNotificationRequestPending,
|
williamr@2
|
207 |
/** This panic indicates that an incorrect data has been sent to the server.*/
|
williamr@2
|
208 |
EPanicInvalidArgument
|
williamr@2
|
209 |
};
|
williamr@2
|
210 |
|
williamr@2
|
211 |
/**
|
williamr@2
|
212 |
@internalComponent
|
williamr@2
|
213 |
*/
|
williamr@2
|
214 |
IMPORT_C static void Panic(TPanic aPanic);
|
williamr@2
|
215 |
|
williamr@2
|
216 |
/**
|
williamr@2
|
217 |
@internalTechnology
|
williamr@2
|
218 |
*/
|
williamr@2
|
219 |
IMPORT_C CTzId* GetTimeZoneIdL() const;
|
williamr@2
|
220 |
|
williamr@2
|
221 |
/**
|
williamr@2
|
222 |
@internalTechnology
|
williamr@2
|
223 |
*/
|
williamr@2
|
224 |
IMPORT_C void SetTimeZoneL(CTzId& aZone) const;
|
williamr@2
|
225 |
|
williamr@2
|
226 |
IMPORT_C void Close();
|
williamr@2
|
227 |
|
williamr@2
|
228 |
IMPORT_C TInt Connect();
|
williamr@2
|
229 |
|
williamr@2
|
230 |
IMPORT_C ~RTz();
|
williamr@2
|
231 |
|
williamr@2
|
232 |
IMPORT_C RTz();
|
williamr@2
|
233 |
|
williamr@2
|
234 |
IMPORT_C TInt ConvertToLocalTime(TTime& aTime) const;
|
williamr@2
|
235 |
|
williamr@2
|
236 |
IMPORT_C TInt ConvertToLocalTime(TTime& aTime, const CTzId& aZone) const;
|
williamr@2
|
237 |
|
williamr@2
|
238 |
IMPORT_C TInt ConvertToUniversalTime(TTime& aTime) const;
|
williamr@2
|
239 |
|
williamr@2
|
240 |
IMPORT_C TInt ConvertToUniversalTime(TTime& aTime, const CTzId& aZone) const;
|
williamr@2
|
241 |
|
williamr@2
|
242 |
IMPORT_C void GetOffsetsForTimeZoneIdsL(const RArray<TInt>& aTzNumericIds, RArray<TInt>& aOffsets) const;
|
williamr@2
|
243 |
|
williamr@2
|
244 |
IMPORT_C TInt AutoUpdateSettingL();
|
williamr@2
|
245 |
|
williamr@2
|
246 |
IMPORT_C void SetAutoUpdateBehaviorL(TTzAutoDSTUpdateModes aUpdateEnabled);
|
williamr@2
|
247 |
|
williamr@2
|
248 |
// Methods for setting the system time.
|
williamr@2
|
249 |
IMPORT_C TInt SetHomeTime(const TTime& aLocalTime) const;
|
williamr@2
|
250 |
|
williamr@2
|
251 |
IMPORT_C TBool IsDaylightSavingOnL(CTzId& aZone) const;
|
williamr@2
|
252 |
|
williamr@2
|
253 |
IMPORT_C TBool IsDaylightSavingOnL(CTzId& aZone, const TTime& aUTCTime) const;
|
williamr@2
|
254 |
|
williamr@2
|
255 |
// Get Encoded Rules for Current Local Time Zone
|
williamr@2
|
256 |
IMPORT_C CTzRules* GetTimeZoneRulesL(const TTime& aStartTime, const TTime& aEndTime, TTzTimeReference aTimeRef) const;
|
williamr@2
|
257 |
|
williamr@2
|
258 |
IMPORT_C CTzRules* GetTimeZoneRulesL(const CTzId& aZone, const TTime& aStartTime, const TTime& aEndTime, TTzTimeReference aTimeRef) const;
|
williamr@2
|
259 |
|
williamr@2
|
260 |
void RegisterTzChangeNotifier(TRequestStatus& aStatus) const;
|
williamr@2
|
261 |
TInt CancelRequestForNotice() const;
|
williamr@2
|
262 |
TVersion Version() const;
|
williamr@2
|
263 |
|
williamr@2
|
264 |
IMPORT_C void NotifyHomeTimeZoneChangedL(const NTzUpdate::TTimeZoneChange& aChange) const;
|
williamr@2
|
265 |
|
williamr@2
|
266 |
IMPORT_C void SetUnknownZoneTimeL(const TTime& aUTCTime, const TInt aUTCOffset);
|
williamr@2
|
267 |
|
williamr@2
|
268 |
IMPORT_C void SetUnknownZoneTimeL(const TTime& aUTCTime, const TInt aUTCOffset, TBool aPersistInCenRep);
|
williamr@2
|
269 |
|
williamr@2
|
270 |
IMPORT_C void __dbgClearCacheL(TBool aRestartCaching);
|
williamr@2
|
271 |
|
williamr@2
|
272 |
TBool StartCachingL();
|
williamr@2
|
273 |
TUint16 CurrentCachedTzId();
|
williamr@2
|
274 |
|
williamr@2
|
275 |
private:
|
williamr@2
|
276 |
static TInt StartServer();
|
williamr@2
|
277 |
TInt DoConnect();
|
williamr@2
|
278 |
void doConvertL(const CTzId& aZone, TTime& aTime,
|
williamr@2
|
279 |
TTzTimeReference aTimerRef) const;
|
williamr@2
|
280 |
void doConvertL(TTime& aTime,
|
williamr@2
|
281 |
TTzTimeReference aTimerRef) const;
|
williamr@2
|
282 |
private:
|
williamr@2
|
283 |
CTzRuleHolder* iRulesHolder;
|
williamr@2
|
284 |
};
|
williamr@2
|
285 |
|
williamr@2
|
286 |
/**
|
williamr@2
|
287 |
Encapsulates a TTime and a TTzTimeReference.
|
williamr@2
|
288 |
Use, for example, for iCalendar's DTSTART.
|
williamr@2
|
289 |
|
williamr@2
|
290 |
@publishedAll
|
williamr@2
|
291 |
@released
|
williamr@2
|
292 |
*/
|
williamr@2
|
293 |
class TTimeWithReference
|
williamr@2
|
294 |
{
|
williamr@2
|
295 |
public:
|
williamr@2
|
296 |
static inline TTimeWithReference Max();
|
williamr@2
|
297 |
inline TTimeWithReference();
|
williamr@2
|
298 |
inline TTimeWithReference(TTime aTime, TTzTimeReference aTimeReference=ETzUtcTimeReference);
|
williamr@2
|
299 |
inline TTimeWithReference(TDateTime aTime, TTzTimeReference aTimeReference=ETzUtcTimeReference);
|
williamr@2
|
300 |
inline bool operator==(const TTimeWithReference& aTime) const;
|
williamr@2
|
301 |
inline bool operator!=(const TTimeWithReference& aTime) const;
|
williamr@2
|
302 |
|
williamr@2
|
303 |
TTime iTime;
|
williamr@2
|
304 |
TTzTimeReference iTimeReference;
|
williamr@2
|
305 |
};
|
williamr@2
|
306 |
|
williamr@2
|
307 |
/** Inequality operator.
|
williamr@2
|
308 |
|
williamr@2
|
309 |
@param aTZId The time zone ID to compare with this one.
|
williamr@2
|
310 |
@return True if the two IDs are different. False if they are the same.
|
williamr@2
|
311 |
*/
|
williamr@2
|
312 |
inline TBool CTzId::operator!=(const CTzId& aTZId) const
|
williamr@2
|
313 |
{
|
williamr@2
|
314 |
return (!operator==(aTZId));
|
williamr@2
|
315 |
}
|
williamr@2
|
316 |
|
williamr@2
|
317 |
//////////////////////////////////
|
williamr@2
|
318 |
// TTimeWithReference
|
williamr@2
|
319 |
//////////////////////////////////
|
williamr@2
|
320 |
inline TTimeWithReference TTimeWithReference::Max()
|
williamr@2
|
321 |
{
|
williamr@2
|
322 |
return TTimeWithReference(
|
williamr@2
|
323 |
TDateTime(9999,EDecember,30,23,59,59,0),
|
williamr@2
|
324 |
ETzUtcTimeReference);
|
williamr@2
|
325 |
}
|
williamr@2
|
326 |
|
williamr@2
|
327 |
inline TTimeWithReference::TTimeWithReference()
|
williamr@2
|
328 |
: iTime(0), iTimeReference(ETzUtcTimeReference)
|
williamr@2
|
329 |
{
|
williamr@2
|
330 |
}
|
williamr@2
|
331 |
inline TTimeWithReference::TTimeWithReference(TTime aTime, TTzTimeReference aTimeReference)
|
williamr@2
|
332 |
: iTime(aTime), iTimeReference(aTimeReference)
|
williamr@2
|
333 |
{
|
williamr@2
|
334 |
}
|
williamr@2
|
335 |
inline TTimeWithReference::TTimeWithReference(TDateTime aTime, TTzTimeReference aTimeReference)
|
williamr@2
|
336 |
: iTime(aTime), iTimeReference(aTimeReference)
|
williamr@2
|
337 |
{
|
williamr@2
|
338 |
}
|
williamr@2
|
339 |
inline bool TTimeWithReference::operator==(const TTimeWithReference& aTime) const
|
williamr@2
|
340 |
{
|
williamr@2
|
341 |
return(aTime.iTime == iTime && aTime.iTimeReference == iTimeReference);
|
williamr@2
|
342 |
}
|
williamr@2
|
343 |
inline bool TTimeWithReference::operator!=(const TTimeWithReference& aTime) const
|
williamr@2
|
344 |
{
|
williamr@2
|
345 |
return(!(*this == aTime));
|
williamr@2
|
346 |
}
|
williamr@2
|
347 |
#endif
|