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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __VTZRULES_H__
17 #define __VTZRULES_H__
21 #include <tzdefines.h>
24 class CVTzActualisedRules;
25 class TVTzActualisedRule;
27 const TInt KVTzRulesGranularity = 4;
29 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
31 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34 Encapsulates one time zone rule.
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);
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);
50 void ExternalizeL(RWriteStream& aStream) const;
51 void InternalizeL(RReadStream& aStream);
52 TBool RuleApplies(const TTime& aStart, const TTime& aEnd) const;
54 IMPORT_C TVTzActualisedRule Actualise(TInt aYear) const; // deprecated, replace by the L version
55 IMPORT_C TVTzActualisedRule ActualiseL(TInt aYear) const;
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
63 TTzRuleDay iDayRule; // format in which the rule is expressed
66 TTzTimeReference iTimeReference;
67 TUint16 iTimeOfChange; // number of minutes since midnight
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.
80 class CTzRules : public CBase
83 IMPORT_C static CTzRules* NewL();
84 IMPORT_C static CTzRules* NewL(TInt aStartYear, TInt aEndYear);
85 IMPORT_C static CTzRules* NewL(RReadStream& aStream);
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;
105 IMPORT_C void GetActualisedRulesL(CVTzActualisedRules& aActRules) const;
106 IMPORT_C TInt ConvertTime(CVTzActualisedRules& aRules, TTime& aTime, TTzTimeReference aTimerRef) const;
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);
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;
123 RArray<TTzRule> iRules;
124 TInt iInitialStdTimeOffset;
126 mutable CVTzActualisedRules* iActualisedRulesCache;
131 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
132 * Actualised time zone rules
133 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
136 Encapsulates a local time change.
141 class TVTzActualisedRule
144 IMPORT_C TVTzActualisedRule(TTime aTimeOfChange, TInt aNewOffset, TTzTimeReference aTimeReference);
145 IMPORT_C TVTzActualisedRule();
147 IMPORT_C void operator=(TVTzActualisedRule aRule);
148 static TInt Order(const TVTzActualisedRule& aLeft, const TVTzActualisedRule& aRight);
153 TTzTimeReference iTimeReference;
158 Encapsulates a collection of the local time changes occurring during a range of years.
163 NONSHARABLE_CLASS(CVTzActualisedRules) : public CBase
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;
172 IMPORT_C TInt StartYear() const;
173 IMPORT_C TInt EndYear() const;
175 IMPORT_C TBool IsDaylightSavingOn(TTime& aTime) const;
176 IMPORT_C TInt GetOffsetFromRuleL(const TTime& aTime, TTzTimeReference aTimeRef) const;
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;
186 TInt32 iStartYear; // years covered by
187 TInt32 iEndYear; // the actualised rules
188 RArray<TVTzActualisedRule> iRules;