|
1 // Copyright (c) 2005-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 "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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32debug.h> |
|
17 #include <tz.h> |
|
18 |
|
19 // This function is used to update month and day in aBufLocalTime |
|
20 // to actual month and day to be passed to TTime() constructor. |
|
21 // Remember using TTime::FormatL() in thelpers.cpp |
|
22 // has added extra month and a day to aBufLocalTime. |
|
23 // aBufLocalTime is in format YYMMDD:HHMMSS.MMMMMM |
|
24 // see TTime::Set() for aBufLocalTime expected format details. |
|
25 TInt UpdateToActualMonthAndDay(TDes& aBufLocalTime) |
|
26 { |
|
27 TInt mVal = 0; |
|
28 TInt dVal = 0; |
|
29 |
|
30 TBuf <4> tempBuf; |
|
31 _LIT(KFormat, "%02d"); |
|
32 |
|
33 //Get the position of colon separator |
|
34 TInt colon = aBufLocalTime.Locate(':'); |
|
35 |
|
36 // Get Month & Day if Present |
|
37 switch(colon) |
|
38 { |
|
39 case 0: break; |
|
40 case 8: |
|
41 { |
|
42 TLex month = aBufLocalTime.Mid(4,2); |
|
43 TLex day = aBufLocalTime.Mid(6,2); |
|
44 month.Val(mVal); |
|
45 day.Val(dVal); |
|
46 } |
|
47 break; |
|
48 default: |
|
49 { |
|
50 // If the colon is at the wrong position. |
|
51 return (KErrArgument); |
|
52 } |
|
53 |
|
54 } |
|
55 |
|
56 // Deduct extra month and a day and update aBufLocalTime |
|
57 if(mVal > 0 && dVal > 0) |
|
58 { |
|
59 mVal-=1; |
|
60 dVal-=1; |
|
61 |
|
62 tempBuf.Format(KFormat, mVal); |
|
63 aBufLocalTime.Replace(4,2, tempBuf); |
|
64 |
|
65 tempBuf.Format(KFormat, dVal); |
|
66 aBufLocalTime.Replace(6,2, tempBuf); |
|
67 } |
|
68 |
|
69 return(KErrNone); |
|
70 } |
|
71 |
|
72 //This function is used in the test code to Set the system time to the given local time. |
|
73 static TInt SetHomeTimeL(TTime& aLocalTime) |
|
74 { |
|
75 TInt retVal = KErrNone; |
|
76 RTz theTzSrv; |
|
77 |
|
78 User::LeaveIfError(theTzSrv.Connect()); |
|
79 CleanupClosePushL(theTzSrv); |
|
80 |
|
81 retVal = theTzSrv.SetHomeTime(aLocalTime); |
|
82 |
|
83 CleanupStack::PopAndDestroy(); //theTzSrv.Close() |
|
84 return retVal; |
|
85 } |
|
86 |
|
87 GLDEF_C TInt E32Main() |
|
88 { |
|
89 TInt err = KErrNone; |
|
90 TInt retVal = KErrNone; |
|
91 TBuf<64> bufLocalTime; |
|
92 |
|
93 User::CommandLine(bufLocalTime); |
|
94 |
|
95 retVal = UpdateToActualMonthAndDay(bufLocalTime); |
|
96 |
|
97 if(retVal == KErrNone) |
|
98 { |
|
99 TTime localTime(bufLocalTime); |
|
100 |
|
101 CTrapCleanup* cleanup = CTrapCleanup::New(); //can fail |
|
102 if (cleanup) |
|
103 { |
|
104 TRAP(err, retVal = SetHomeTimeL(localTime)) |
|
105 if(err != KErrNone) |
|
106 { |
|
107 retVal = err; |
|
108 } |
|
109 delete cleanup; |
|
110 } |
|
111 } |
|
112 |
|
113 return retVal; |
|
114 } |