|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __VTZRULES_H__ |
|
17 #define __VTZRULES_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <s32strm.h> |
|
21 #include <tzdefines.h> |
|
22 #include <tz.h> |
|
23 |
|
24 class CVTzActualisedRules; |
|
25 class TVTzActualisedRule; |
|
26 |
|
27 const TInt KVTzRulesGranularity = 4; |
|
28 |
|
29 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
30 * Time zone rules |
|
31 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
|
32 |
|
33 /** |
|
34 Encapsulates one time zone rule. |
|
35 |
|
36 @publishedAll |
|
37 @released |
|
38 */ |
|
39 class TTzRule |
|
40 { |
|
41 public: |
|
42 IMPORT_C TTzRule(TInt16 aFromYear, TInt16 aToYear, TInt16 aOldOffset, TInt16 aNewOffset, TMonth aMonth, TTzRuleDay aDayRule, |
|
43 TUint8 aDayOfMonth, TUint8 aDayOfWeek, TTzTimeReference aTimeReference, TUint16 aTimeOfChange); |
|
44 IMPORT_C TTzRule(); |
|
45 IMPORT_C TTzRule(const TTzRule& aRule); |
|
46 IMPORT_C TTzRule(TTimeWithReference aFromYear, TTimeWithReference aToYear, TInt16 aOldOffset, TInt16 aNewOffset, TMonth aMonth, TTzRuleDay aDayRule, |
|
47 TUint8 aDayOfMonth, TUint8 aDayOfWeek, TTzTimeReference aTimeReference, TUint16 aTimeOfChange); |
|
48 |
|
49 |
|
50 void ExternalizeL(RWriteStream& aStream) const; |
|
51 void InternalizeL(RReadStream& aStream); |
|
52 TBool RuleApplies(const TTime& aStart, const TTime& aEnd) const; |
|
53 |
|
54 IMPORT_C TVTzActualisedRule Actualise(TInt aYear) const; // deprecated, replace by the L version |
|
55 IMPORT_C TVTzActualisedRule ActualiseL(TInt aYear) const; |
|
56 |
|
57 public: |
|
58 TTimeWithReference iFrom; // first date the rule applies |
|
59 TTimeWithReference iTo; // last date the rule applies |
|
60 TInt16 iOldLocalTimeOffset; // local time offset (in minutes) BEFORE the change (local time = UTC + DST) |
|
61 TInt16 iNewLocalTimeOffset; // local time offset (in minutes) AFTER the change |
|
62 TMonth iMonth; |
|
63 TTzRuleDay iDayRule; // format in which the rule is expressed |
|
64 TUint8 iDayOfMonth; |
|
65 TUint8 iDayOfWeek; |
|
66 TTzTimeReference iTimeReference; |
|
67 TUint16 iTimeOfChange; // number of minutes since midnight |
|
68 TUint32 iReserved; |
|
69 }; |
|
70 |
|
71 |
|
72 |
|
73 /** |
|
74 Encapsulates a collection of time zone rules, and includes the period covered by the rules |
|
75 and the standard time offset at the start of that period. |
|
76 |
|
77 @publishedAll |
|
78 @released |
|
79 */ |
|
80 class CTzRules : public CBase |
|
81 { |
|
82 public: |
|
83 IMPORT_C static CTzRules* NewL(); |
|
84 IMPORT_C static CTzRules* NewL(TInt aStartYear, TInt aEndYear); |
|
85 IMPORT_C static CTzRules* NewL(RReadStream& aStream); |
|
86 IMPORT_C ~CTzRules(); |
|
87 IMPORT_C TBool RulesApply(const TTime& aTime) const; |
|
88 IMPORT_C void AddRuleL(TTzRule aRule); |
|
89 IMPORT_C void RemoveRule(TInt aIndex); |
|
90 IMPORT_C TTzRule& operator[](TInt aIndex); |
|
91 IMPORT_C TInt Count() const; |
|
92 IMPORT_C TInt StartYear() const; |
|
93 IMPORT_C TInt EndYear() const; |
|
94 IMPORT_C void SetStartYear(TInt aYear); |
|
95 IMPORT_C void SetEndYear(TInt aYear); |
|
96 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
97 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
98 IMPORT_C TInt InitialStdTimeOffset() const; |
|
99 IMPORT_C void SetInitialStdTimeOffset(TInt aOffset); |
|
100 IMPORT_C void ConvertToUtcL(TTime& aLocalTime) const; |
|
101 IMPORT_C void ConvertToLocalL(TTime& aUtcTime) const; |
|
102 IMPORT_C CTzRules* CloneL() const; |
|
103 IMPORT_C TBool IsEqualTo(const CTzRules& aRules) const; |
|
104 |
|
105 IMPORT_C void GetActualisedRulesL(CVTzActualisedRules& aActRules) const; |
|
106 IMPORT_C TInt ConvertTime(CVTzActualisedRules& aRules, TTime& aTime, TTzTimeReference aTimerRef) const; |
|
107 |
|
108 IMPORT_C TInt GetOffsetL(const TTime& aTime, TTzTimeReference aTimeRef) const; |
|
109 IMPORT_C TInt SizeOfObject() const; |
|
110 IMPORT_C void CopyL(const CTzRules& aTzRule); |
|
111 |
|
112 private: |
|
113 CTzRules(); |
|
114 CTzRules(TInt aStartYear, TInt aEndYear); |
|
115 void AddActualisedRulesL(CVTzActualisedRules& aActRules, TInt aYear) const; |
|
116 TInt CompareTimesWithRef(TTime aTimeA, TTzTimeReference aTimeARef, |
|
117 TTime aTimeB, TTzTimeReference aTimeBRef, TInt aStdOffset, TInt aWallOffset, |
|
118 TTimeIntervalMinutes* aMinutesDifference) const; |
|
119 |
|
120 private: |
|
121 TInt16 iStartYear; |
|
122 TInt16 iEndYear; |
|
123 RArray<TTzRule> iRules; |
|
124 TInt iInitialStdTimeOffset; |
|
125 |
|
126 mutable CVTzActualisedRules* iActualisedRulesCache; |
|
127 }; |
|
128 |
|
129 |
|
130 |
|
131 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
132 * Actualised time zone rules |
|
133 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
|
134 |
|
135 /** |
|
136 Encapsulates a local time change. |
|
137 |
|
138 @publishedAll |
|
139 @released |
|
140 */ |
|
141 class TVTzActualisedRule |
|
142 { |
|
143 public: |
|
144 IMPORT_C TVTzActualisedRule(TTime aTimeOfChange, TInt aNewOffset, TTzTimeReference aTimeReference); |
|
145 IMPORT_C TVTzActualisedRule(); |
|
146 |
|
147 IMPORT_C void operator=(TVTzActualisedRule aRule); |
|
148 static TInt Order(const TVTzActualisedRule& aLeft, const TVTzActualisedRule& aRight); |
|
149 |
|
150 public: |
|
151 TTime iTimeOfChange; |
|
152 TInt32 iNewOffset; |
|
153 TTzTimeReference iTimeReference; |
|
154 }; |
|
155 |
|
156 |
|
157 /** |
|
158 Encapsulates a collection of the local time changes occurring during a range of years. |
|
159 |
|
160 @publishedAll |
|
161 @released |
|
162 */ |
|
163 NONSHARABLE_CLASS(CVTzActualisedRules) : public CBase |
|
164 { |
|
165 public: |
|
166 IMPORT_C static CVTzActualisedRules* NewL(TInt aStartYear, TInt aEndYear); |
|
167 IMPORT_C ~CVTzActualisedRules(); |
|
168 IMPORT_C void AddRuleL(const TVTzActualisedRule& aRule); |
|
169 IMPORT_C TInt Count() const; |
|
170 IMPORT_C TVTzActualisedRule& operator[](TInt aIndex) const; |
|
171 |
|
172 IMPORT_C TInt StartYear() const; |
|
173 IMPORT_C TInt EndYear() const; |
|
174 |
|
175 IMPORT_C TBool IsDaylightSavingOn(TTime& aTime) const; |
|
176 IMPORT_C TInt GetOffsetFromRuleL(const TTime& aTime, TTzTimeReference aTimeRef) const; |
|
177 |
|
178 private: |
|
179 CVTzActualisedRules(TInt aStartYear, TInt aEndYear); |
|
180 CVTzActualisedRules(); |
|
181 TInt CompareTimesWithRef(TTime aRolloverTime, TTzTimeReference aTimeRefRollover, |
|
182 TTime aUserTime, TTzTimeReference aTimeRefUser, |
|
183 TInt aOldWallOffset, TTimeIntervalMinutes& aDiffMinutes) const; |
|
184 |
|
185 private: |
|
186 TInt32 iStartYear; // years covered by |
|
187 TInt32 iEndYear; // the actualised rules |
|
188 RArray<TVTzActualisedRule> iRules; |
|
189 }; |
|
190 |
|
191 #endif |