|
1 // Copyright (c) 1999-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 #include <e32base.h> |
|
18 #include <e32std.h> |
|
19 #include <msvstd.h> |
|
20 #include <msventry.h> |
|
21 #include <msvoffpeaktime.h> |
|
22 #include <schsend_panic.h> |
|
23 |
|
24 |
|
25 // |
|
26 // |
|
27 // Type Class TMsvOffPeakTime |
|
28 // |
|
29 // |
|
30 |
|
31 /** |
|
32 Default constructor. |
|
33 */ |
|
34 |
|
35 EXPORT_C TMsvOffPeakTime::TMsvOffPeakTime() |
|
36 { |
|
37 Reset(); |
|
38 } |
|
39 |
|
40 |
|
41 /** |
|
42 Constructor specifying off-peak time parameters. |
|
43 Note that the offpeak start time must be specified in UTC (Universal Time Coordinated)time. |
|
44 |
|
45 @param aDay |
|
46 Day start time. |
|
47 |
|
48 @param aHour |
|
49 Hour start time. |
|
50 |
|
51 @param aMinute |
|
52 Minute start time. |
|
53 |
|
54 @param aValidityPeriod |
|
55 Duration (in minutes). |
|
56 */ |
|
57 |
|
58 EXPORT_C TMsvOffPeakTime::TMsvOffPeakTime(const TDay aDay, const TInt aHour, const TInt aMinute, const TTimeIntervalMinutes aValidityPeriod) |
|
59 { |
|
60 SetDay(aDay); |
|
61 SetHour(aHour); |
|
62 SetMinute(aMinute); |
|
63 SetValidityPeriod(aValidityPeriod); |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 Resets the object to default settings. |
|
69 */ |
|
70 |
|
71 EXPORT_C void TMsvOffPeakTime::Reset() |
|
72 { |
|
73 iHour = 0; |
|
74 iMinute = 0; |
|
75 iDay = EMonday; |
|
76 iValidityPeriod = (TTimeIntervalMinutes) 0; |
|
77 } |
|
78 |
|
79 |
|
80 /* |
|
81 Hour Access Functions |
|
82 */ |
|
83 |
|
84 /** |
|
85 Gets the start time hour parameter. |
|
86 |
|
87 @return Start time hour parameter |
|
88 */ |
|
89 |
|
90 EXPORT_C TInt TMsvOffPeakTime::Hour() const |
|
91 { |
|
92 return iHour; |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 Sets the start time hour parameter. |
|
98 Note that the offpeak start time must be specified in UTC (Universal Time Coordinated)time. |
|
99 |
|
100 @param aHour |
|
101 Start time hour parameter. |
|
102 |
|
103 @panic ScheduleSend-DLL 12 |
|
104 The hour parameter is invalid (negative or more than 23). |
|
105 */ |
|
106 |
|
107 EXPORT_C void TMsvOffPeakTime::SetHour(const TInt aHour) |
|
108 { |
|
109 __ASSERT_ALWAYS((aHour >= 0) && (aHour < 24), gPanic(EInvalidHour)); |
|
110 |
|
111 iHour = (TInt8) aHour; |
|
112 } |
|
113 |
|
114 |
|
115 /* |
|
116 Minute Access Functions |
|
117 */ |
|
118 |
|
119 /** |
|
120 Gets the start time minute parameter. |
|
121 |
|
122 @return Start time minute parameter. |
|
123 */ |
|
124 |
|
125 EXPORT_C TInt TMsvOffPeakTime::Minute() const |
|
126 { |
|
127 return iMinute; |
|
128 } |
|
129 |
|
130 |
|
131 /** |
|
132 Sets the start time minute parameter. |
|
133 Note that the offpeak start time must be specified in UTC (Universal Time Coordinated)time. |
|
134 |
|
135 @param aMinute |
|
136 Start time minute parameter. |
|
137 |
|
138 @panic ScheduleSend-DLL 13 |
|
139 The minute parameter is invalid (negative or more than 59). |
|
140 */ |
|
141 |
|
142 EXPORT_C void TMsvOffPeakTime::SetMinute(const TInt aMinute) |
|
143 { |
|
144 __ASSERT_ALWAYS((aMinute >= 0) && (aMinute < 60), gPanic(EInvalidMinute)); |
|
145 |
|
146 iMinute = (TInt8) aMinute; |
|
147 } |
|
148 |
|
149 |
|
150 /* |
|
151 Day Access Functions |
|
152 */ |
|
153 |
|
154 /** |
|
155 Gets the start time day parameter. |
|
156 |
|
157 @return Start time day parameter. |
|
158 */ |
|
159 |
|
160 EXPORT_C TDay TMsvOffPeakTime::Day() const |
|
161 { |
|
162 return iDay; |
|
163 } |
|
164 |
|
165 |
|
166 /** |
|
167 Sets the start time day parameter. |
|
168 Note that the offpeak start time must be specified in UTC (Universal Time Coordinated)time. |
|
169 |
|
170 @param aDay |
|
171 Start time day parameter. |
|
172 */ |
|
173 |
|
174 EXPORT_C void TMsvOffPeakTime::SetDay(const TDay aDay) |
|
175 { |
|
176 iDay = aDay; |
|
177 } |
|
178 |
|
179 |
|
180 /* |
|
181 ValidityPeriod Access Functions |
|
182 */ |
|
183 |
|
184 /** |
|
185 Gets the duration parameter. |
|
186 |
|
187 @return Duration parameter. |
|
188 */ |
|
189 |
|
190 EXPORT_C const TTimeIntervalMinutes TMsvOffPeakTime::ValidityPeriod() const |
|
191 { |
|
192 return iValidityPeriod; |
|
193 } |
|
194 |
|
195 |
|
196 /** |
|
197 Sets the duration parameter. |
|
198 |
|
199 @param aValidityPeriod |
|
200 Duration parameter. |
|
201 |
|
202 @panic ScheduleSend-DLL 10 |
|
203 The duration period is invalid (negative or more than 24 hours). |
|
204 */ |
|
205 |
|
206 EXPORT_C void TMsvOffPeakTime::SetValidityPeriod(const TTimeIntervalMinutes aValidityPeriod) |
|
207 { |
|
208 __ASSERT_ALWAYS((aValidityPeriod.Int() >= 0) && (aValidityPeriod.Int() <= (24 * 60)), gPanic(EInvalidValidityPeriod)); |
|
209 |
|
210 iValidityPeriod = aValidityPeriod; |
|
211 } |
|
212 |
|
213 |
|
214 |
|
215 /** |
|
216 Gets the next time, after a specified time, when this off-peak time becomes |
|
217 active. |
|
218 |
|
219 If aFromTime is within the validity period of this off-peak time, then the |
|
220 next time will be less than or equal to aFromTime. |
|
221 |
|
222 @param aFromTime |
|
223 Specified time. |
|
224 |
|
225 @return Next time |
|
226 */ |
|
227 |
|
228 EXPORT_C const TTime TMsvOffPeakTime::NextTimeInclusive(const TTime& aFromTime) const |
|
229 { |
|
230 TTime nextTime = aFromTime; |
|
231 TDateTime from = nextTime.DateTime(); |
|
232 |
|
233 from.SetHour(iHour); |
|
234 from.SetMinute(iMinute); |
|
235 from.SetSecond(0); |
|
236 from.SetMicroSecond(0); |
|
237 |
|
238 nextTime = TTime(from); |
|
239 |
|
240 while (nextTime.DayNoInWeek() != iDay || nextTime > aFromTime) |
|
241 { |
|
242 nextTime -= (TTimeIntervalDays) 1; |
|
243 } |
|
244 |
|
245 TTimeIntervalMinutes mins; |
|
246 aFromTime.MinutesFrom(nextTime, mins); |
|
247 |
|
248 __ASSERT_DEBUG(mins.Int() >= 0, gPanic(EProgrammingBug)); |
|
249 |
|
250 //mins must be greater than or equal to zero (0) because of the above while loop |
|
251 if (mins.Int() < iValidityPeriod.Int()) //TO DO: Perhaps <= instead |
|
252 { |
|
253 return nextTime; |
|
254 } |
|
255 |
|
256 while (nextTime < aFromTime) |
|
257 { |
|
258 nextTime += (TTimeIntervalDays) 7; |
|
259 } |
|
260 |
|
261 return nextTime; |
|
262 } |
|
263 |
|
264 |
|
265 // |
|
266 // |
|
267 // Class CMsvOffPeakTimes |
|
268 // |
|
269 // |
|
270 |
|
271 /** |
|
272 Default constructor. |
|
273 */ |
|
274 |
|
275 EXPORT_C CMsvOffPeakTimes::CMsvOffPeakTimes() |
|
276 : CArrayFixFlat<TMsvOffPeakTime>(1) |
|
277 { |
|
278 } |
|
279 |
|
280 |
|
281 /** |
|
282 Gets the off-peak time period that is after and closest to a specified time. |
|
283 |
|
284 If aFromTime is within an off-peak time period, then that off-peak time period |
|
285 is returned. |
|
286 |
|
287 @param aFromTime |
|
288 Time to find. |
|
289 |
|
290 @param aNext |
|
291 On return, the off-peak time period that is closest to aFromTime. |
|
292 |
|
293 @param aNextTime |
|
294 On return, the next start of aNext from aFromTime. |
|
295 |
|
296 @see TMsvOffPeakTime::NextTimeInclusive() for details. |
|
297 |
|
298 @return KErrNotFound The array does not contain any off-peak time periods. |
|
299 */ |
|
300 |
|
301 EXPORT_C TInt CMsvOffPeakTimes::GetNextOffPeakTime(const TTime& aFromTime, TMsvOffPeakTime& aNext, TTime& aNextTime) const |
|
302 { |
|
303 const TInt count = Count(); |
|
304 |
|
305 if (count < 1) |
|
306 { |
|
307 return KErrNotFound; |
|
308 } |
|
309 |
|
310 aNext = At(0); |
|
311 aNextTime = aNext.NextTimeInclusive(aFromTime); |
|
312 |
|
313 for (TInt curTime = 1; curTime < count; curTime++) |
|
314 { |
|
315 TMsvOffPeakTime time = At(curTime); |
|
316 TTime tempTime = time.NextTimeInclusive(aFromTime); |
|
317 |
|
318 if (tempTime < aNextTime) |
|
319 { |
|
320 aNextTime = tempTime; |
|
321 aNext = time; |
|
322 } |
|
323 } |
|
324 |
|
325 return KErrNone; |
|
326 } |
|
327 |