/* Intended Usage: Utility routine for converting from UTC to localtime. */ inline time_t toLocal (const time_t aUniversalTime) { #ifndef __SERIES60_MRT_1_0 TTimeIntervalSeconds offset = User::UTCOffset(); return aUniversalTime + offset.Int(); #else TLocale locale; return aUniversalTime + locale.UniversalTimeOffset().Int(); #endif //__SERIES60_MRT_1_0 }
// --------------------------------------------------------------------------- // TPresCondValidity::ConvertToLocal() // --------------------------------------------------------------------------- // void TPresCondValidity::ConvertToLocal(TTime& aDateTime) { OPENG_DP(D_OPENG_LIT( " TPresCondValidity::ConvertToLocal()" ) ); OPENG_DP(D_OPENG_LIT( " ConvertToLocal aDateTime:")); LogDateTime(aDateTime.DateTime()); TLocale myLocale; myLocale.Refresh(); // getting UTC difference TTimeIntervalSeconds uTCseconds = myLocale.UniversalTimeOffset(); aDateTime = aDateTime + uTCseconds; }
bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local) { TDateTime Date; TTime ot; if (!tp || t == INVALID_DATETIME_T) return 0; ot = DateTimeToSymbian(t); if (Local) { #ifndef SYMBIAN90 TLocale locale; TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset()); ot += universalTimeOffset; if (locale.QueryHomeHasDaylightSavingOn()) { TTimeIntervalHours daylightSaving(1); ot += daylightSaving; } #else RTz TzServer; if (TzServer.Connect()==KErrNone) { CTzConverter* Converter = CTzConverter::NewL(TzServer); Converter->ConvertToLocalTime(ot); delete Converter; TzServer.Close(); } #endif } Date = ot.DateTime(); tp->Year = Date.Year(); tp->Month = (int)Date.Month() + 1; tp->Day = Date.Day()+1; tp->Hour = Date.Hour(); tp->Minute = Date.Minute(); tp->Second = Date.Second(); return 1; }
datetime_t TimePackToRel(const datepack_t *tp, bool_t Local) { TDateTime Date; TTime ot; if (!tp) return INVALID_DATETIME_T; Date.SetYear(tp->Year); Date.SetMonth((TMonth)(tp->Month-1)); Date.SetDay(tp->Day-1); Date.SetHour(tp->Hour); Date.SetMinute(tp->Minute); Date.SetSecond(tp->Second); ot = TTime(Date); if (Local) { #ifndef SYMBIAN90 TLocale locale; TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset()); ot -= universalTimeOffset; if (locale.QueryHomeHasDaylightSavingOn()) { TTimeIntervalHours daylightSaving(1); ot -= daylightSaving; } #else RTz TzServer; if (TzServer.Connect()==KErrNone) { CTzConverter* Converter = CTzConverter::NewL(TzServer); Converter->ConvertToUniversalTime(ot); delete Converter; TzServer.Close(); } #endif } return SymbianToDateTime(ot); }
void DoLog(const TDesC& aText) { static const TInt KLogEntryMaxLength = 128; _LIT(KLineFeed, "\n"); /** * Log time format (see TTime) is * Day-Month-Year Hours:Minutes:Seconds:Milliseconds * * Example: 30-12-2004 23:00:55:990 */ _LIT(KLogTimeFormat, "%F%D-%M-%Y %H:%T:%S:%*C3"); TBuf8<KLogEntryMaxLength> writeBuffer; RFs FileServer; RFile File; if(FileServer.Connect() != KErrNone) { FileServer.Close(); // just in case User::Panic(KLogPanicCategory(), KPanicFsConnectFailed); return; } // Open file for writing, if exists. Othervise create new file. if(File.Open(FileServer, KLogFileName(), EFileWrite) != KErrNone) { if(File.Create(FileServer, KLogFileName(), EFileWrite) != KErrNone) { FileServer.Close(); User::Panic(KLogPanicCategory(), KPanicFileCreateFailed); } } TTime currentTime; currentTime.UniversalTime(); TBuf<32> timeString; // currentTime is now in universal time. Convert it to home time. TLocale locale; TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset()); TTimeIntervalHours daylightSaving(0); if(locale.QueryHomeHasDaylightSavingOn()) { daylightSaving = 1; } currentTime = currentTime + universalTimeOffset + daylightSaving; TInt leaveCode(KErrNone); TRAP(leaveCode, currentTime.FormatL(timeString, KLogTimeFormat)); leaveCode = 0; // not used // Add LogString to the end of file and close the file TInt currentSize = 0, returnCode; writeBuffer.Append(timeString); writeBuffer.Append(_L(": ")); writeBuffer.Append(aText.Left(KLogEntryMaxLength-timeString.Length())); writeBuffer.Append(KLineFeed); File.Size(currentSize); returnCode = File.Write(currentSize, writeBuffer, writeBuffer.Length()); File.Close(); // Close file server session FileServer.Close(); if(returnCode != KErrNone) { User::Panic(KLogPanicCategory(), KPanicFileWriteFailed); } }