|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "util.h" |
|
18 #include <centralrepository.h> |
|
19 |
|
20 _LIT(KDaylightSavingsMinFormat, "%F%Y0224:"); |
|
21 _LIT(KDaylightSavingsMaxFormat, "%F%Y0924:"); |
|
22 |
|
23 void Util::SetAppropriateTimezoneL() |
|
24 { |
|
25 TUid repUid = {0x1020e4d3}; |
|
26 CRepository* rep = CRepository::NewLC(repUid); |
|
27 |
|
28 // Set the date format to European |
|
29 User::LeaveIfError(rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction)); |
|
30 User::LeaveIfError(rep->Set(101, EDateEuropean)); // 101 is the date format reg entry |
|
31 TUint32 keys(0); |
|
32 User::LeaveIfError(rep->CommitTransaction(keys)); |
|
33 |
|
34 CleanupStack::PopAndDestroy(rep); |
|
35 |
|
36 TExtendedLocale locale; |
|
37 locale.LoadSystemSettings(); |
|
38 locale.GetLocale()->SetDateFormat(EDateEuropean); |
|
39 User::LeaveIfError(locale.SaveSystemSettings()); |
|
40 } |
|
41 |
|
42 TBool Util::DaylightSavingsAppliesL(const TTime& utc) |
|
43 { |
|
44 |
|
45 // This algorithm needs the first day of the week to be monday |
|
46 |
|
47 TDay oldStart; |
|
48 |
|
49 TLocale set; |
|
50 oldStart = set.StartOfWeek(); |
|
51 set.SetStartOfWeek(EMonday); |
|
52 set.Set(); |
|
53 |
|
54 TBuf<9> min; |
|
55 TBuf<9> max; |
|
56 |
|
57 utc.FormatL(min, KDaylightSavingsMinFormat); |
|
58 utc.FormatL(max, KDaylightSavingsMaxFormat); |
|
59 |
|
60 // Get times representing the first/last possible day of this |
|
61 // year that daylight savings time change could change on |
|
62 |
|
63 TTime timeMin; |
|
64 User::LeaveIfError(timeMin.Set(min)); |
|
65 TTime timeMax; |
|
66 User::LeaveIfError(timeMax.Set(max)); |
|
67 |
|
68 // Find the last sunday in the respective months |
|
69 |
|
70 TTimeIntervalDays addMin(6 - timeMin.DayNoInWeek()); |
|
71 TTimeIntervalDays addMax(6 - timeMax.DayNoInWeek()); |
|
72 |
|
73 timeMin += addMin; |
|
74 timeMax += addMax; |
|
75 |
|
76 // The change happens at 1AM. |
|
77 TTimeIntervalHours hour(1); |
|
78 timeMin += hour; |
|
79 timeMax += hour; |
|
80 |
|
81 // Now we know which day the change occurs on. |
|
82 // Compare it to what the UTC is. |
|
83 |
|
84 TBool result = ((timeMin <= utc) && (timeMax > utc)); |
|
85 |
|
86 // reset the first week day |
|
87 set.SetStartOfWeek(oldStart); |
|
88 set.Set(); |
|
89 |
|
90 return result; |
|
91 |
|
92 } |