sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "util.h" sl@0: #include sl@0: sl@0: _LIT(KDaylightSavingsMinFormat, "%F%Y0224:"); sl@0: _LIT(KDaylightSavingsMaxFormat, "%F%Y0924:"); sl@0: sl@0: void Util::SetAppropriateTimezoneL() sl@0: { sl@0: TUid repUid = {0x1020e4d3}; sl@0: CRepository* rep = CRepository::NewLC(repUid); sl@0: sl@0: // Set the date format to European sl@0: User::LeaveIfError(rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction)); sl@0: User::LeaveIfError(rep->Set(101, EDateEuropean)); // 101 is the date format reg entry sl@0: TUint32 keys(0); sl@0: User::LeaveIfError(rep->CommitTransaction(keys)); sl@0: sl@0: CleanupStack::PopAndDestroy(rep); sl@0: sl@0: TExtendedLocale locale; sl@0: locale.LoadSystemSettings(); sl@0: locale.GetLocale()->SetDateFormat(EDateEuropean); sl@0: User::LeaveIfError(locale.SaveSystemSettings()); sl@0: } sl@0: sl@0: TBool Util::DaylightSavingsAppliesL(const TTime& utc) sl@0: { sl@0: sl@0: // This algorithm needs the first day of the week to be monday sl@0: sl@0: TDay oldStart; sl@0: sl@0: TLocale set; sl@0: oldStart = set.StartOfWeek(); sl@0: set.SetStartOfWeek(EMonday); sl@0: set.Set(); sl@0: sl@0: TBuf<9> min; sl@0: TBuf<9> max; sl@0: sl@0: utc.FormatL(min, KDaylightSavingsMinFormat); sl@0: utc.FormatL(max, KDaylightSavingsMaxFormat); sl@0: sl@0: // Get times representing the first/last possible day of this sl@0: // year that daylight savings time change could change on sl@0: sl@0: TTime timeMin; sl@0: User::LeaveIfError(timeMin.Set(min)); sl@0: TTime timeMax; sl@0: User::LeaveIfError(timeMax.Set(max)); sl@0: sl@0: // Find the last sunday in the respective months sl@0: sl@0: TTimeIntervalDays addMin(6 - timeMin.DayNoInWeek()); sl@0: TTimeIntervalDays addMax(6 - timeMax.DayNoInWeek()); sl@0: sl@0: timeMin += addMin; sl@0: timeMax += addMax; sl@0: sl@0: // The change happens at 1AM. sl@0: TTimeIntervalHours hour(1); sl@0: timeMin += hour; sl@0: timeMax += hour; sl@0: sl@0: // Now we know which day the change occurs on. sl@0: // Compare it to what the UTC is. sl@0: sl@0: TBool result = ((timeMin <= utc) && (timeMax > utc)); sl@0: sl@0: // reset the first week day sl@0: set.SetStartOfWeek(oldStart); sl@0: set.Set(); sl@0: sl@0: return result; sl@0: sl@0: }