sl@0: // Copyright (c) 2005-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 "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: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // This function is used to update month and day in aBufLocalTime sl@0: // to actual month and day to be passed to TTime() constructor. sl@0: // Remember using TTime::FormatL() in thelpers.cpp sl@0: // has added extra month and a day to aBufLocalTime. sl@0: // aBufLocalTime is in format YYMMDD:HHMMSS.MMMMMM sl@0: // see TTime::Set() for aBufLocalTime expected format details. sl@0: TInt UpdateToActualMonthAndDay(TDes& aBufLocalTime) sl@0: { sl@0: TInt mVal = 0; sl@0: TInt dVal = 0; sl@0: sl@0: TBuf <4> tempBuf; sl@0: _LIT(KFormat, "%02d"); sl@0: sl@0: //Get the position of colon separator sl@0: TInt colon = aBufLocalTime.Locate(':'); sl@0: sl@0: // Get Month & Day if Present sl@0: switch(colon) sl@0: { sl@0: case 0: break; sl@0: case 8: sl@0: { sl@0: TLex month = aBufLocalTime.Mid(4,2); sl@0: TLex day = aBufLocalTime.Mid(6,2); sl@0: month.Val(mVal); sl@0: day.Val(dVal); sl@0: } sl@0: break; sl@0: default: sl@0: { sl@0: // If the colon is at the wrong position. sl@0: return (KErrArgument); sl@0: } sl@0: sl@0: } sl@0: sl@0: // Deduct extra month and a day and update aBufLocalTime sl@0: if(mVal > 0 && dVal > 0) sl@0: { sl@0: mVal-=1; sl@0: dVal-=1; sl@0: sl@0: tempBuf.Format(KFormat, mVal); sl@0: aBufLocalTime.Replace(4,2, tempBuf); sl@0: sl@0: tempBuf.Format(KFormat, dVal); sl@0: aBufLocalTime.Replace(6,2, tempBuf); sl@0: } sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: //This function is used in the test code to Set the system time to the given local time. sl@0: static TInt SetHomeTimeL(TTime& aLocalTime) sl@0: { sl@0: TInt retVal = KErrNone; sl@0: RTz theTzSrv; sl@0: sl@0: User::LeaveIfError(theTzSrv.Connect()); sl@0: CleanupClosePushL(theTzSrv); sl@0: sl@0: retVal = theTzSrv.SetHomeTime(aLocalTime); sl@0: sl@0: CleanupStack::PopAndDestroy(); //theTzSrv.Close() sl@0: return retVal; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt retVal = KErrNone; sl@0: TBuf<64> bufLocalTime; sl@0: sl@0: User::CommandLine(bufLocalTime); sl@0: sl@0: retVal = UpdateToActualMonthAndDay(bufLocalTime); sl@0: sl@0: if(retVal == KErrNone) sl@0: { sl@0: TTime localTime(bufLocalTime); sl@0: sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); //can fail sl@0: if (cleanup) sl@0: { sl@0: TRAP(err, retVal = SetHomeTimeL(localTime)) sl@0: if(err != KErrNone) sl@0: { sl@0: retVal = err; sl@0: } sl@0: delete cleanup; sl@0: } sl@0: } sl@0: sl@0: return retVal; sl@0: }