|
1 // Copyright (c) 1996-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 the License "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 // e32test\datetime\t_tparse.cpp |
|
15 // Overview: |
|
16 // Date & time tests |
|
17 // API Information: |
|
18 // TTime, TDateTime |
|
19 // Details: |
|
20 // - Set various locale settings to known values. |
|
21 // - Test parsing a variety of simple time formats. Verify results are as expected. |
|
22 // - Test parsing a variety of simple date formats. Verify results are as expected. |
|
23 // - Test parsing a variety of date and time formats. Verify results are as expected. |
|
24 // - Attempt to parse a variety of bad date and time descriptors. Verify the error |
|
25 // results are as expected. |
|
26 // - Test a variety of date and time locale changes. Verify results are as expected. |
|
27 // Platforms/Drives/Compatibility: |
|
28 // All. |
|
29 // Assumptions/Requirement/Pre-requisites: |
|
30 // Failures and causes: |
|
31 // Base Port information: |
|
32 // |
|
33 // |
|
34 |
|
35 #include <e32test.h> |
|
36 |
|
37 RTest test(_L("T_TPARSE")); |
|
38 |
|
39 LOCAL_C TInt DateTimeParse(TDateTime& aDateTime,const TDesC& aDes,TInt aCenturyOffset=0) |
|
40 { |
|
41 |
|
42 TTime time; |
|
43 TInt r=time.Parse(aDes,aCenturyOffset); |
|
44 if (r>=0) |
|
45 aDateTime=time.DateTime(); |
|
46 return r; |
|
47 } |
|
48 |
|
49 LOCAL_D void SimpleTimeFormats() |
|
50 { |
|
51 |
|
52 TInt error; |
|
53 TDateTime dateTime; |
|
54 error=DateTimeParse(dateTime,_L("23:34:45:56")); |
|
55 test(error==EParseTimePresent); |
|
56 test(dateTime.Hour()==23); |
|
57 test(dateTime.Minute()==34); |
|
58 test(dateTime.Second()==45); |
|
59 test(dateTime.MicroSecond()==56); |
|
60 |
|
61 error=DateTimeParse(dateTime,_L("23:34:45.56")); |
|
62 test(error==EParseTimePresent); |
|
63 test(dateTime.Hour()==23); |
|
64 test(dateTime.Minute()==34); |
|
65 test(dateTime.Second()==45); |
|
66 test(dateTime.MicroSecond()==56); |
|
67 |
|
68 error=DateTimeParse(dateTime,_L("23:34:45.1234567")); |
|
69 test(error==KErrGeneral); |
|
70 |
|
71 error=DateTimeParse(dateTime,_L("23:34:45")); |
|
72 test(error==EParseTimePresent); |
|
73 test(dateTime.Hour()==23); |
|
74 test(dateTime.Minute()==34); |
|
75 test(dateTime.Second()==45); |
|
76 test(dateTime.MicroSecond()==0); |
|
77 |
|
78 error=DateTimeParse(dateTime,_L("00023:00034")); |
|
79 test(error==EParseTimePresent); |
|
80 test(dateTime.Hour()==23); |
|
81 test(dateTime.Minute()==34); |
|
82 test(dateTime.Second()==00); |
|
83 test(dateTime.MicroSecond()==0); |
|
84 |
|
85 error=DateTimeParse(dateTime,_L("23: 34")); |
|
86 test(error==EParseTimePresent); |
|
87 test(dateTime.Hour()==23); |
|
88 test(dateTime.Minute()==34); |
|
89 test(dateTime.Second()==0); |
|
90 test(dateTime.MicroSecond()==0); |
|
91 |
|
92 error=DateTimeParse(dateTime,_L("23: 34am")); |
|
93 test(error==EParseTimePresent); |
|
94 test(dateTime.Hour()==23); |
|
95 test(dateTime.Minute()==34); |
|
96 test(dateTime.Second()==0); |
|
97 test(dateTime.MicroSecond()==0); |
|
98 |
|
99 error=DateTimeParse(dateTime,_L("23: 34AM")); |
|
100 test(error==EParseTimePresent); |
|
101 test(dateTime.Hour()==23); |
|
102 test(dateTime.Minute()==34); |
|
103 test(dateTime.Second()==0); |
|
104 test(dateTime.MicroSecond()==0); |
|
105 |
|
106 error=DateTimeParse(dateTime,_L(" 23 : 34 ")); |
|
107 test(error==EParseTimePresent); |
|
108 test(dateTime.Hour()==23); |
|
109 test(dateTime.Minute()==34); |
|
110 test(dateTime.Second()==0); |
|
111 test(dateTime.MicroSecond()==0); |
|
112 |
|
113 DateTimeParse(dateTime,_L("12 . 34")); |
|
114 test(dateTime.Hour()==12); |
|
115 test(dateTime.Minute()==34); |
|
116 |
|
117 error=DateTimeParse(dateTime,_L("23:34:")); |
|
118 test(error==KErrArgument); |
|
119 |
|
120 error=DateTimeParse(dateTime,_L(" 0012 : 00034 . 056")); |
|
121 test(error==EParseTimePresent); |
|
122 test(dateTime.Hour()==12); |
|
123 test(dateTime.Minute()==34); |
|
124 test(dateTime.Second()==56); |
|
125 test(dateTime.MicroSecond()==0); |
|
126 |
|
127 error=DateTimeParse(dateTime,_L("24 : 56")); |
|
128 test(error==KErrGeneral);// TDateTime class does not allow 24:56 |
|
129 |
|
130 error=DateTimeParse(dateTime,_L("10")); |
|
131 test(error==KErrArgument); |
|
132 |
|
133 error=DateTimeParse(dateTime,_L("10a")); |
|
134 test(error==EParseTimePresent); |
|
135 test(dateTime.Hour()==10); |
|
136 |
|
137 error=DateTimeParse(dateTime,_L("10p")); |
|
138 test(error==EParseTimePresent); |
|
139 test(dateTime.Hour()==22); |
|
140 |
|
141 error=DateTimeParse(dateTime,_L("10 p")); |
|
142 test(error==EParseTimePresent); |
|
143 test(dateTime.Hour()==22); |
|
144 |
|
145 error=DateTimeParse(dateTime,_L("10pm ")); |
|
146 test(error==EParseTimePresent); |
|
147 test(dateTime.Hour()==22); |
|
148 |
|
149 error=DateTimeParse(dateTime,_L("10 pm")); |
|
150 test(error==EParseTimePresent); |
|
151 test(dateTime.Hour()==22); |
|
152 |
|
153 error=DateTimeParse(dateTime,_L("10 AM")); |
|
154 test(error==EParseTimePresent); |
|
155 test(dateTime.Hour()==10); |
|
156 |
|
157 error=DateTimeParse(dateTime,_L("10 PM")); |
|
158 test(error==EParseTimePresent); |
|
159 test(dateTime.Hour()==22); |
|
160 |
|
161 error=DateTimeParse(dateTime,_L("10pmERROR")); |
|
162 test(error==KErrArgument); |
|
163 |
|
164 DateTimeParse(dateTime,_L("12 : 56 pm")); |
|
165 test(dateTime.Hour()==12); |
|
166 test(dateTime.Minute()==56); |
|
167 |
|
168 DateTimeParse(dateTime,_L("12 : 56 am ")); |
|
169 test(dateTime.Hour()==0); |
|
170 test(dateTime.Minute()==56); |
|
171 |
|
172 DateTimeParse(dateTime,_L("12.34.56am")); |
|
173 test(dateTime.Hour()==0); |
|
174 test(dateTime.Minute()==34); |
|
175 test(dateTime.Second()==56); |
|
176 |
|
177 DateTimeParse(dateTime,_L("12.34.56pm ")); |
|
178 test(dateTime.Hour()==12); |
|
179 test(dateTime.Minute()==34); |
|
180 test(dateTime.Second()==56); |
|
181 test(dateTime.MicroSecond()==0); |
|
182 |
|
183 error=DateTimeParse(dateTime,_L("12:34:56am ERROR")); |
|
184 test(error==KErrArgument); |
|
185 |
|
186 error=DateTimeParse(dateTime,_L("12 : 56 am 05/jan/1996 ")); |
|
187 test(error==(EParseTimePresent|EParseDatePresent)); |
|
188 test(dateTime.Hour()==0); |
|
189 test(dateTime.Minute()==56); |
|
190 } |
|
191 |
|
192 LOCAL_D void SimpleDateFormats() |
|
193 { |
|
194 TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); |
|
195 TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); |
|
196 TTime before2000(before2000DateTime); |
|
197 TTime after2000(after2000DateTime); |
|
198 |
|
199 for (TInt ii=0;ii<=1;ii++) |
|
200 { |
|
201 TBool currentTimeIsBeforeYear2000=ETrue; |
|
202 if (ii==0) |
|
203 { |
|
204 User::SetUTCTime(before2000); |
|
205 currentTimeIsBeforeYear2000=ETrue; |
|
206 } |
|
207 else if (ii==1) |
|
208 { |
|
209 User::SetUTCTime(after2000); |
|
210 currentTimeIsBeforeYear2000=EFalse; |
|
211 } |
|
212 TInt error; |
|
213 TDateTime dateTime; |
|
214 DateTimeParse(dateTime,_L("5/6/1996")); |
|
215 test(dateTime.Day()==4); |
|
216 test(dateTime.Month()==EJune); |
|
217 test(dateTime.Year()==1996); |
|
218 |
|
219 DateTimeParse(dateTime,_L("5-6,1996")); |
|
220 test(dateTime.Day()==4); |
|
221 test(dateTime.Month()==EJune); |
|
222 test(dateTime.Year()==1996); |
|
223 |
|
224 DateTimeParse(dateTime,_L("5 6 1996")); |
|
225 test(dateTime.Day()==4); |
|
226 test(dateTime.Month()==EJune); |
|
227 test(dateTime.Year()==1996); |
|
228 |
|
229 DateTimeParse(dateTime,_L("5 ; 6 1996")); |
|
230 test(dateTime.Day()==4); |
|
231 test(dateTime.Month()==EJune); |
|
232 test(dateTime.Year()==1996); |
|
233 |
|
234 |
|
235 DateTimeParse(dateTime,_L("5 / 6, 96 ")); |
|
236 test(dateTime.Day()==4); |
|
237 test(dateTime.Month()==EJune); |
|
238 if (currentTimeIsBeforeYear2000) |
|
239 test(dateTime.Year()==1996); |
|
240 else |
|
241 test(dateTime.Year()==2096); |
|
242 |
|
243 DateTimeParse(dateTime,_L("5/6/19 "),20); |
|
244 test(dateTime.Day()==4); |
|
245 test(dateTime.Month()==EJune); |
|
246 test(dateTime.Year()==2019); |
|
247 |
|
248 DateTimeParse(dateTime,_L("5/6/20 "),20); |
|
249 test(dateTime.Day()==4); |
|
250 test(dateTime.Month()==EJune); |
|
251 test(dateTime.Year()==1920); |
|
252 |
|
253 DateTimeParse(dateTime,_L("5/6/00"),20); |
|
254 test(dateTime.Day()==4); |
|
255 test(dateTime.Month()==EJune); |
|
256 test(dateTime.Year()==2000); |
|
257 |
|
258 error=DateTimeParse(dateTime,_L("5/6/00 "),00); |
|
259 test(error==EParseDatePresent); |
|
260 test(dateTime.Day()==4); |
|
261 test(dateTime.Month()==EJune); |
|
262 if (currentTimeIsBeforeYear2000) |
|
263 test(dateTime.Year()==1900); |
|
264 else |
|
265 test(dateTime.Year()==2000); |
|
266 |
|
267 error=DateTimeParse(dateTime,_L("june 5 /00 "),00); |
|
268 test(error==EParseDatePresent); |
|
269 test(dateTime.Day()==4); |
|
270 test(dateTime.Month()==EJune); |
|
271 if (currentTimeIsBeforeYear2000) |
|
272 test(dateTime.Year()==1900); |
|
273 else |
|
274 test(dateTime.Year()==2000); |
|
275 |
|
276 error=DateTimeParse(dateTime,_L("5 june/00 "),00); |
|
277 test(error==EParseDatePresent); |
|
278 test(dateTime.Day()==4); |
|
279 test(dateTime.Month()==EJune); |
|
280 if (currentTimeIsBeforeYear2000) |
|
281 test(dateTime.Year()==1900); |
|
282 else |
|
283 test(dateTime.Year()==2000); |
|
284 |
|
285 error=DateTimeParse(dateTime,_L("5june 96 "),00); |
|
286 test(error==KErrArgument); |
|
287 |
|
288 // two field dates |
|
289 |
|
290 error=DateTimeParse(dateTime,_L("5/6")); |
|
291 test(error==EParseDatePresent); |
|
292 test(dateTime.Day()==4); |
|
293 test(dateTime.Month()==EJune); |
|
294 test(dateTime.Year()==0); |
|
295 |
|
296 error=DateTimeParse(dateTime,_L("5-6,")); |
|
297 test(error==KErrArgument); |
|
298 |
|
299 error=DateTimeParse(dateTime,_L("5/6/ "),20); |
|
300 test(error==KErrArgument); |
|
301 |
|
302 error=DateTimeParse(dateTime,_L("july 11"),20); |
|
303 test(error==EParseDatePresent); |
|
304 test(dateTime.Day()==10); |
|
305 test(dateTime.Month()==EJuly); |
|
306 test(dateTime.Year()==0); |
|
307 |
|
308 error=DateTimeParse(dateTime,_L("11 july"),20); |
|
309 test(error==EParseDatePresent); |
|
310 test(dateTime.Day()==10); |
|
311 test(dateTime.Month()==EJuly); |
|
312 test(dateTime.Year()==0); |
|
313 |
|
314 error=DateTimeParse(dateTime,_L("june 5 "),00); |
|
315 test(error==EParseDatePresent); |
|
316 test(dateTime.Day()==4); |
|
317 test(dateTime.Month()==EJune); |
|
318 test(dateTime.Year()==0); |
|
319 |
|
320 error=DateTimeParse(dateTime,_L("5 june/ "),00); |
|
321 test(error==KErrArgument); |
|
322 |
|
323 error=DateTimeParse(dateTime,_L("5june "),00); |
|
324 test(error==KErrArgument); |
|
325 |
|
326 DateTimeParse(dateTime,_L("5/6/1")); |
|
327 if (currentTimeIsBeforeYear2000) |
|
328 test(dateTime.Year()==1901); |
|
329 else |
|
330 test(dateTime.Year()==2001); |
|
331 DateTimeParse(dateTime,_L("5/6/01")); |
|
332 if (currentTimeIsBeforeYear2000) |
|
333 test(dateTime.Year()==1901); |
|
334 else |
|
335 test(dateTime.Year()==2001); |
|
336 DateTimeParse(dateTime,_L("5/6/001")); |
|
337 test(dateTime.Year()==0001); |
|
338 DateTimeParse(dateTime,_L("5/6/0001")); |
|
339 test(dateTime.Year()==0001); |
|
340 } |
|
341 } |
|
342 |
|
343 LOCAL_D void DateTimeFormats() |
|
344 { |
|
345 TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); |
|
346 TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); |
|
347 TTime before2000(before2000DateTime); |
|
348 TTime after2000(after2000DateTime); |
|
349 |
|
350 for (TInt ii=0;ii<=1;ii++) |
|
351 { |
|
352 TBool currentTimeIsBeforeYear2000=ETrue; |
|
353 if (ii==0) |
|
354 { |
|
355 User::SetUTCTime(before2000); |
|
356 currentTimeIsBeforeYear2000=ETrue; |
|
357 } |
|
358 else if (ii==1) |
|
359 { |
|
360 User::SetUTCTime(after2000); |
|
361 currentTimeIsBeforeYear2000=EFalse; |
|
362 } |
|
363 TInt error; |
|
364 TDateTime dateTime; |
|
365 error=DateTimeParse(dateTime,_L("5/6/1996 10am")); |
|
366 test(error==(EParseDatePresent|EParseTimePresent)); |
|
367 test(dateTime.Day()==4); |
|
368 test(dateTime.Month()==EJune); |
|
369 test(dateTime.Year()==1996); |
|
370 test(dateTime.Hour()==10); |
|
371 |
|
372 error=DateTimeParse(dateTime,_L("5/6/1996 10 pm ")); |
|
373 test(error==(EParseDatePresent|EParseTimePresent)); |
|
374 test(dateTime.Day()==4); |
|
375 test(dateTime.Month()==EJune); |
|
376 test(dateTime.Year()==1996); |
|
377 test(dateTime.Hour()==22); |
|
378 |
|
379 error=DateTimeParse(dateTime,_L("5/6/1996 10 : 30 ")); |
|
380 test(error==(EParseDatePresent|EParseTimePresent)); |
|
381 test(dateTime.Day()==4); |
|
382 test(dateTime.Month()==EJune); |
|
383 test(dateTime.Year()==1996); |
|
384 test(dateTime.Hour()==10); |
|
385 test(dateTime.Minute()==30); |
|
386 |
|
387 error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 pm ")); |
|
388 test(error==(EParseDatePresent|EParseTimePresent)); |
|
389 test(dateTime.Day()==4); |
|
390 test(dateTime.Month()==EJune); |
|
391 test(dateTime.Year()==1996); |
|
392 test(dateTime.Hour()==22); |
|
393 test(dateTime.Minute()==40); |
|
394 |
|
395 error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 . 01 ")); |
|
396 test(error==(EParseDatePresent|EParseTimePresent)); |
|
397 test(dateTime.Day()==4); |
|
398 test(dateTime.Month()==EJune); |
|
399 test(dateTime.Year()==1996); |
|
400 test(dateTime.Hour()==10); |
|
401 test(dateTime.Minute()==40); |
|
402 test(dateTime.Second()==01); |
|
403 test(dateTime.MicroSecond()==0); |
|
404 |
|
405 error=DateTimeParse(dateTime,_L("5-6 ,1996 10 : 40 . 01 pm ")); |
|
406 test(error==(EParseDatePresent|EParseTimePresent)); |
|
407 test(dateTime.Day()==4); |
|
408 test(dateTime.Month()==EJune); |
|
409 test(dateTime.Year()==1996); |
|
410 test(dateTime.Hour()==22); |
|
411 test(dateTime.Minute()==40); |
|
412 test(dateTime.Second()==01); |
|
413 test(dateTime.MicroSecond()==0); |
|
414 |
|
415 error=DateTimeParse(dateTime,_L("20- feb /96 12 : 40 . 01 am")); |
|
416 test(error==(EParseDatePresent|EParseTimePresent)); |
|
417 test(dateTime.Day()==19); |
|
418 test(dateTime.Month()==EFebruary); |
|
419 test(dateTime.Hour()==0); |
|
420 test(dateTime.Minute()==40); |
|
421 test(dateTime.Second()==01); |
|
422 test(dateTime.MicroSecond()==0); |
|
423 if (currentTimeIsBeforeYear2000) |
|
424 test(dateTime.Year()==1996); |
|
425 else |
|
426 test(dateTime.Year()==2096); |
|
427 |
|
428 error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 . 01 . 02 ")); |
|
429 test(error==(EParseDatePresent|EParseTimePresent)); |
|
430 test(dateTime.Day()==4); |
|
431 test(dateTime.Month()==EJune); |
|
432 test(dateTime.Year()==1996); |
|
433 test(dateTime.Hour()==10); |
|
434 test(dateTime.Minute()==40); |
|
435 test(dateTime.Second()==01); |
|
436 test(dateTime.MicroSecond()==2); |
|
437 |
|
438 error=DateTimeParse(dateTime,_L("5-6 ,1996 10 : 40 . 01 . 03 pm ")); |
|
439 test(error==(EParseDatePresent|EParseTimePresent)); |
|
440 test(dateTime.Day()==4); |
|
441 test(dateTime.Month()==EJune); |
|
442 test(dateTime.Year()==1996); |
|
443 test(dateTime.Hour()==22); |
|
444 test(dateTime.Minute()==40); |
|
445 test(dateTime.Second()==01); |
|
446 test(dateTime.MicroSecond()==3); |
|
447 |
|
448 error=DateTimeParse(dateTime,_L("20- feb /96 12 : 40 . 01 . 04 am")); |
|
449 test(error==(EParseDatePresent|EParseTimePresent)); |
|
450 test(dateTime.Day()==19); |
|
451 test(dateTime.Month()==EFebruary); |
|
452 test(dateTime.Hour()==0); |
|
453 test(dateTime.Minute()==40); |
|
454 test(dateTime.Second()==01); |
|
455 test(dateTime.MicroSecond()==4); |
|
456 if (currentTimeIsBeforeYear2000) |
|
457 test(dateTime.Year()==1996); |
|
458 else |
|
459 test(dateTime.Year()==2096); |
|
460 |
|
461 error=DateTimeParse(dateTime,_L("20- feb /9612 : 40.01am")); |
|
462 test(error==KErrGeneral); |
|
463 |
|
464 // two field dates |
|
465 |
|
466 error=DateTimeParse(dateTime,_L("5/6 10am")); |
|
467 test(error==(EParseDatePresent|EParseTimePresent)); |
|
468 test(dateTime.Day()==4); |
|
469 test(dateTime.Month()==EJune); |
|
470 test(dateTime.Year()==0); |
|
471 test(dateTime.Hour()==10); |
|
472 |
|
473 error=DateTimeParse(dateTime,_L("5/6/ 10 pm ")); |
|
474 test(error==(EParseDatePresent|EParseTimePresent)); |
|
475 test(dateTime.Day()==4); |
|
476 test(dateTime.Month()==EJune); |
|
477 test(dateTime.Year()==0); |
|
478 test(dateTime.Hour()==22); |
|
479 |
|
480 error=DateTimeParse(dateTime,_L("5/6 10 : 40 . 01 ")); |
|
481 test(error==(EParseDatePresent|EParseTimePresent)); |
|
482 test(dateTime.Day()==4); |
|
483 test(dateTime.Month()==EJune); |
|
484 test(dateTime.Year()==0); |
|
485 test(dateTime.Hour()==10); |
|
486 test(dateTime.Minute()==40); |
|
487 test(dateTime.Second()==01); |
|
488 test(dateTime.MicroSecond()==0); |
|
489 |
|
490 error=DateTimeParse(dateTime,_L("5-6 , 10 : 40 . 01 pm ")); |
|
491 test(error==(EParseDatePresent|EParseTimePresent)); |
|
492 test(dateTime.Day()==4); |
|
493 test(dateTime.Month()==EJune); |
|
494 test(dateTime.Year()==0); |
|
495 test(dateTime.Hour()==22); |
|
496 test(dateTime.Minute()==40); |
|
497 test(dateTime.Second()==01); |
|
498 test(dateTime.MicroSecond()==0); |
|
499 |
|
500 error=DateTimeParse(dateTime,_L("5/6 10 : 40 . 01 . 02")); |
|
501 test(error==(EParseDatePresent|EParseTimePresent)); |
|
502 test(dateTime.Day()==4); |
|
503 test(dateTime.Month()==EJune); |
|
504 test(dateTime.Year()==0); |
|
505 test(dateTime.Hour()==10); |
|
506 test(dateTime.Minute()==40); |
|
507 test(dateTime.Second()==01); |
|
508 test(dateTime.MicroSecond()==2); |
|
509 |
|
510 error=DateTimeParse(dateTime,_L("5-6 , 10 : 40 . 01 . 05pm ")); |
|
511 test(error==(EParseDatePresent|EParseTimePresent)); |
|
512 test(dateTime.Day()==4); |
|
513 test(dateTime.Month()==EJune); |
|
514 test(dateTime.Year()==0); |
|
515 test(dateTime.Hour()==22); |
|
516 test(dateTime.Minute()==40); |
|
517 test(dateTime.Second()==01); |
|
518 test(dateTime.MicroSecond()==5); |
|
519 |
|
520 } |
|
521 } |
|
522 |
|
523 LOCAL_D void TimeDateFormats() |
|
524 { |
|
525 TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); |
|
526 TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); |
|
527 TTime before2000(before2000DateTime); |
|
528 TTime after2000(after2000DateTime); |
|
529 |
|
530 for (TInt ii=0;ii<=1;ii++) |
|
531 { |
|
532 TBool currentTimeIsBeforeYear2000=ETrue; |
|
533 if (ii==0) |
|
534 { |
|
535 User::SetUTCTime(before2000); |
|
536 currentTimeIsBeforeYear2000=ETrue; |
|
537 } |
|
538 else if (ii==1) |
|
539 { |
|
540 User::SetUTCTime(after2000); |
|
541 currentTimeIsBeforeYear2000=EFalse; |
|
542 } |
|
543 TInt error; |
|
544 TDateTime dateTime; |
|
545 error=DateTimeParse(dateTime,_L("10pm 5/6/96")); |
|
546 test(error==(EParseDatePresent|EParseTimePresent)); |
|
547 test(dateTime.Hour()==22); |
|
548 test(dateTime.Day()==4); |
|
549 test(dateTime.Month()==EJune); |
|
550 if (currentTimeIsBeforeYear2000) |
|
551 test(dateTime.Year()==1996); |
|
552 else |
|
553 test(dateTime.Year()==2096); |
|
554 |
|
555 |
|
556 error=DateTimeParse(dateTime,_L("12 am 5 -feb,03 ")); |
|
557 test(error==(EParseDatePresent|EParseTimePresent)); |
|
558 test(dateTime.Hour()==00); |
|
559 test(dateTime.Day()==4); |
|
560 test(dateTime.Month()==EFebruary); |
|
561 if (currentTimeIsBeforeYear2000) |
|
562 test(dateTime.Year()==1903); |
|
563 else |
|
564 test(dateTime.Year()==2003); |
|
565 |
|
566 error=DateTimeParse(dateTime,_L("12 .56am 5 -feb,03 ")); |
|
567 test(error==(EParseDatePresent|EParseTimePresent)); |
|
568 test(dateTime.Hour()==00); |
|
569 test(dateTime.Minute()==56); |
|
570 test(dateTime.Day()==4); |
|
571 test(dateTime.Month()==EFebruary); |
|
572 if (currentTimeIsBeforeYear2000) |
|
573 test(dateTime.Year()==1903); |
|
574 else |
|
575 test(dateTime.Year()==2003); |
|
576 |
|
577 error=DateTimeParse(dateTime,_L("12 .56:01.03pm 5 -SEPTEMBER,03 ")); |
|
578 test(error==(EParseDatePresent|EParseTimePresent)); |
|
579 test(dateTime.Hour()==12); |
|
580 test(dateTime.Minute()==56); |
|
581 test(dateTime.Second()==01); |
|
582 test(dateTime.MicroSecond()==03); |
|
583 test(dateTime.Day()==4); |
|
584 test(dateTime.Month()==ESeptember); |
|
585 if (currentTimeIsBeforeYear2000) |
|
586 test(dateTime.Year()==1903); |
|
587 else |
|
588 test(dateTime.Year()==2003); |
|
589 |
|
590 |
|
591 error=DateTimeParse(dateTime,_L("12 .56:01pm SEPTEMBER 5,03 ")); |
|
592 test(error==(EParseDatePresent|EParseTimePresent)); |
|
593 test(dateTime.Hour()==12); |
|
594 test(dateTime.Minute()==56); |
|
595 test(dateTime.Second()==01); |
|
596 test(dateTime.Day()==4); |
|
597 test(dateTime.Month()==ESeptember); |
|
598 if (currentTimeIsBeforeYear2000) |
|
599 test(dateTime.Year()==1903); |
|
600 else |
|
601 test(dateTime.Year()==2003); |
|
602 |
|
603 |
|
604 error=DateTimeParse(dateTime,_L("12 .0056:01pm 5 -SEPTEMBERX,03 ")); |
|
605 test(error==KErrArgument); |
|
606 |
|
607 error=DateTimeParse(dateTime,_L("12 .56:015 -SEPTEMBER,03 ")); |
|
608 test(error==(EParseDatePresent|EParseTimePresent)); |
|
609 test(dateTime.Hour()==12); |
|
610 test(dateTime.Minute()==56); |
|
611 test(dateTime.Second()==15); |
|
612 test(dateTime.Day()==2); |
|
613 test(dateTime.Month()==ESeptember); |
|
614 test(dateTime.Year()==0); |
|
615 |
|
616 // max descriptor length 27 tokens// 13 tokens after spaces are striped |
|
617 error=DateTimeParse(dateTime,_L(" 10 : 00 : 00 . 123456 pm 5 / 6 / 96 ")); |
|
618 test(error==(EParseDatePresent|EParseTimePresent)); |
|
619 test(dateTime.MicroSecond()==123456); |
|
620 test(dateTime.Second()==0); |
|
621 test(dateTime.Minute()==0); |
|
622 test(dateTime.Hour()==22); |
|
623 test(dateTime.Day()==4); |
|
624 test(dateTime.Month()==EJune); |
|
625 if (currentTimeIsBeforeYear2000) |
|
626 test(dateTime.Year()==1996); |
|
627 else |
|
628 test(dateTime.Year()==2096); |
|
629 |
|
630 |
|
631 // the formaula array will overflow with too many tokens |
|
632 error=DateTimeParse(dateTime,_L(" 10 : 00 : 00 pm 5 / 6 / 96 / / / / / / / / / / / / / / / ")); |
|
633 test(error==KErrArgument); |
|
634 } |
|
635 } |
|
636 |
|
637 LOCAL_D void BadDescriptors() |
|
638 { |
|
639 |
|
640 TInt error; |
|
641 TDateTime dateTime; |
|
642 error=DateTimeParse(dateTime,_L("10pmpm")); |
|
643 test(error==KErrArgument); |
|
644 |
|
645 error=DateTimeParse(dateTime,_L("10pmX")); |
|
646 test(error==KErrArgument); |
|
647 |
|
648 error=DateTimeParse(dateTime,_L("1111")); |
|
649 test(error==KErrArgument); |
|
650 |
|
651 error=DateTimeParse(dateTime,_L("10::10")); |
|
652 test(error==KErrGeneral); |
|
653 |
|
654 error=DateTimeParse(dateTime,_L("10-,10")); |
|
655 test(error==KErrArgument); |
|
656 |
|
657 error=DateTimeParse(dateTime,_L(" - 10:10")); |
|
658 test(error==KErrArgument); |
|
659 |
|
660 error=DateTimeParse(dateTime,_L(" 10 10:10")); |
|
661 test(error==KErrArgument); |
|
662 |
|
663 error=DateTimeParse(dateTime,_L(" 5 june 10000")); |
|
664 test(error==KErrArgument); |
|
665 |
|
666 error=DateTimeParse(dateTime,_L("24:01")); |
|
667 test(error==KErrGeneral); |
|
668 |
|
669 error=DateTimeParse(dateTime,_L("may 2, 9623:34:45")); |
|
670 test(error==KErrGeneral); |
|
671 |
|
672 error=DateTimeParse(dateTime,_L(" 9/10/- ")); |
|
673 test(error==KErrArgument); |
|
674 } |
|
675 |
|
676 LOCAL_D void TestLocaleChanges() |
|
677 { |
|
678 TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); |
|
679 TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); |
|
680 TTime before2000(before2000DateTime); |
|
681 TTime after2000(after2000DateTime); |
|
682 |
|
683 for (TInt ii=0;ii<=1;ii++) |
|
684 { |
|
685 TBool currentTimeIsBeforeYear2000=ETrue; |
|
686 if (ii==0) |
|
687 { |
|
688 User::SetUTCTime(before2000); |
|
689 currentTimeIsBeforeYear2000=ETrue; |
|
690 } |
|
691 else if (ii==1) |
|
692 { |
|
693 User::SetUTCTime(after2000); |
|
694 currentTimeIsBeforeYear2000=EFalse; |
|
695 } |
|
696 TLocale locale; |
|
697 locale.Refresh(); |
|
698 TLocale savedLocale; |
|
699 TInt error; |
|
700 TDateTime dateTime; |
|
701 |
|
702 //Set decimal separator in locale to another value: |
|
703 locale.SetDecimalSeparator('!'); |
|
704 locale.Set(); |
|
705 error=DateTimeParse(dateTime,_L("3/6 10:10:10!111111")); |
|
706 test(error==(EParseDatePresent|EParseTimePresent)); |
|
707 test(dateTime.MicroSecond()==111111); |
|
708 test(dateTime.Second()==10); |
|
709 test(dateTime.Minute()==10); |
|
710 test(dateTime.Hour()==10); |
|
711 test(dateTime.Day()==2); |
|
712 test(dateTime.Month()==EJune); |
|
713 |
|
714 error=DateTimeParse(dateTime,_L("1/6/12")); |
|
715 test(error==EParseDatePresent); |
|
716 test(dateTime.Second()==0); |
|
717 test(dateTime.Minute()==0); |
|
718 test(dateTime.Hour()==0); |
|
719 test(dateTime.Day()==0); |
|
720 test(dateTime.Month()==EJune); |
|
721 if (currentTimeIsBeforeYear2000) |
|
722 test(dateTime.Year()==1912); |
|
723 else |
|
724 test(dateTime.Year()==2012); |
|
725 |
|
726 error=DateTimeParse(dateTime,_L(" dec 3 12"),10); |
|
727 test(error==EParseDatePresent); |
|
728 test(dateTime.Second()==0); |
|
729 test(dateTime.Minute()==0); |
|
730 test(dateTime.Hour()==0); |
|
731 test(dateTime.Day()==2); |
|
732 test(dateTime.Month()==EDecember); |
|
733 if (currentTimeIsBeforeYear2000) |
|
734 test(dateTime.Year()==1912); |
|
735 else |
|
736 test(dateTime.Year()==1912); |
|
737 |
|
738 error=DateTimeParse(dateTime,_L(" 3 dec 12 "),12); |
|
739 test(error==EParseDatePresent); |
|
740 test(dateTime.Second()==0); |
|
741 test(dateTime.Minute()==0); |
|
742 test(dateTime.Hour()==0); |
|
743 test(dateTime.Day()==2); |
|
744 test(dateTime.Month()==EDecember); |
|
745 if (currentTimeIsBeforeYear2000) |
|
746 test(dateTime.Year()==1912); |
|
747 else |
|
748 test(dateTime.Year()==1912); |
|
749 |
|
750 TDateFormat dateFormat=EDateAmerican; |
|
751 locale.SetDateFormat(dateFormat); |
|
752 locale.Set(); |
|
753 |
|
754 error=DateTimeParse(dateTime,_L("1/6/12")); |
|
755 test(error==EParseDatePresent); |
|
756 test(dateTime.Second()==0); |
|
757 test(dateTime.Minute()==0); |
|
758 test(dateTime.Hour()==0); |
|
759 test(dateTime.Day()==5); |
|
760 test(dateTime.Month()==EJanuary); |
|
761 if (currentTimeIsBeforeYear2000) |
|
762 test(dateTime.Year()==1912); |
|
763 else |
|
764 test(dateTime.Year()==2012); |
|
765 |
|
766 error=DateTimeParse(dateTime,_L(" dec 3 12"),13); |
|
767 test(error==EParseDatePresent); |
|
768 test(dateTime.Second()==0); |
|
769 test(dateTime.Minute()==0); |
|
770 test(dateTime.Hour()==0); |
|
771 test(dateTime.Day()==2); |
|
772 test(dateTime.Month()==EDecember); |
|
773 if (currentTimeIsBeforeYear2000) |
|
774 test(dateTime.Year()==2012); |
|
775 else |
|
776 test(dateTime.Year()==2012); |
|
777 |
|
778 error=DateTimeParse(dateTime,_L(" 3 dec 12 ")); |
|
779 test(error==EParseDatePresent); |
|
780 test(dateTime.Second()==0); |
|
781 test(dateTime.Minute()==0); |
|
782 test(dateTime.Hour()==0); |
|
783 test(dateTime.Day()==2); |
|
784 test(dateTime.Month()==EDecember); |
|
785 if (currentTimeIsBeforeYear2000) |
|
786 test(dateTime.Year()==1912); |
|
787 else |
|
788 test(dateTime.Year()==2012); |
|
789 |
|
790 dateFormat=EDateJapanese; |
|
791 locale.SetDateFormat(dateFormat); |
|
792 locale.Set(); |
|
793 |
|
794 error=DateTimeParse(dateTime,_L("3/17")); |
|
795 test(error==EParseDatePresent); |
|
796 test(dateTime.Second()==0); |
|
797 test(dateTime.Minute()==0); |
|
798 test(dateTime.Hour()==0); |
|
799 test(dateTime.Day()==16); |
|
800 test(dateTime.Month()==EMarch); |
|
801 test(dateTime.Year()==0); |
|
802 |
|
803 error=DateTimeParse(dateTime,_L("1/6/12")); |
|
804 test(error==EParseDatePresent); |
|
805 test(dateTime.Second()==0); |
|
806 test(dateTime.Minute()==0); |
|
807 test(dateTime.Hour()==0); |
|
808 test(dateTime.Day()==11); |
|
809 test(dateTime.Month()==EJune); |
|
810 if (currentTimeIsBeforeYear2000) |
|
811 test(dateTime.Year()==1901); |
|
812 else |
|
813 test(dateTime.Year()==2001); |
|
814 |
|
815 error=DateTimeParse(dateTime,_L("1*6*12")); |
|
816 test(error==KErrArgument); |
|
817 |
|
818 error=DateTimeParse(dateTime,_L("1+6+12")); |
|
819 test(error==KErrArgument); |
|
820 |
|
821 locale.SetDateSeparator('*',1); |
|
822 locale.SetDateSeparator('+',2); |
|
823 locale.Set(); |
|
824 |
|
825 error=DateTimeParse(dateTime,_L("1*6*12")); |
|
826 test(error==EParseDatePresent); |
|
827 test(dateTime.Second()==0); |
|
828 test(dateTime.Minute()==0); |
|
829 test(dateTime.Hour()==0); |
|
830 test(dateTime.Day()==11); |
|
831 test(dateTime.Month()==EJune); |
|
832 if (currentTimeIsBeforeYear2000) |
|
833 test(dateTime.Year()==1901); |
|
834 else |
|
835 test(dateTime.Year()==2001); |
|
836 |
|
837 error=DateTimeParse(dateTime,_L("1+6+12")); |
|
838 test(error==EParseDatePresent); |
|
839 test(dateTime.Second()==0); |
|
840 test(dateTime.Minute()==0); |
|
841 test(dateTime.Hour()==0); |
|
842 test(dateTime.Day()==11); |
|
843 test(dateTime.Month()==EJune); |
|
844 if (currentTimeIsBeforeYear2000) |
|
845 test(dateTime.Year()==1901); |
|
846 else |
|
847 test(dateTime.Year()==2001); |
|
848 |
|
849 error=DateTimeParse(dateTime,_L("1+6+12 14:32.54am")); |
|
850 test(error==(EParseDatePresent|EParseTimePresent)); |
|
851 test(dateTime.Second()==54); |
|
852 test(dateTime.Minute()==32); |
|
853 test(dateTime.Hour()==14); |
|
854 test(dateTime.Day()==11); |
|
855 test(dateTime.Month()==EJune); |
|
856 if (currentTimeIsBeforeYear2000) |
|
857 test(dateTime.Year()==1901); |
|
858 else |
|
859 test(dateTime.Year()==2001); |
|
860 |
|
861 error=DateTimeParse(dateTime,_L("10p 1+6+12")); |
|
862 test(error==(EParseDatePresent|EParseTimePresent)); |
|
863 test(dateTime.Second()==0); |
|
864 test(dateTime.Minute()==0); |
|
865 test(dateTime.Hour()==22); |
|
866 test(dateTime.Day()==11); |
|
867 test(dateTime.Month()==EJune); |
|
868 if (currentTimeIsBeforeYear2000) |
|
869 test(dateTime.Year()==1901); |
|
870 else |
|
871 test(dateTime.Year()==2001); |
|
872 |
|
873 // European |
|
874 locale.SetDateFormat(EDateEuropean); |
|
875 locale.SetDateSeparator('.',2); |
|
876 locale.Set(); |
|
877 |
|
878 error=DateTimeParse(dateTime,_L("1+6+12")); |
|
879 test(error==KErrArgument); |
|
880 |
|
881 error=DateTimeParse(dateTime,_L("3.6.86")); |
|
882 test(error==EParseDatePresent); |
|
883 test(dateTime.Second()==0); |
|
884 test(dateTime.Minute()==0); |
|
885 test(dateTime.Hour()==0); |
|
886 test(dateTime.Day()==2); |
|
887 test(dateTime.Month()==EJune); |
|
888 if (currentTimeIsBeforeYear2000) |
|
889 test(dateTime.Year()==1986); |
|
890 else |
|
891 test(dateTime.Year()==2086); |
|
892 |
|
893 error=DateTimeParse(dateTime,_L("3.6.86 10:10:10")); |
|
894 test(error==(EParseDatePresent|EParseTimePresent)); |
|
895 test(dateTime.Second()==10); |
|
896 test(dateTime.Minute()==10); |
|
897 test(dateTime.Hour()==10); |
|
898 test(dateTime.Day()==2); |
|
899 test(dateTime.Month()==EJune); |
|
900 if (currentTimeIsBeforeYear2000) |
|
901 test(dateTime.Year()==1986); |
|
902 else |
|
903 test(dateTime.Year()==2086); |
|
904 |
|
905 locale.SetDateSeparator(':',1); |
|
906 locale.Set(); |
|
907 |
|
908 error=DateTimeParse(dateTime,_L("3.6.86 10:10:10")); |
|
909 test(error==KErrArgument); |
|
910 // test(error==(EParseDatePresent|EParseTimePresent)); |
|
911 test(dateTime.Second()==10); |
|
912 test(dateTime.Minute()==10); |
|
913 test(dateTime.Hour()==10); |
|
914 test(dateTime.Day()==2); |
|
915 test(dateTime.Month()==EJune); |
|
916 if (currentTimeIsBeforeYear2000) |
|
917 test(dateTime.Year()==1986); |
|
918 else |
|
919 test(dateTime.Year()==2086); |
|
920 |
|
921 error=DateTimeParse(dateTime,_L("3:6:86 10.10.10")); |
|
922 test(error==KErrArgument); |
|
923 test(dateTime.Second()==10); |
|
924 test(dateTime.Minute()==10); |
|
925 test(dateTime.Hour()==10); |
|
926 test(dateTime.Day()==2); |
|
927 test(dateTime.Month()==EJune); |
|
928 if (currentTimeIsBeforeYear2000) |
|
929 test(dateTime.Year()==1986); |
|
930 else |
|
931 test(dateTime.Year()==2086); |
|
932 |
|
933 error=DateTimeParse(dateTime,_L("10.10")); |
|
934 test(error==EParseDatePresent); |
|
935 test(dateTime.Second()==0); |
|
936 test(dateTime.Minute()==0); |
|
937 test(dateTime.Hour()==0); |
|
938 test(dateTime.Day()==9); |
|
939 test(dateTime.Month()==EOctober); |
|
940 test(dateTime.Year()==0); |
|
941 |
|
942 // If the date sep has been set to '.' then 10th October |
|
943 error=DateTimeParse(dateTime,_L("10.10pm")); |
|
944 test(error==KErrArgument); |
|
945 test(dateTime.Second()==0); |
|
946 test(dateTime.Minute()==0); |
|
947 test(dateTime.Hour()==0); |
|
948 test(dateTime.Day()==9); |
|
949 test(dateTime.Month()==EOctober); |
|
950 test(dateTime.Year()==0); |
|
951 |
|
952 error=DateTimeParse(dateTime,_L("10p 3:6:86")); |
|
953 test(error==(EParseDatePresent|EParseTimePresent)); |
|
954 test(dateTime.Second()==0); |
|
955 test(dateTime.Minute()==0); |
|
956 test(dateTime.Hour()==22); |
|
957 test(dateTime.Day()==2); |
|
958 test(dateTime.Month()==EJune); |
|
959 if (currentTimeIsBeforeYear2000) |
|
960 test(dateTime.Year()==1986); |
|
961 else |
|
962 test(dateTime.Year()==2086); |
|
963 |
|
964 error=DateTimeParse(dateTime,_L("1:6:12 3.05.06")); |
|
965 test(error==KErrArgument); |
|
966 |
|
967 error=DateTimeParse(dateTime,_L(" 3.05.06 1:6:12")); |
|
968 test(error==KErrArgument); |
|
969 |
|
970 locale.Refresh(); |
|
971 savedLocale.Set(); |
|
972 } |
|
973 } |
|
974 |
|
975 TInt E32Main() |
|
976 { |
|
977 |
|
978 test.Title(); |
|
979 test.Start(_L("Begin tests")); |
|
980 TLocale currentLocale; |
|
981 |
|
982 TLocale b; |
|
983 b.SetDateSeparator('\0',0); |
|
984 b.SetDateSeparator('/',1); |
|
985 b.SetDateSeparator('/',2); |
|
986 b.SetDateSeparator('\0',3); |
|
987 b.SetDateFormat(EDateEuropean); |
|
988 b.SetTimeFormat(ETime12); |
|
989 b.SetTimeSeparator('\0',0); |
|
990 b.SetTimeSeparator(':',1); |
|
991 b.SetTimeSeparator(':',2); |
|
992 b.SetTimeSeparator('\0',3); |
|
993 b.SetAmPmSpaceBetween(ETrue); |
|
994 b.SetAmPmSymbolPosition(ELocaleAfter); |
|
995 b.SetWorkDays(0x1F); |
|
996 b.SetStartOfWeek(EMonday); |
|
997 b.Set(); |
|
998 |
|
999 TTimeIntervalSeconds oldOffset = User::UTCOffset(); |
|
1000 User::SetUTCOffset(0); |
|
1001 |
|
1002 test.Console()->Printf(_L("SimpleTimeFormats\n")); |
|
1003 SimpleTimeFormats(); |
|
1004 test.Console()->Printf(_L("SimpleDateFormats\n")); |
|
1005 SimpleDateFormats(); |
|
1006 test.Console()->Printf(_L("DateTimeFormats\n")); |
|
1007 DateTimeFormats(); |
|
1008 test.Console()->Printf(_L("TimeDateFormats\n")); |
|
1009 TimeDateFormats(); |
|
1010 test.Console()->Printf(_L("BadDescriptors\n")); |
|
1011 BadDescriptors(); |
|
1012 test.Console()->Printf(_L("TestLocaleChanges\n")); |
|
1013 TestLocaleChanges(); |
|
1014 test.Console()->Printf(_L("End of tests\n")); |
|
1015 currentLocale.Set(); |
|
1016 User::SetUTCOffset(oldOffset); |
|
1017 test.End(); |
|
1018 return(KErrNone); |
|
1019 } |
|
1020 |
|
1021 |