1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSUtils/TSetUTCTime.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32std.h>
1.20 +#include <e32debug.h>
1.21 +
1.22 +// This function is used to update month and day in aBufLocalTime
1.23 +// to actual month and day to be passed to TTime() constructor.
1.24 +// Remember using TTime::FormatL() in thelpers.cpp
1.25 +// has added extra month and a day to aBufLocalTime.
1.26 +// aBufLocalTime is in format YYMMDD:HHMMSS.MMMMMM
1.27 +// see TTime::Set() for aBufLocalTime expected format details.
1.28 +TInt UpdateToActualMonthAndDay(TDes& aBufUTCTime)
1.29 + {
1.30 + TInt mVal = 0;
1.31 + TInt dVal = 0;
1.32 +
1.33 + TBuf <4> tempBuf;
1.34 + _LIT(KFormat, "%02d");
1.35 +
1.36 + //Get the position of colon separator
1.37 + TInt colon = aBufUTCTime.Locate(':');
1.38 +
1.39 + // Get Month & Day if Present
1.40 + switch(colon)
1.41 + {
1.42 + case 0: break;
1.43 + case 8:
1.44 + {
1.45 + TLex month = aBufUTCTime.Mid(4,2);
1.46 + TLex day = aBufUTCTime.Mid(6,2);
1.47 + month.Val(mVal);
1.48 + day.Val(dVal);
1.49 + }
1.50 + break;
1.51 + default:
1.52 + {
1.53 + // If the colon is at the wrong position
1.54 + return (KErrArgument);
1.55 + }
1.56 +
1.57 + }
1.58 +
1.59 + // Deduct extra month and a day and update aBufLocalTime
1.60 + if(mVal > 0 && dVal > 0)
1.61 + {
1.62 + mVal-=1;
1.63 + dVal-=1;
1.64 +
1.65 + tempBuf.Format(KFormat, mVal);
1.66 + aBufUTCTime.Replace(4,2, tempBuf);
1.67 +
1.68 + tempBuf.Format(KFormat, dVal);
1.69 + aBufUTCTime.Replace(6,2, tempBuf);
1.70 + }
1.71 +
1.72 + return(KErrNone);
1.73 + }
1.74 +
1.75 +GLDEF_C TInt E32Main()
1.76 + {
1.77 + TInt err = KErrNone;
1.78 + TBuf<64> bufUTCTime;
1.79 +
1.80 + User::CommandLine(bufUTCTime);
1.81 + err = UpdateToActualMonthAndDay(bufUTCTime);
1.82 +
1.83 + if( err == KErrNone)
1.84 + {
1.85 + TTime utcTime(bufUTCTime);
1.86 + err = User::SetUTCTime(utcTime);
1.87 + }
1.88 +
1.89 + return err;
1.90 + }
1.91 +