Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <centralrepository.h>
22 _LIT(KDaylightSavingsMinFormat, "%F%Y0224:");
23 _LIT(KDaylightSavingsMaxFormat, "%F%Y0924:");
25 void Util::SetAppropriateTimezoneL()
27 TUid repUid = {0x1020e4d3};
28 CRepository* rep = CRepository::NewLC(repUid);
30 // Set the date format to European
31 User::LeaveIfError(rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction));
32 User::LeaveIfError(rep->Set(101, EDateEuropean)); // 101 is the date format reg entry
34 User::LeaveIfError(rep->CommitTransaction(keys));
36 CleanupStack::PopAndDestroy(rep);
38 TExtendedLocale locale;
39 locale.LoadSystemSettings();
40 locale.GetLocale()->SetDateFormat(EDateEuropean);
41 User::LeaveIfError(locale.SaveSystemSettings());
44 TBool Util::DaylightSavingsAppliesL(const TTime& utc)
47 // This algorithm needs the first day of the week to be monday
52 oldStart = set.StartOfWeek();
53 set.SetStartOfWeek(EMonday);
59 utc.FormatL(min, KDaylightSavingsMinFormat);
60 utc.FormatL(max, KDaylightSavingsMaxFormat);
62 // Get times representing the first/last possible day of this
63 // year that daylight savings time change could change on
66 User::LeaveIfError(timeMin.Set(min));
68 User::LeaveIfError(timeMax.Set(max));
70 // Find the last sunday in the respective months
72 TTimeIntervalDays addMin(6 - timeMin.DayNoInWeek());
73 TTimeIntervalDays addMax(6 - timeMax.DayNoInWeek());
78 // The change happens at 1AM.
79 TTimeIntervalHours hour(1);
83 // Now we know which day the change occurs on.
84 // Compare it to what the UTC is.
86 TBool result = ((timeMin <= utc) && (timeMax > utc));
88 // reset the first week day
89 set.SetStartOfWeek(oldStart);