|
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 /** |
|
17 @file |
|
18 @publishedAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 |
|
23 #include <caltime.h> |
|
24 |
|
25 // dependency on AgnModel for time constants and conversions |
|
26 #include "agmdate.h" |
|
27 |
|
28 /** Constructor for the TCalTime class. |
|
29 The time is initialised to Time::NullTTime(). |
|
30 |
|
31 @publishedAll |
|
32 @released |
|
33 @capability None |
|
34 */ |
|
35 EXPORT_C TCalTime::TCalTime() |
|
36 { |
|
37 iTime = Time::NullTTime(); |
|
38 iTimeMode = EFixedUtc; |
|
39 iReserved1 = 0; |
|
40 iReserved2 = 0; |
|
41 } |
|
42 |
|
43 /** |
|
44 Sets the time to a UTC value. Time values set using this API are said to be "fixed". |
|
45 Fixed times in UTC format can be converted to the equivalent local time in any time |
|
46 zone using RTz, or converted to the local time of the current system time zone by |
|
47 calling TimeLocalL(). This is described in RFC2445 as FORM #2: DATE WITH UTC TIME. |
|
48 |
|
49 @capability None |
|
50 @param aUtcTime The time to be set in UTC. |
|
51 @leave KErrArgument If the given time is not null but smaller than TCalTime::MinTime() or bigger than TCalTime::MaxTime() |
|
52 */ |
|
53 EXPORT_C void TCalTime::SetTimeUtcL(const TTime& aUtcTime) |
|
54 { |
|
55 if (aUtcTime != Time::NullTTime() && (aUtcTime < MinTime() || aUtcTime > MaxTime())) |
|
56 { |
|
57 User::Leave(KErrArgument); |
|
58 } |
|
59 iTime = aUtcTime; |
|
60 iTimeMode = static_cast<TUint8>(EFixedUtc); |
|
61 } |
|
62 |
|
63 /** |
|
64 Sets the time to a local time value bound to the current system time zone. Time values |
|
65 set using this API are said to be "fixed". The local time can be converted to an |
|
66 equivalent local time in any other time zone by calling TimeUtcL() and then converting |
|
67 the UTC time to the equivalent local time zone using RTz. This is described in RFC2445 |
|
68 as FORM #3: DATE WITH LOCAL TIME AND TIME ZONE REFERENCE. |
|
69 |
|
70 @capability None |
|
71 @param aLocalTime The time to be set in system-local time. |
|
72 @leave KErrArgument If the given time is not null but smaller than TCalTime::MinTime() or bigger than TCalTime::MaxTime() |
|
73 */ |
|
74 EXPORT_C void TCalTime::SetTimeLocalL(const TTime& aLocalTime) |
|
75 { |
|
76 TTime utcTime = AgnDateTime::ConvertToUtcTimeL(aLocalTime); |
|
77 if (utcTime != Time::NullTTime() && (utcTime < MinTime() || utcTime > MaxTime())) |
|
78 { |
|
79 User::Leave(KErrArgument); |
|
80 } |
|
81 iTime = utcTime; |
|
82 iTimeMode = static_cast<TUint8>(EFixedUtc); |
|
83 } |
|
84 |
|
85 /** |
|
86 Returns the fixed or floating time as UTC. |
|
87 |
|
88 @capability None |
|
89 @return The time in UTC. |
|
90 */ |
|
91 EXPORT_C TTime TCalTime::TimeUtcL() const |
|
92 { |
|
93 if (TimeMode() == EFloating) |
|
94 { |
|
95 return AgnDateTime::ConvertToUtcTimeL(iTime); |
|
96 } |
|
97 else |
|
98 { |
|
99 return iTime; |
|
100 } |
|
101 } |
|
102 |
|
103 /** |
|
104 Returns the fixed or floating time as local time. If the time is fixed, the time is converted to the local time of the |
|
105 current system time zone before being returned. |
|
106 |
|
107 @capability None |
|
108 @return The time in system-local time. |
|
109 */ |
|
110 EXPORT_C TTime TCalTime::TimeLocalL() const |
|
111 { |
|
112 if (TimeMode() == EFloating) |
|
113 { |
|
114 return iTime; |
|
115 } |
|
116 else |
|
117 { |
|
118 return AgnDateTime::ConvertToLocalTimeL(iTime); |
|
119 } |
|
120 } |
|
121 |
|
122 /** Get the maximum time allowed in the Interim API. |
|
123 Note that this time is the same for UTC and system local time - it can't be converted. |
|
124 |
|
125 @publishedAll |
|
126 @released |
|
127 @capability None |
|
128 @return The maximum time. |
|
129 */ |
|
130 EXPORT_C TTime TCalTime::MaxTime() |
|
131 { |
|
132 return AgnDateTime::MaxDate(); |
|
133 } |
|
134 |
|
135 /** Get the minimum time allowed in the Interim API. |
|
136 Note that this time is the same for UTC and system local time - it can't be converted. |
|
137 |
|
138 @publishedAll |
|
139 @released |
|
140 @capability None |
|
141 @return The minimum time. |
|
142 */ |
|
143 EXPORT_C TTime TCalTime::MinTime() |
|
144 { |
|
145 return AgnDateTime::MinDate(); |
|
146 } |
|
147 |
|
148 |
|
149 /** |
|
150 Sets the time to a local floating time value. Time values set using this API are said to be |
|
151 "floating" and are not bound to any time zone in particular. Floating time is |
|
152 used to represent the same time regardless of which time zone it is currently being |
|
153 observed from. This is described in RFC2445 as FORM #1: DATE WITH LOCAL TIME. |
|
154 |
|
155 @publishedAll |
|
156 @released |
|
157 |
|
158 @capability None |
|
159 @param aLocalTime The time to be set in floating local time. |
|
160 @leave KErrArgument If the given time is not null but smaller than TCalTime::MinTime() or bigger than TCalTime::MaxTime() |
|
161 */ |
|
162 EXPORT_C void TCalTime::SetTimeLocalFloatingL(const TTime& aLocalTime) |
|
163 { |
|
164 if (aLocalTime != Time::NullTTime() && (aLocalTime < MinTime() || aLocalTime > MaxTime())) |
|
165 { |
|
166 User::Leave(KErrArgument); |
|
167 } |
|
168 iTime = aLocalTime; |
|
169 iTimeMode = static_cast<TUint8>(EFloating); |
|
170 } |
|
171 |
|
172 /** |
|
173 Returns the time mode that the time has been set to, whether it be floating local time, |
|
174 fixed UTC time, or fixed local time. |
|
175 |
|
176 @publishedAll |
|
177 @released |
|
178 |
|
179 @return Time mode of the calendar time |
|
180 */ |
|
181 EXPORT_C TCalTime::TTimeMode TCalTime::TimeMode() const |
|
182 { |
|
183 return static_cast<TTimeMode>(iTimeMode); |
|
184 } |