|
1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Utility class providing utility functions to know beginning of the day, maximum/minimum date allowed in calendar, |
|
15 * day range, on same day, on same month etc. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 //debug |
|
22 #include "calendarui_debug.h" |
|
23 |
|
24 #include <calendateutils.h> |
|
25 #include <caltime.h> // For Min/MaxValidDate |
|
26 |
|
27 // LOCAL CONSTANTS AND MACROS |
|
28 const TInt KDefaultStartTime(8); // 8 am |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS ============================== |
|
31 |
|
32 // ============================ CalenDateUtils ============================== |
|
33 // ----------------------------------------------------------------------------- |
|
34 // ?classname::?member_function |
|
35 // ?implementation_description |
|
36 // (other items were commented in a header). |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C TBool CalenDateUtils::OnSameDay( const TTime& aX, const TTime& aY ) |
|
40 { |
|
41 TRACE_ENTRY_POINT; |
|
42 |
|
43 TDateTime x = aX.DateTime(); |
|
44 TDateTime y = aY.DateTime(); |
|
45 |
|
46 TRACE_EXIT_POINT; |
|
47 return x.Year() == y.Year() |
|
48 && x.Month() == y.Month() |
|
49 && x.Day() == y.Day(); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ?classname::?member_function |
|
54 // ?implementation_description |
|
55 // (other items were commented in a header). |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C TBool CalenDateUtils::OnSameMonth( const TTime& aX, const TTime& aY ) |
|
59 { |
|
60 TRACE_ENTRY_POINT; |
|
61 |
|
62 TDateTime x = aX.DateTime(); |
|
63 TDateTime y = aY.DateTime(); |
|
64 |
|
65 TRACE_EXIT_POINT; |
|
66 return ( x.Year() == y.Year() && x.Month() == y.Month() ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // ?classname::?member_function |
|
71 // ?implementation_description |
|
72 // (other items were commented in a header). |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C TTime CalenDateUtils::BeginningOfDay( const TTime& aStartTime ) |
|
76 { |
|
77 TRACE_ENTRY_POINT; |
|
78 |
|
79 TTime zero(TInt64(0)); |
|
80 |
|
81 TRACE_EXIT_POINT; |
|
82 return zero + aStartTime.DaysFrom( zero ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // ?classname::?member_function |
|
87 // ?implementation_description |
|
88 // (other items were commented in a header). |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C TTime CalenDateUtils::DisplayTimeOnDay( const TTime& aStartTime, |
|
92 const TTime& aDay ) |
|
93 { |
|
94 TRACE_ENTRY_POINT; |
|
95 |
|
96 if( ! OnSameDay( aStartTime, aDay ) ) |
|
97 { |
|
98 TRACE_EXIT_POINT; |
|
99 return BeginningOfDay( aDay ); |
|
100 } |
|
101 else |
|
102 { |
|
103 TRACE_EXIT_POINT; |
|
104 return aStartTime; |
|
105 } |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // ?classname::?member_function |
|
110 // ?implementation_description |
|
111 // (other items were commented in a header). |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C TBool CalenDateUtils::TimeRangesIntersect( const TTime& aXStart, |
|
115 const TTime& aXEnd, |
|
116 const TTime& aYStart, |
|
117 const TTime& aYEnd ) |
|
118 { |
|
119 TRACE_ENTRY_POINT; |
|
120 |
|
121 TRACE_EXIT_POINT; |
|
122 return (! ( aYEnd <= aXStart || aXEnd <= aYStart )) |
|
123 || (aXStart == aXEnd && aYStart <= aXStart && aXStart < aYEnd) |
|
124 || (aYStart == aYEnd && aXStart <= aYStart && aYStart < aXEnd) |
|
125 || (aXStart == aXEnd && aYStart == aYEnd && aXStart == aYStart); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // ?classname::?member_function |
|
130 // ?implementation_description |
|
131 // (other items were commented in a header). |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C TBool CalenDateUtils::IsValidDay( const TTime& aTime ) |
|
135 { |
|
136 TRACE_ENTRY_POINT; |
|
137 |
|
138 // Interim API supports range from 1900-2100, |
|
139 TRACE_EXIT_POINT; |
|
140 return ( MinTime() <= aTime && aTime <= MaxTime() ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // ?classname::?member_function |
|
145 // ?implementation_description |
|
146 // (other items were commented in a header). |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C void CalenDateUtils::GetDayRangeL( const TTime& aStartDay, |
|
150 const TTime& aEndDay, |
|
151 CalCommon::TCalTimeRange& aRange ) |
|
152 { |
|
153 TRACE_ENTRY_POINT; |
|
154 |
|
155 TDateTime start( aStartDay.DateTime() ); |
|
156 TDateTime end( aEndDay.DateTime() ); |
|
157 |
|
158 start.SetHour( 0 ); |
|
159 start.SetMinute( 0 ); |
|
160 start.SetSecond( 0 ); |
|
161 start.SetMicroSecond( 0 ); |
|
162 |
|
163 end.SetHour( 23 ); |
|
164 end.SetMinute( 59 ); |
|
165 end.SetSecond( 59 ); |
|
166 end.SetMicroSecond( 0 ); |
|
167 |
|
168 // prevent overflow |
|
169 TCalTime endDate; |
|
170 endDate.SetTimeLocalL( LimitToValidTime( TTime( end ) ) ); |
|
171 |
|
172 TCalTime startDate; |
|
173 startDate.SetTimeLocalL( LimitToValidTime( TTime( start ) ) ); |
|
174 |
|
175 CalCommon::TCalTimeRange dayrange( startDate, endDate ); |
|
176 |
|
177 aRange = dayrange; |
|
178 |
|
179 TRACE_EXIT_POINT; |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // ?classname::?member_function |
|
184 // ?implementation_description |
|
185 // (other items were commented in a header). |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C TBool CalenDateUtils::IsNullTimeL( TCalTime& aTime ) |
|
189 { |
|
190 TRACE_ENTRY_POINT; |
|
191 |
|
192 TRACE_EXIT_POINT; |
|
193 return( aTime.TimeLocalL() == Time::NullTTime() ); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // ?classname::?member_function |
|
198 // ?implementation_description |
|
199 // (other items were commented in a header). |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C TTime CalenDateUtils::LimitToValidTime( const TTime& aTime ) |
|
203 { |
|
204 TRACE_ENTRY_POINT; |
|
205 |
|
206 TTime valid = aTime; |
|
207 valid = valid > MaxTime() ? MaxTime() : valid; |
|
208 valid = valid < MinTime() ? MinTime() : valid; |
|
209 |
|
210 TRACE_EXIT_POINT; |
|
211 return valid; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // ?classname::?member_function |
|
216 // Returns maximum time allowed, 31.12.2100 0:00 is max so 30.12.2100 is last actual |
|
217 // date to be used. |
|
218 // (other items were commented in a header). |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 EXPORT_C TTime CalenDateUtils::MaxTime() |
|
222 { |
|
223 TRACE_ENTRY_POINT; |
|
224 |
|
225 TTime time( TCalTime::MaxTime() - TTimeIntervalMinutes( 1 ) ); |
|
226 |
|
227 TRACE_EXIT_POINT; |
|
228 return time; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // ?classname::?member_function |
|
233 // Returns minimum time allowed, 1.1.1900 0:00 is min |
|
234 // (other items were commented in a header). |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C TTime CalenDateUtils::MinTime() |
|
238 { |
|
239 TRACE_ENTRY_POINT; |
|
240 |
|
241 TRACE_EXIT_POINT; |
|
242 return TCalTime::MinTime(); |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // (other items were commented in a header). |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C TTimeIntervalMinutes CalenDateUtils::TimeOfDay( const TTime& aDateTime ) |
|
250 { |
|
251 TRACE_ENTRY_POINT; |
|
252 |
|
253 TTime midnight = CalenDateUtils::BeginningOfDay( aDateTime ); |
|
254 TTimeIntervalMinutes result; |
|
255 aDateTime.MinutesFrom( midnight, result ); |
|
256 |
|
257 TRACE_EXIT_POINT; |
|
258 return result; |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // (other items were commented in a header). |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 EXPORT_C TTime CalenDateUtils::RoundToPreviousHour( const TTime& aTime ) |
|
266 { |
|
267 TRACE_ENTRY_POINT; |
|
268 |
|
269 TDateTime dt = aTime.DateTime(); |
|
270 dt.SetMinute(0); |
|
271 dt.SetSecond(0); |
|
272 dt.SetMicroSecond(0); |
|
273 |
|
274 TRACE_EXIT_POINT; |
|
275 return TTime( dt ); |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // (other items were commented in a header). |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 EXPORT_C TTimeIntervalMinutes CalenDateUtils::RoundToPreviousHour( const TTimeIntervalMinutes& aMinutes ) |
|
283 { |
|
284 TRACE_ENTRY_POINT; |
|
285 |
|
286 TRACE_EXIT_POINT; |
|
287 return TTimeIntervalMinutes( (aMinutes.Int() / 60) * 60 ); |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // (other items were commented in a header). |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 EXPORT_C TTime CalenDateUtils::Now() |
|
295 { |
|
296 TRACE_ENTRY_POINT; |
|
297 |
|
298 TTime now; |
|
299 now.HomeTime(); |
|
300 |
|
301 TRACE_EXIT_POINT; |
|
302 return now; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // (other items were commented in a header). |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 EXPORT_C TTime CalenDateUtils::Today() |
|
310 { |
|
311 TRACE_ENTRY_POINT; |
|
312 |
|
313 TRACE_EXIT_POINT; |
|
314 return CalenDateUtils::BeginningOfDay( Now() ); |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // (other items were commented in a header). |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C TBool CalenDateUtils::IsOnToday( const TTime& aTime ) |
|
322 { |
|
323 TRACE_ENTRY_POINT; |
|
324 |
|
325 TRACE_EXIT_POINT; |
|
326 return CalenDateUtils::OnSameDay( aTime, Today() ); |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // (other items were commented in a header). |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 EXPORT_C TTime CalenDateUtils::DefaultTime( const TTime& aDate ) |
|
334 { |
|
335 TRACE_ENTRY_POINT; |
|
336 |
|
337 TTime dateTime( Time::NullTTime() ); |
|
338 // DD:MM:YY @ hh:mm:ss |
|
339 dateTime = CalenDateUtils::BeginningOfDay( aDate ); |
|
340 // DD:MM:YY @ 00:00:00 |
|
341 dateTime += TTimeIntervalHours( KDefaultStartTime ); // DD:MM:YY @ 08:00 am |
|
342 |
|
343 TRACE_EXIT_POINT; |
|
344 return dateTime; |
|
345 } |
|
346 |
|
347 // End of File |