Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\datetime\t_tparse.cpp
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:
29 // Assumptions/Requirement/Pre-requisites:
30 // Failures and causes:
31 // Base Port information:
37 RTest test(_L("T_TPARSE"));
39 LOCAL_C TInt DateTimeParse(TDateTime& aDateTime,const TDesC& aDes,TInt aCenturyOffset=0)
43 TInt r=time.Parse(aDes,aCenturyOffset);
45 aDateTime=time.DateTime();
49 LOCAL_D void SimpleTimeFormats()
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);
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);
68 error=DateTimeParse(dateTime,_L("23:34:45.1234567"));
69 test(error==KErrGeneral);
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);
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);
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);
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);
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);
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);
113 DateTimeParse(dateTime,_L("12 . 34"));
114 test(dateTime.Hour()==12);
115 test(dateTime.Minute()==34);
117 error=DateTimeParse(dateTime,_L("23:34:"));
118 test(error==KErrArgument);
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);
127 error=DateTimeParse(dateTime,_L("24 : 56"));
128 test(error==KErrGeneral);// TDateTime class does not allow 24:56
130 error=DateTimeParse(dateTime,_L("10"));
131 test(error==KErrArgument);
133 error=DateTimeParse(dateTime,_L("10a"));
134 test(error==EParseTimePresent);
135 test(dateTime.Hour()==10);
137 error=DateTimeParse(dateTime,_L("10p"));
138 test(error==EParseTimePresent);
139 test(dateTime.Hour()==22);
141 error=DateTimeParse(dateTime,_L("10 p"));
142 test(error==EParseTimePresent);
143 test(dateTime.Hour()==22);
145 error=DateTimeParse(dateTime,_L("10pm "));
146 test(error==EParseTimePresent);
147 test(dateTime.Hour()==22);
149 error=DateTimeParse(dateTime,_L("10 pm"));
150 test(error==EParseTimePresent);
151 test(dateTime.Hour()==22);
153 error=DateTimeParse(dateTime,_L("10 AM"));
154 test(error==EParseTimePresent);
155 test(dateTime.Hour()==10);
157 error=DateTimeParse(dateTime,_L("10 PM"));
158 test(error==EParseTimePresent);
159 test(dateTime.Hour()==22);
161 error=DateTimeParse(dateTime,_L("10pmERROR"));
162 test(error==KErrArgument);
164 DateTimeParse(dateTime,_L("12 : 56 pm"));
165 test(dateTime.Hour()==12);
166 test(dateTime.Minute()==56);
168 DateTimeParse(dateTime,_L("12 : 56 am "));
169 test(dateTime.Hour()==0);
170 test(dateTime.Minute()==56);
172 DateTimeParse(dateTime,_L("12.34.56am"));
173 test(dateTime.Hour()==0);
174 test(dateTime.Minute()==34);
175 test(dateTime.Second()==56);
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);
183 error=DateTimeParse(dateTime,_L("12:34:56am ERROR"));
184 test(error==KErrArgument);
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);
192 LOCAL_D void SimpleDateFormats()
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);
199 for (TInt ii=0;ii<=1;ii++)
201 TBool currentTimeIsBeforeYear2000=ETrue;
204 User::SetUTCTime(before2000);
205 currentTimeIsBeforeYear2000=ETrue;
209 User::SetUTCTime(after2000);
210 currentTimeIsBeforeYear2000=EFalse;
214 DateTimeParse(dateTime,_L("5/6/1996"));
215 test(dateTime.Day()==4);
216 test(dateTime.Month()==EJune);
217 test(dateTime.Year()==1996);
219 DateTimeParse(dateTime,_L("5-6,1996"));
220 test(dateTime.Day()==4);
221 test(dateTime.Month()==EJune);
222 test(dateTime.Year()==1996);
224 DateTimeParse(dateTime,_L("5 6 1996"));
225 test(dateTime.Day()==4);
226 test(dateTime.Month()==EJune);
227 test(dateTime.Year()==1996);
229 DateTimeParse(dateTime,_L("5 ; 6 1996"));
230 test(dateTime.Day()==4);
231 test(dateTime.Month()==EJune);
232 test(dateTime.Year()==1996);
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);
241 test(dateTime.Year()==2096);
243 DateTimeParse(dateTime,_L("5/6/19 "),20);
244 test(dateTime.Day()==4);
245 test(dateTime.Month()==EJune);
246 test(dateTime.Year()==2019);
248 DateTimeParse(dateTime,_L("5/6/20 "),20);
249 test(dateTime.Day()==4);
250 test(dateTime.Month()==EJune);
251 test(dateTime.Year()==1920);
253 DateTimeParse(dateTime,_L("5/6/00"),20);
254 test(dateTime.Day()==4);
255 test(dateTime.Month()==EJune);
256 test(dateTime.Year()==2000);
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);
265 test(dateTime.Year()==2000);
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);
274 test(dateTime.Year()==2000);
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);
283 test(dateTime.Year()==2000);
285 error=DateTimeParse(dateTime,_L("5june 96 "),00);
286 test(error==KErrArgument);
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);
296 error=DateTimeParse(dateTime,_L("5-6,"));
297 test(error==KErrArgument);
299 error=DateTimeParse(dateTime,_L("5/6/ "),20);
300 test(error==KErrArgument);
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);
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);
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);
320 error=DateTimeParse(dateTime,_L("5 june/ "),00);
321 test(error==KErrArgument);
323 error=DateTimeParse(dateTime,_L("5june "),00);
324 test(error==KErrArgument);
326 DateTimeParse(dateTime,_L("5/6/1"));
327 if (currentTimeIsBeforeYear2000)
328 test(dateTime.Year()==1901);
330 test(dateTime.Year()==2001);
331 DateTimeParse(dateTime,_L("5/6/01"));
332 if (currentTimeIsBeforeYear2000)
333 test(dateTime.Year()==1901);
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);
343 LOCAL_D void DateTimeFormats()
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);
350 for (TInt ii=0;ii<=1;ii++)
352 TBool currentTimeIsBeforeYear2000=ETrue;
355 User::SetUTCTime(before2000);
356 currentTimeIsBeforeYear2000=ETrue;
360 User::SetUTCTime(after2000);
361 currentTimeIsBeforeYear2000=EFalse;
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);
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);
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);
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);
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);
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);
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);
426 test(dateTime.Year()==2096);
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);
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);
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);
459 test(dateTime.Year()==2096);
461 error=DateTimeParse(dateTime,_L("20- feb /9612 : 40.01am"));
462 test(error==KErrGeneral);
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);
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);
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);
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);
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);
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);
523 LOCAL_D void TimeDateFormats()
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);
530 for (TInt ii=0;ii<=1;ii++)
532 TBool currentTimeIsBeforeYear2000=ETrue;
535 User::SetUTCTime(before2000);
536 currentTimeIsBeforeYear2000=ETrue;
540 User::SetUTCTime(after2000);
541 currentTimeIsBeforeYear2000=EFalse;
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);
553 test(dateTime.Year()==2096);
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);
564 test(dateTime.Year()==2003);
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);
575 test(dateTime.Year()==2003);
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);
588 test(dateTime.Year()==2003);
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);
601 test(dateTime.Year()==2003);
604 error=DateTimeParse(dateTime,_L("12 .0056:01pm 5 -SEPTEMBERX,03 "));
605 test(error==KErrArgument);
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);
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);
628 test(dateTime.Year()==2096);
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);
637 LOCAL_D void BadDescriptors()
642 error=DateTimeParse(dateTime,_L("10pmpm"));
643 test(error==KErrArgument);
645 error=DateTimeParse(dateTime,_L("10pmX"));
646 test(error==KErrArgument);
648 error=DateTimeParse(dateTime,_L("1111"));
649 test(error==KErrArgument);
651 error=DateTimeParse(dateTime,_L("10::10"));
652 test(error==KErrGeneral);
654 error=DateTimeParse(dateTime,_L("10-,10"));
655 test(error==KErrArgument);
657 error=DateTimeParse(dateTime,_L(" - 10:10"));
658 test(error==KErrArgument);
660 error=DateTimeParse(dateTime,_L(" 10 10:10"));
661 test(error==KErrArgument);
663 error=DateTimeParse(dateTime,_L(" 5 june 10000"));
664 test(error==KErrArgument);
666 error=DateTimeParse(dateTime,_L("24:01"));
667 test(error==KErrGeneral);
669 error=DateTimeParse(dateTime,_L("may 2, 9623:34:45"));
670 test(error==KErrGeneral);
672 error=DateTimeParse(dateTime,_L(" 9/10/- "));
673 test(error==KErrArgument);
676 LOCAL_D void TestLocaleChanges()
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);
683 for (TInt ii=0;ii<=1;ii++)
685 TBool currentTimeIsBeforeYear2000=ETrue;
688 User::SetUTCTime(before2000);
689 currentTimeIsBeforeYear2000=ETrue;
693 User::SetUTCTime(after2000);
694 currentTimeIsBeforeYear2000=EFalse;
702 //Set decimal separator in locale to another value:
703 locale.SetDecimalSeparator('!');
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);
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);
724 test(dateTime.Year()==2012);
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);
736 test(dateTime.Year()==1912);
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);
748 test(dateTime.Year()==1912);
750 TDateFormat dateFormat=EDateAmerican;
751 locale.SetDateFormat(dateFormat);
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);
764 test(dateTime.Year()==2012);
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);
776 test(dateTime.Year()==2012);
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);
788 test(dateTime.Year()==2012);
790 dateFormat=EDateJapanese;
791 locale.SetDateFormat(dateFormat);
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);
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);
813 test(dateTime.Year()==2001);
815 error=DateTimeParse(dateTime,_L("1*6*12"));
816 test(error==KErrArgument);
818 error=DateTimeParse(dateTime,_L("1+6+12"));
819 test(error==KErrArgument);
821 locale.SetDateSeparator('*',1);
822 locale.SetDateSeparator('+',2);
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);
835 test(dateTime.Year()==2001);
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);
847 test(dateTime.Year()==2001);
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);
859 test(dateTime.Year()==2001);
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);
871 test(dateTime.Year()==2001);
874 locale.SetDateFormat(EDateEuropean);
875 locale.SetDateSeparator('.',2);
878 error=DateTimeParse(dateTime,_L("1+6+12"));
879 test(error==KErrArgument);
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);
891 test(dateTime.Year()==2086);
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);
903 test(dateTime.Year()==2086);
905 locale.SetDateSeparator(':',1);
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);
919 test(dateTime.Year()==2086);
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);
931 test(dateTime.Year()==2086);
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);
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);
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);
962 test(dateTime.Year()==2086);
964 error=DateTimeParse(dateTime,_L("1:6:12 3.05.06"));
965 test(error==KErrArgument);
967 error=DateTimeParse(dateTime,_L(" 3.05.06 1:6:12"));
968 test(error==KErrArgument);
979 test.Start(_L("Begin tests"));
980 TLocale currentLocale;
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);
996 b.SetStartOfWeek(EMonday);
999 TTimeIntervalSeconds oldOffset = User::UTCOffset();
1000 User::SetUTCOffset(0);
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"));
1008 test.Console()->Printf(_L("TimeDateFormats\n"));
1010 test.Console()->Printf(_L("BadDescriptors\n"));
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);