sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\datetime\t_tparse.cpp sl@0: // Overview: sl@0: // Date & time tests sl@0: // API Information: sl@0: // TTime, TDateTime sl@0: // Details: sl@0: // - Set various locale settings to known values. sl@0: // - Test parsing a variety of simple time formats. Verify results are as expected. sl@0: // - Test parsing a variety of simple date formats. Verify results are as expected. sl@0: // - Test parsing a variety of date and time formats. Verify results are as expected. sl@0: // - Attempt to parse a variety of bad date and time descriptors. Verify the error sl@0: // results are as expected. sl@0: // - Test a variety of date and time locale changes. Verify results are as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: RTest test(_L("T_TPARSE")); sl@0: sl@0: LOCAL_C TInt DateTimeParse(TDateTime& aDateTime,const TDesC& aDes,TInt aCenturyOffset=0) sl@0: { sl@0: sl@0: TTime time; sl@0: TInt r=time.Parse(aDes,aCenturyOffset); sl@0: if (r>=0) sl@0: aDateTime=time.DateTime(); sl@0: return r; sl@0: } sl@0: sl@0: LOCAL_D void SimpleTimeFormats() sl@0: { sl@0: sl@0: TInt error; sl@0: TDateTime dateTime; sl@0: error=DateTimeParse(dateTime,_L("23:34:45:56")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==45); sl@0: test(dateTime.MicroSecond()==56); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23:34:45.56")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==45); sl@0: test(dateTime.MicroSecond()==56); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23:34:45.1234567")); sl@0: test(error==KErrGeneral); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23:34:45")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==45); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("00023:00034")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==00); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23: 34")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23: 34am")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23: 34AM")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 23 : 34 ")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==23); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: DateTimeParse(dateTime,_L("12 . 34")); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==34); sl@0: sl@0: error=DateTimeParse(dateTime,_L("23:34:")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 0012 : 00034 . 056")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==56); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("24 : 56")); sl@0: test(error==KErrGeneral);// TDateTime class does not allow 24:56 sl@0: sl@0: error=DateTimeParse(dateTime,_L("10")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10a")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==10); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10p")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10 p")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10pm ")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10 pm")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10 AM")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==10); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10 PM")); sl@0: test(error==EParseTimePresent); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10pmERROR")); sl@0: test(error==KErrArgument); sl@0: sl@0: DateTimeParse(dateTime,_L("12 : 56 pm")); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==56); sl@0: sl@0: DateTimeParse(dateTime,_L("12 : 56 am ")); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Minute()==56); sl@0: sl@0: DateTimeParse(dateTime,_L("12.34.56am")); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==56); sl@0: sl@0: DateTimeParse(dateTime,_L("12.34.56pm ")); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==34); sl@0: test(dateTime.Second()==56); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("12:34:56am ERROR")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 : 56 am 05/jan/1996 ")); sl@0: test(error==(EParseTimePresent|EParseDatePresent)); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Minute()==56); sl@0: } sl@0: sl@0: LOCAL_D void SimpleDateFormats() sl@0: { sl@0: TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); sl@0: TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); sl@0: TTime before2000(before2000DateTime); sl@0: TTime after2000(after2000DateTime); sl@0: sl@0: for (TInt ii=0;ii<=1;ii++) sl@0: { sl@0: TBool currentTimeIsBeforeYear2000=ETrue; sl@0: if (ii==0) sl@0: { sl@0: User::SetUTCTime(before2000); sl@0: currentTimeIsBeforeYear2000=ETrue; sl@0: } sl@0: else if (ii==1) sl@0: { sl@0: User::SetUTCTime(after2000); sl@0: currentTimeIsBeforeYear2000=EFalse; sl@0: } sl@0: TInt error; sl@0: TDateTime dateTime; sl@0: DateTimeParse(dateTime,_L("5/6/1996")); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: sl@0: DateTimeParse(dateTime,_L("5-6,1996")); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: sl@0: DateTimeParse(dateTime,_L("5 6 1996")); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: sl@0: DateTimeParse(dateTime,_L("5 ; 6 1996")); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: sl@0: sl@0: DateTimeParse(dateTime,_L("5 / 6, 96 ")); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1996); sl@0: else sl@0: test(dateTime.Year()==2096); sl@0: sl@0: DateTimeParse(dateTime,_L("5/6/19 "),20); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==2019); sl@0: sl@0: DateTimeParse(dateTime,_L("5/6/20 "),20); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1920); sl@0: sl@0: DateTimeParse(dateTime,_L("5/6/00"),20); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==2000); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/00 "),00); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1900); sl@0: else sl@0: test(dateTime.Year()==2000); sl@0: sl@0: error=DateTimeParse(dateTime,_L("june 5 /00 "),00); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1900); sl@0: else sl@0: test(dateTime.Year()==2000); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5 june/00 "),00); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1900); sl@0: else sl@0: test(dateTime.Year()==2000); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5june 96 "),00); sl@0: test(error==KErrArgument); sl@0: sl@0: // two field dates sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5-6,")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/ "),20); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("july 11"),20); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==10); sl@0: test(dateTime.Month()==EJuly); sl@0: test(dateTime.Year()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("11 july"),20); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==10); sl@0: test(dateTime.Month()==EJuly); sl@0: test(dateTime.Year()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("june 5 "),00); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5 june/ "),00); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5june "),00); sl@0: test(error==KErrArgument); sl@0: sl@0: DateTimeParse(dateTime,_L("5/6/1")); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: DateTimeParse(dateTime,_L("5/6/01")); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: DateTimeParse(dateTime,_L("5/6/001")); sl@0: test(dateTime.Year()==0001); sl@0: DateTimeParse(dateTime,_L("5/6/0001")); sl@0: test(dateTime.Year()==0001); sl@0: } sl@0: } sl@0: sl@0: LOCAL_D void DateTimeFormats() sl@0: { sl@0: TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); sl@0: TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); sl@0: TTime before2000(before2000DateTime); sl@0: TTime after2000(after2000DateTime); sl@0: sl@0: for (TInt ii=0;ii<=1;ii++) sl@0: { sl@0: TBool currentTimeIsBeforeYear2000=ETrue; sl@0: if (ii==0) sl@0: { sl@0: User::SetUTCTime(before2000); sl@0: currentTimeIsBeforeYear2000=ETrue; sl@0: } sl@0: else if (ii==1) sl@0: { sl@0: User::SetUTCTime(after2000); sl@0: currentTimeIsBeforeYear2000=EFalse; sl@0: } sl@0: TInt error; sl@0: TDateTime dateTime; sl@0: error=DateTimeParse(dateTime,_L("5/6/1996 10am")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==10); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/1996 10 pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/1996 10 : 30 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Minute()==30); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Minute()==40); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 . 01 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5-6 ,1996 10 : 40 . 01 pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("20- feb /96 12 : 40 . 01 am")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==19); sl@0: test(dateTime.Month()==EFebruary); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==0); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1996); sl@0: else sl@0: test(dateTime.Year()==2096); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/1996 10 : 40 . 01 . 02 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==2); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5-6 ,1996 10 : 40 . 01 . 03 pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==1996); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==3); sl@0: sl@0: error=DateTimeParse(dateTime,_L("20- feb /96 12 : 40 . 01 . 04 am")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==19); sl@0: test(dateTime.Month()==EFebruary); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==4); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1996); sl@0: else sl@0: test(dateTime.Year()==2096); sl@0: sl@0: error=DateTimeParse(dateTime,_L("20- feb /9612 : 40.01am")); sl@0: test(error==KErrGeneral); sl@0: sl@0: // two field dates sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6 10am")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: test(dateTime.Hour()==10); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6/ 10 pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: test(dateTime.Hour()==22); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6 10 : 40 . 01 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5-6 , 10 : 40 . 01 pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5/6 10 : 40 . 01 . 02")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==2); sl@0: sl@0: error=DateTimeParse(dateTime,_L("5-6 , 10 : 40 . 01 . 05pm ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: test(dateTime.Year()==0); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Minute()==40); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==5); sl@0: sl@0: } sl@0: } sl@0: sl@0: LOCAL_D void TimeDateFormats() sl@0: { sl@0: TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); sl@0: TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); sl@0: TTime before2000(before2000DateTime); sl@0: TTime after2000(after2000DateTime); sl@0: sl@0: for (TInt ii=0;ii<=1;ii++) sl@0: { sl@0: TBool currentTimeIsBeforeYear2000=ETrue; sl@0: if (ii==0) sl@0: { sl@0: User::SetUTCTime(before2000); sl@0: currentTimeIsBeforeYear2000=ETrue; sl@0: } sl@0: else if (ii==1) sl@0: { sl@0: User::SetUTCTime(after2000); sl@0: currentTimeIsBeforeYear2000=EFalse; sl@0: } sl@0: TInt error; sl@0: TDateTime dateTime; sl@0: error=DateTimeParse(dateTime,_L("10pm 5/6/96")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1996); sl@0: else sl@0: test(dateTime.Year()==2096); sl@0: sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 am 5 -feb,03 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Hour()==00); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EFebruary); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1903); sl@0: else sl@0: test(dateTime.Year()==2003); sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 .56am 5 -feb,03 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Hour()==00); sl@0: test(dateTime.Minute()==56); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EFebruary); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1903); sl@0: else sl@0: test(dateTime.Year()==2003); sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 .56:01.03pm 5 -SEPTEMBER,03 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==56); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.MicroSecond()==03); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==ESeptember); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1903); sl@0: else sl@0: test(dateTime.Year()==2003); sl@0: sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 .56:01pm SEPTEMBER 5,03 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==56); sl@0: test(dateTime.Second()==01); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==ESeptember); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1903); sl@0: else sl@0: test(dateTime.Year()==2003); sl@0: sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 .0056:01pm 5 -SEPTEMBERX,03 ")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("12 .56:015 -SEPTEMBER,03 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Hour()==12); sl@0: test(dateTime.Minute()==56); sl@0: test(dateTime.Second()==15); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==ESeptember); sl@0: test(dateTime.Year()==0); sl@0: sl@0: // max descriptor length 27 tokens// 13 tokens after spaces are striped sl@0: error=DateTimeParse(dateTime,_L(" 10 : 00 : 00 . 123456 pm 5 / 6 / 96 ")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.MicroSecond()==123456); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Day()==4); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1996); sl@0: else sl@0: test(dateTime.Year()==2096); sl@0: sl@0: sl@0: // the formaula array will overflow with too many tokens sl@0: error=DateTimeParse(dateTime,_L(" 10 : 00 : 00 pm 5 / 6 / 96 / / / / / / / / / / / / / / / ")); sl@0: test(error==KErrArgument); sl@0: } sl@0: } sl@0: sl@0: LOCAL_D void BadDescriptors() sl@0: { sl@0: sl@0: TInt error; sl@0: TDateTime dateTime; sl@0: error=DateTimeParse(dateTime,_L("10pmpm")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10pmX")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1111")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10::10")); sl@0: test(error==KErrGeneral); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10-,10")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" - 10:10")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 10 10:10")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 5 june 10000")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("24:01")); sl@0: test(error==KErrGeneral); sl@0: sl@0: error=DateTimeParse(dateTime,_L("may 2, 9623:34:45")); sl@0: test(error==KErrGeneral); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 9/10/- ")); sl@0: test(error==KErrArgument); sl@0: } sl@0: sl@0: LOCAL_D void TestLocaleChanges() sl@0: { sl@0: TDateTime before2000DateTime(1999,EJanuary,0,0,0,0,0); sl@0: TDateTime after2000DateTime(2001,EJanuary,0,0,0,0,0); sl@0: TTime before2000(before2000DateTime); sl@0: TTime after2000(after2000DateTime); sl@0: sl@0: for (TInt ii=0;ii<=1;ii++) sl@0: { sl@0: TBool currentTimeIsBeforeYear2000=ETrue; sl@0: if (ii==0) sl@0: { sl@0: User::SetUTCTime(before2000); sl@0: currentTimeIsBeforeYear2000=ETrue; sl@0: } sl@0: else if (ii==1) sl@0: { sl@0: User::SetUTCTime(after2000); sl@0: currentTimeIsBeforeYear2000=EFalse; sl@0: } sl@0: TLocale locale; sl@0: locale.Refresh(); sl@0: TLocale savedLocale; sl@0: TInt error; sl@0: TDateTime dateTime; sl@0: sl@0: //Set decimal separator in locale to another value: sl@0: locale.SetDecimalSeparator('!'); sl@0: locale.Set(); sl@0: error=DateTimeParse(dateTime,_L("3/6 10:10:10!111111")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.MicroSecond()==111111); sl@0: test(dateTime.Second()==10); sl@0: test(dateTime.Minute()==10); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EJune); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1/6/12")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==0); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1912); sl@0: else sl@0: test(dateTime.Year()==2012); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" dec 3 12"),10); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EDecember); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1912); sl@0: else sl@0: test(dateTime.Year()==1912); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 3 dec 12 "),12); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EDecember); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1912); sl@0: else sl@0: test(dateTime.Year()==1912); sl@0: sl@0: TDateFormat dateFormat=EDateAmerican; sl@0: locale.SetDateFormat(dateFormat); sl@0: locale.Set(); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1/6/12")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==5); sl@0: test(dateTime.Month()==EJanuary); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1912); sl@0: else sl@0: test(dateTime.Year()==2012); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" dec 3 12"),13); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EDecember); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==2012); sl@0: else sl@0: test(dateTime.Year()==2012); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 3 dec 12 ")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EDecember); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1912); sl@0: else sl@0: test(dateTime.Year()==2012); sl@0: sl@0: dateFormat=EDateJapanese; sl@0: locale.SetDateFormat(dateFormat); sl@0: locale.Set(); sl@0: sl@0: error=DateTimeParse(dateTime,_L("3/17")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==16); sl@0: test(dateTime.Month()==EMarch); sl@0: test(dateTime.Year()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1/6/12")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==11); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1*6*12")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1+6+12")); sl@0: test(error==KErrArgument); sl@0: sl@0: locale.SetDateSeparator('*',1); sl@0: locale.SetDateSeparator('+',2); sl@0: locale.Set(); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1*6*12")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==11); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1+6+12")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==11); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1+6+12 14:32.54am")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Second()==54); sl@0: test(dateTime.Minute()==32); sl@0: test(dateTime.Hour()==14); sl@0: test(dateTime.Day()==11); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10p 1+6+12")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Day()==11); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1901); sl@0: else sl@0: test(dateTime.Year()==2001); sl@0: sl@0: // European sl@0: locale.SetDateFormat(EDateEuropean); sl@0: locale.SetDateSeparator('.',2); sl@0: locale.Set(); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1+6+12")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L("3.6.86")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1986); sl@0: else sl@0: test(dateTime.Year()==2086); sl@0: sl@0: error=DateTimeParse(dateTime,_L("3.6.86 10:10:10")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Second()==10); sl@0: test(dateTime.Minute()==10); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1986); sl@0: else sl@0: test(dateTime.Year()==2086); sl@0: sl@0: locale.SetDateSeparator(':',1); sl@0: locale.Set(); sl@0: sl@0: error=DateTimeParse(dateTime,_L("3.6.86 10:10:10")); sl@0: test(error==KErrArgument); sl@0: // test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Second()==10); sl@0: test(dateTime.Minute()==10); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1986); sl@0: else sl@0: test(dateTime.Year()==2086); sl@0: sl@0: error=DateTimeParse(dateTime,_L("3:6:86 10.10.10")); sl@0: test(error==KErrArgument); sl@0: test(dateTime.Second()==10); sl@0: test(dateTime.Minute()==10); sl@0: test(dateTime.Hour()==10); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1986); sl@0: else sl@0: test(dateTime.Year()==2086); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10.10")); sl@0: test(error==EParseDatePresent); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==9); sl@0: test(dateTime.Month()==EOctober); sl@0: test(dateTime.Year()==0); sl@0: sl@0: // If the date sep has been set to '.' then 10th October sl@0: error=DateTimeParse(dateTime,_L("10.10pm")); sl@0: test(error==KErrArgument); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==0); sl@0: test(dateTime.Day()==9); sl@0: test(dateTime.Month()==EOctober); sl@0: test(dateTime.Year()==0); sl@0: sl@0: error=DateTimeParse(dateTime,_L("10p 3:6:86")); sl@0: test(error==(EParseDatePresent|EParseTimePresent)); sl@0: test(dateTime.Second()==0); sl@0: test(dateTime.Minute()==0); sl@0: test(dateTime.Hour()==22); sl@0: test(dateTime.Day()==2); sl@0: test(dateTime.Month()==EJune); sl@0: if (currentTimeIsBeforeYear2000) sl@0: test(dateTime.Year()==1986); sl@0: else sl@0: test(dateTime.Year()==2086); sl@0: sl@0: error=DateTimeParse(dateTime,_L("1:6:12 3.05.06")); sl@0: test(error==KErrArgument); sl@0: sl@0: error=DateTimeParse(dateTime,_L(" 3.05.06 1:6:12")); sl@0: test(error==KErrArgument); sl@0: sl@0: locale.Refresh(); sl@0: savedLocale.Set(); sl@0: } sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Begin tests")); sl@0: TLocale currentLocale; sl@0: sl@0: TLocale b; sl@0: b.SetDateSeparator('\0',0); sl@0: b.SetDateSeparator('/',1); sl@0: b.SetDateSeparator('/',2); sl@0: b.SetDateSeparator('\0',3); sl@0: b.SetDateFormat(EDateEuropean); sl@0: b.SetTimeFormat(ETime12); sl@0: b.SetTimeSeparator('\0',0); sl@0: b.SetTimeSeparator(':',1); sl@0: b.SetTimeSeparator(':',2); sl@0: b.SetTimeSeparator('\0',3); sl@0: b.SetAmPmSpaceBetween(ETrue); sl@0: b.SetAmPmSymbolPosition(ELocaleAfter); sl@0: b.SetWorkDays(0x1F); sl@0: b.SetStartOfWeek(EMonday); sl@0: b.Set(); sl@0: sl@0: TTimeIntervalSeconds oldOffset = User::UTCOffset(); sl@0: User::SetUTCOffset(0); sl@0: sl@0: test.Console()->Printf(_L("SimpleTimeFormats\n")); sl@0: SimpleTimeFormats(); sl@0: test.Console()->Printf(_L("SimpleDateFormats\n")); sl@0: SimpleDateFormats(); sl@0: test.Console()->Printf(_L("DateTimeFormats\n")); sl@0: DateTimeFormats(); sl@0: test.Console()->Printf(_L("TimeDateFormats\n")); sl@0: TimeDateFormats(); sl@0: test.Console()->Printf(_L("BadDescriptors\n")); sl@0: BadDescriptors(); sl@0: test.Console()->Printf(_L("TestLocaleChanges\n")); sl@0: TestLocaleChanges(); sl@0: test.Console()->Printf(_L("End of tests\n")); sl@0: currentLocale.Set(); sl@0: User::SetUTCOffset(oldOffset); sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: