|
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 #include <e32def.h> |
|
17 #include <s32strm.h> |
|
18 #include "SCHTIME.H" |
|
19 #include "SCHEXEC.H" |
|
20 |
|
21 /** |
|
22 UTC/Local Time flag value |
|
23 @internalComponent |
|
24 */ |
|
25 const TUint32 KIsUtc = 0x00000001; |
|
26 |
|
27 /** |
|
28 Default constructor for TTsTime. |
|
29 This constructor initialises its member data to zero. |
|
30 By default this sets it to be UTC based. |
|
31 */ |
|
32 EXPORT_C TTsTime::TTsTime(): |
|
33 iUtcTime(0), |
|
34 iOffset(0), |
|
35 iFlags(KIsUtc) |
|
36 { |
|
37 } |
|
38 |
|
39 /** |
|
40 Copy constructor for TTsTime |
|
41 @param aTTsTime value to duplicate |
|
42 */ |
|
43 EXPORT_C TTsTime::TTsTime(const TTsTime& aTTsTime) |
|
44 { |
|
45 *this = aTTsTime; |
|
46 } |
|
47 |
|
48 /** |
|
49 Constructs a TTsTime with a TTime. |
|
50 If the iIsUtc is ETrue, then TTsTime is UTC based time, if iIsUtc is EFalse |
|
51 then TTsTime is local time based. This constructor will update all the member data as appropriate. |
|
52 @param aTime The TTime value |
|
53 @param aIsUtc is Etrue when aTime is UTC and EFalse when aTime is local time. |
|
54 */ |
|
55 EXPORT_C TTsTime::TTsTime(const TTime& aTime, TBool aIsUtc) |
|
56 { |
|
57 // if the time passed as argument is UTC based |
|
58 if(aIsUtc) |
|
59 SetUtcTime(aTime); |
|
60 |
|
61 // if the time passed is local time |
|
62 else |
|
63 SetLocalTime(aTime); |
|
64 } |
|
65 |
|
66 /** |
|
67 Sets this object to a local time based value updating its parameters as appropriate. |
|
68 @param aLocalTime The local time to be set. |
|
69 */ |
|
70 EXPORT_C void TTsTime::SetLocalTime(const TTime& aLocalTime) |
|
71 { |
|
72 iOffset = User::UTCOffset(); // sets the current UTC offset to iOffset |
|
73 iUtcTime = aLocalTime - iOffset; // converts the given aLocalTime to a UTC time value |
|
74 iFlags &= ~KIsUtc; //set the Bit 0 to zero for Local Time |
|
75 } |
|
76 |
|
77 /** |
|
78 Sets this object to a UTC time based value updating its parameters as appropriate. |
|
79 @param aUtcTime The UTC time to be set |
|
80 */ |
|
81 EXPORT_C void TTsTime::SetUtcTime(const TTime& aUtcTime) |
|
82 { |
|
83 iUtcTime = aUtcTime; |
|
84 iOffset = 0; |
|
85 iFlags |= KIsUtc; //set the Bit 0 to one as TTsTime is UTC |
|
86 } |
|
87 |
|
88 /** |
|
89 This function returns a home time value. |
|
90 @return Retrieves time from object in local time |
|
91 */ |
|
92 EXPORT_C const TTime TTsTime::GetLocalTime() |
|
93 { |
|
94 return DetermineLocalTime(); |
|
95 } |
|
96 |
|
97 /** |
|
98 This function returns a home time value. |
|
99 @return Retrieves time from object in local time |
|
100 */ |
|
101 EXPORT_C TTime TTsTime::GetLocalTime() const |
|
102 { |
|
103 return DetermineLocalTime(); |
|
104 } |
|
105 |
|
106 /** |
|
107 This function returns a UTC value. |
|
108 @return Returns the UTC time value. |
|
109 */ |
|
110 EXPORT_C const TTime& TTsTime::GetUtcTime() |
|
111 { |
|
112 return iUtcTime; |
|
113 } |
|
114 |
|
115 /** |
|
116 This function returns a UTC value. |
|
117 @return Returns the UTC time value. |
|
118 */ |
|
119 EXPORT_C const TTime& TTsTime::GetUtcTime() const |
|
120 { |
|
121 return iUtcTime; |
|
122 } |
|
123 |
|
124 /** |
|
125 @return ETrue, if TTsTime object is UTC and EFalse if TTsTime object is local time |
|
126 */ |
|
127 EXPORT_C TBool TTsTime::IsUtc() const |
|
128 { |
|
129 return iFlags & KIsUtc ? ETrue: EFalse; |
|
130 } |
|
131 |
|
132 |
|
133 /** |
|
134 This function returns a home time value. |
|
135 If UTC based returns UTC time + User::UTCOffset(). If local time based returns |
|
136 local time of the object. |
|
137 @internalComponent |
|
138 */ |
|
139 TTime TTsTime::DetermineLocalTime() const |
|
140 { |
|
141 TTime localTime; |
|
142 if(IsUtc()) |
|
143 localTime = iUtcTime+User::UTCOffset(); |
|
144 else |
|
145 localTime = iUtcTime+iOffset; |
|
146 |
|
147 return localTime; |
|
148 } |
|
149 |
|
150 /** |
|
151 This class does not explicitly update iOffSet if the system TimeZone/DST offset changes. |
|
152 When called this API will update the object if the system TimeZone/DST offset has changed. |
|
153 Keeping the offset in objects of this class correct is the responsibility of the |
|
154 Task Scheduler server.This applies to local time objects only. UTC objects will be unaffected. |
|
155 @internalComponent |
|
156 */ |
|
157 void TTsTime::ProcessOffsetEvent() |
|
158 { |
|
159 if(iFlags & KIsUtc) |
|
160 return; |
|
161 |
|
162 TTimeIntervalSeconds kernelOffset = User::UTCOffset(); |
|
163 |
|
164 // check if there was an offset event happened without TTsTime being updated |
|
165 // localTime will always be the addition of UTC time and kernel offset |
|
166 if (iOffset != kernelOffset) |
|
167 { |
|
168 // If TTsTime is home time and there was a time zone change then TTsTime needs to be update. |
|
169 // If not then TTsTime remains the same, as UTC times are the same everywhere. |
|
170 iUtcTime = (iUtcTime+iOffset) - kernelOffset; |
|
171 iOffset = kernelOffset; |
|
172 } |
|
173 } |
|
174 /** |
|
175 Overloaded assignment operator for TTsTime |
|
176 @param aTsTime time value to copy |
|
177 */ |
|
178 EXPORT_C TTsTime& TTsTime::operator=(const TTsTime& aTsTime) |
|
179 { |
|
180 Mem::Copy(this,&aTsTime,sizeof(*this)); |
|
181 return *this; |
|
182 } |
|
183 |
|
184 /** |
|
185 Uses the standard template operator>>() to internalize the object from aStream. |
|
186 Additionally this method will ensure that the object is updated in the event that |
|
187 the system TimeZone/DST offset changed since it was externalised. |
|
188 @internalComponent |
|
189 */ |
|
190 void TTsTime::InternalizeL(RReadStream& aStream) |
|
191 { |
|
192 TInt32 offset; |
|
193 TInt64 utcTime; |
|
194 |
|
195 // Updates TTsTime if local time based and the system Timezone/DST change occurred. |
|
196 ProcessOffsetEvent(); |
|
197 |
|
198 aStream >> utcTime; |
|
199 iUtcTime = TTime(utcTime); |
|
200 aStream >> offset; |
|
201 iOffset = offset; |
|
202 aStream >> iFlags; |
|
203 } |
|
204 |
|
205 /** |
|
206 Uses the standard template operator>>() to externalize the object to aStream |
|
207 @internalComponent |
|
208 */ |
|
209 void TTsTime::ExternalizeL(RWriteStream& aStream) const |
|
210 { |
|
211 aStream << iUtcTime.Int64(); |
|
212 aStream.WriteInt32L(iOffset.Int()); |
|
213 aStream.WriteUint32L(iFlags); |
|
214 } |