|
1 // Copyright (c) 1998-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 /** |
|
17 @file |
|
18 @internalAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 |
|
23 #ifndef __AGMCALENDARTIME_H__ |
|
24 #define __AGMCALENDARTIME_H__ |
|
25 |
|
26 #include <e32base.h> |
|
27 |
|
28 class CTzRules; |
|
29 class CTzConverter; |
|
30 class CAgnTlsProxy; |
|
31 class RReadStream; |
|
32 class RWriteStream; |
|
33 |
|
34 /** Interface class representing a time mode. |
|
35 A time mode can be floating, fixed to UTC, or fixed to a particular time zone (but that is not supported yet). |
|
36 This class provides functions to convert between UTC and the relevant local time. |
|
37 */ |
|
38 NONSHARABLE_CLASS(MAgnCalendarTimeMode) |
|
39 { |
|
40 public: |
|
41 enum TFormat {ELocal, EUtc, EFixedLocal}; // EFixedLocal indicate the local time that is associated with the rule of TAgnCalendarFixedUsingRulesTimeMode |
|
42 |
|
43 /** The time mode for a calendar entry */ |
|
44 enum TTimeMode |
|
45 { |
|
46 /** Floating time. */ |
|
47 EFloating, |
|
48 /** Fixed time in UTC format. When a fixed time entry is repeating, its repeat rule use EFixedTimeZone mode to store the corresponding time zone where the start and end time are stored in EFixedUtc. */ |
|
49 EFixedUtc, |
|
50 /** Timezone rule time mode. Currently, this is used only for repeating entry where the start and end time are stored in EFixedUtc more */ |
|
51 EFixedTimeZone, |
|
52 }; |
|
53 public: |
|
54 virtual void ToL(TFormat aFormat, TTime& aTime) const = 0; |
|
55 virtual void FromL(TFormat aFormat, TTime& aTime) const = 0; |
|
56 virtual TTimeMode TimeMode() const = 0; |
|
57 }; |
|
58 |
|
59 |
|
60 /** |
|
61 The main time class for use within Calendar. |
|
62 This stores either a fixed or floating time - a fixed time is stored as UTC, a floating time is stored as local. |
|
63 The offset between UTC and local is cached and updated when necessary. |
|
64 |
|
65 This class should be used as widely as possible throughout Calendar, eventually replacing the less useful TTime. |
|
66 TCalTime is an equivalent class to TAgnCalendarTime, but is exposed in the Calendar API. |
|
67 */ |
|
68 NONSHARABLE_CLASS(TAgnCalendarTime) |
|
69 { |
|
70 public: |
|
71 IMPORT_C TAgnCalendarTime(); |
|
72 |
|
73 IMPORT_C void SetFloatingL(const TTime& aTime); // sets floating time |
|
74 IMPORT_C void SetLocalL(const TTime& aTime); // sets fixed time |
|
75 IMPORT_C void SetUtcL(const TTime& aTime); // sets fixed time |
|
76 |
|
77 IMPORT_C TTime LocalL() const; |
|
78 IMPORT_C TTime UtcL() const; |
|
79 |
|
80 IMPORT_C TBool IsSet() const; // returns ETrue if non-NullTTime |
|
81 IMPORT_C TBool operator==(const TAgnCalendarTime& aTime) const; |
|
82 IMPORT_C TBool operator!=(const TAgnCalendarTime& aTime) const; |
|
83 IMPORT_C TBool operator<(const TAgnCalendarTime& aTime) const; |
|
84 IMPORT_C TBool operator>(const TAgnCalendarTime& aTime) const; |
|
85 IMPORT_C TBool operator<=(const TAgnCalendarTime& aTime) const; |
|
86 IMPORT_C TBool operator>=(const TAgnCalendarTime& aTime) const; |
|
87 |
|
88 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
89 IMPORT_C MAgnCalendarTimeMode::TTimeMode TimeMode() const; // return the time mode |
|
90 |
|
91 void SetNull(); |
|
92 IMPORT_C TBool IsValidTime() const; |
|
93 void ExternalizeL(RWriteStream& aStream) const; |
|
94 const MAgnCalendarTimeMode* CalendarTimeMode() const; |
|
95 |
|
96 // functions used in RArrays of TAgnCalendarTime |
|
97 static TInt Compare(const TAgnCalendarTime& aLeft, const TAgnCalendarTime& aRight); |
|
98 static void InsertInOrderL(RArray<TAgnCalendarTime>& aTimeArray, const TAgnCalendarTime& aTimeToInsert); |
|
99 static TBool CompareTimeArrays(const RArray<TAgnCalendarTime>* aLeft, const RArray<TAgnCalendarTime>* aRight); |
|
100 static void InternalizeTimeArrayL(RArray<TAgnCalendarTime>& aArray, RReadStream& aStream); |
|
101 static void ExternalizeTimeArrayL(RArray<TAgnCalendarTime>& aArray, RWriteStream& aStream); |
|
102 |
|
103 private: |
|
104 void StoreNewOffset(const TTime& aTime) const; |
|
105 CAgnTlsProxy* TimeZoneAccessor() const; |
|
106 |
|
107 void SetTzId(TUint16 aTzId) const; // Always use this to set the iTzId time zone variable |
|
108 TUint16 TzId() const; // Always use this to get the iTzId time zone variable |
|
109 void SetFloatingFlag(TBool aFloating) const; |
|
110 |
|
111 void SetDateTimeL(const TTime& aTime, TBool aFloating, MAgnCalendarTimeMode::TFormat aFormat = MAgnCalendarTimeMode::EUtc); |
|
112 TTime DateTimeL(MAgnCalendarTimeMode::TFormat aFormat) const; |
|
113 private: |
|
114 TTime iTime; // time stored as UTC or local depending on iCalendarMode |
|
115 mutable TInt16 iLocalOffsetInMinutes; |
|
116 mutable TUint16 iTzId; // caches current time zone ID AND floating status |
|
117 mutable CAgnTlsProxy* iTimeZoneAccessor; // not owned |
|
118 }; |
|
119 |
|
120 /** Concrete time mode class for fixed UTC time mode. |
|
121 */ |
|
122 NONSHARABLE_CLASS(TAgnCalendarFixedTimeMode) : public MAgnCalendarTimeMode |
|
123 { |
|
124 public: |
|
125 TAgnCalendarFixedTimeMode(CTzConverter& aTimeConverter); |
|
126 void ToL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const; |
|
127 void FromL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const; |
|
128 TTimeMode TimeMode() const; |
|
129 private: |
|
130 TAgnCalendarFixedTimeMode(const TAgnCalendarFixedTimeMode&); // not implemented |
|
131 TAgnCalendarFixedTimeMode& operator=(TAgnCalendarFixedTimeMode&); // not implemented |
|
132 private: |
|
133 CTzConverter& iTimeConverter; // not owned |
|
134 }; |
|
135 |
|
136 /** Concrete time mode class for 'fixed to time zone' time mode. |
|
137 */ |
|
138 NONSHARABLE_CLASS(TAgnCalendarFixedUsingRulesTimeMode) : public MAgnCalendarTimeMode |
|
139 { |
|
140 public: |
|
141 TAgnCalendarFixedUsingRulesTimeMode(CTzRules& aTimeZoneRules, CTzConverter& aTimeConverter); |
|
142 void ToL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const; |
|
143 void FromL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const; |
|
144 const CTzRules& TzZone() const; |
|
145 TTimeMode TimeMode() const; |
|
146 private: |
|
147 TAgnCalendarFixedUsingRulesTimeMode(const TAgnCalendarFixedUsingRulesTimeMode&); // not implemented |
|
148 TAgnCalendarFixedUsingRulesTimeMode& operator=(TAgnCalendarFixedUsingRulesTimeMode&); // not implemented |
|
149 private: |
|
150 const CTzRules& iTimeZoneRules; // not owned |
|
151 CTzConverter& iTimeConverter; // not owned |
|
152 }; |
|
153 |
|
154 /** Concrete time mode class for floating time mode. |
|
155 */ |
|
156 NONSHARABLE_CLASS(TAgnCalendarFloatingTimeMode) : public MAgnCalendarTimeMode |
|
157 { |
|
158 public: |
|
159 TAgnCalendarFloatingTimeMode(CTzConverter& aTimeConverter); |
|
160 void ToL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const; |
|
161 void FromL(MAgnCalendarTimeMode::TFormat aFormat, TTime& aTime) const; |
|
162 TTimeMode TimeMode() const; |
|
163 private: |
|
164 TAgnCalendarFloatingTimeMode(const TAgnCalendarFloatingTimeMode&); // not implemented |
|
165 TAgnCalendarFloatingTimeMode& operator=(TAgnCalendarFloatingTimeMode&); // not implemented |
|
166 private: |
|
167 CTzConverter& iTimeConverter; // not owned |
|
168 }; |
|
169 |
|
170 #endif |