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_dparse.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: RTest test(_L("T_DPARSE")); sl@0: TInt offset=0; sl@0: sl@0: LOCAL_C TInt DateTimeParse(TDateTime& aDateTime,const TDesC& aDes,TInt aCenturyOffset=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 TInt ConvertDesToDateTimeInteractively() sl@0: { sl@0: TKeyCode code; sl@0: TBuf<32> buf; sl@0: buf.SetLength(0); sl@0: FOREVER sl@0: { sl@0: code = test.Console()->Getch(); sl@0: if (code==EKeyEnter || code==EKeyLineFeed) sl@0: break; sl@0: if (code==EKeyEscape) sl@0: return KErrGeneral; sl@0: if ((code==EKeyDelete || code==EKeyBackspace) && buf.Length()>0) sl@0: { sl@0: TChar del(code); sl@0: TBuf<1> delBuf; sl@0: delBuf.Append(del); sl@0: test.Printf(delBuf); sl@0: buf.SetLength(buf.Length()-1); sl@0: continue; sl@0: } sl@0: if (buf.Length()==0 && code==EKeyF1) sl@0: { sl@0: test.Printf(_L("Enter a two digit value. ")); sl@0: TKeyCode code1 = test.Console()->Getch(); sl@0: TKeyCode code2 = test.Console()->Getch(); sl@0: TChar ch1(code1); sl@0: TChar ch2(code2); sl@0: TBuf<2> centuryOffset; sl@0: centuryOffset.Append(ch1); sl@0: centuryOffset.Append(ch2); sl@0: TLex lex(centuryOffset); sl@0: if (lex.Val(offset)!=KErrNone) sl@0: return KErrGeneral; sl@0: test.Printf(_L("The century offset is set to %d\n"),offset); sl@0: if (ConvertDesToDateTimeInteractively()==KErrGeneral) sl@0: return KErrGeneral; sl@0: } sl@0: TChar ch(code); sl@0: buf.Append(ch); sl@0: TBuf<1> charBuf; sl@0: charBuf.Append(ch); sl@0: test.Printf(charBuf); sl@0: } sl@0: test.Printf(_L(" = ")); sl@0: TDateTime dateTime; sl@0: TInt error = DateTimeParse(dateTime,buf,offset); sl@0: TInt year = dateTime.Year(); sl@0: TInt month = dateTime.Month()+1; sl@0: TInt day = dateTime.Day()+1; sl@0: TInt hour = dateTime.Hour(); sl@0: TInt min = dateTime.Minute(); sl@0: TInt sec = dateTime.Second(); sl@0: TInt msec = dateTime.MicroSecond(); sl@0: switch(error) sl@0: { sl@0: case EParseTimePresent: sl@0: test.Printf(_L("%d:%d:%d.%d "),hour,min,sec,msec); sl@0: test.Printf(_L("Time\n")); sl@0: break; sl@0: case EParseDatePresent: sl@0: test.Printf(_L("%d/%d/%d "),day,month,year); sl@0: test.Printf(_L("Date\n")); sl@0: break; sl@0: case EParseTimePresent|EParseDatePresent: sl@0: test.Printf(_L("%d:%d:%d.%d %d/%d/%d "),hour,min,sec,msec,day,month,year); sl@0: test.Printf(_L("DateAndTime\n")); sl@0: break; sl@0: default: sl@0: test.Printf(_L("error\n")); sl@0: break; sl@0: } sl@0: if (ConvertDesToDateTimeInteractively()==KErrGeneral) sl@0: return KErrGeneral; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: TInt E32Main() sl@0: { sl@0: test.Start(_L("Begin tests")); sl@0: test.Console()->Printf(_L("Convert a Des To a DateTime.\n")); sl@0: test.Printf(_L("Enter a Date, a Time or a Date & Time.\n")); sl@0: test.Printf(_L("Press Escape to exit tests.\n")); sl@0: test.Printf(_L("Press the F1 key to set the century offset.\n")); sl@0: ConvertDesToDateTimeInteractively(); sl@0: test.End(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: