|
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 <e32std.h> |
|
17 #include <e32debug.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& aBufUTCTime) |
|
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 = aBufUTCTime.Locate(':'); |
|
35 |
|
36 // Get Month & Day if Present |
|
37 switch(colon) |
|
38 { |
|
39 case 0: break; |
|
40 case 8: |
|
41 { |
|
42 TLex month = aBufUTCTime.Mid(4,2); |
|
43 TLex day = aBufUTCTime.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 aBufUTCTime.Replace(4,2, tempBuf); |
|
64 |
|
65 tempBuf.Format(KFormat, dVal); |
|
66 aBufUTCTime.Replace(6,2, tempBuf); |
|
67 } |
|
68 |
|
69 return(KErrNone); |
|
70 } |
|
71 |
|
72 GLDEF_C TInt E32Main() |
|
73 { |
|
74 TInt err = KErrNone; |
|
75 TBuf<64> bufUTCTime; |
|
76 |
|
77 User::CommandLine(bufUTCTime); |
|
78 err = UpdateToActualMonthAndDay(bufUTCTime); |
|
79 |
|
80 if( err == KErrNone) |
|
81 { |
|
82 TTime utcTime(bufUTCTime); |
|
83 err = User::SetUTCTime(utcTime); |
|
84 } |
|
85 |
|
86 return err; |
|
87 } |
|
88 |