void CPigeonScheduledSend::PopulateOffPeakListL() { //There are no existing off peak times set up //So no need to remember them iOffPeakList->Reset(); TTime t; TDateTime d; t.HomeTime(); t -= TTimeIntervalHours(1); d = t.DateTime(); TTimeIntervalMinutes twoHours = 120; TMsvOffPeakTime current(t.DayNoInWeek(), d.Hour(), d.Minute(), twoHours); iOffPeakList->AppendL(current); t -= TTimeIntervalDays(1); d = t.DateTime(); TMsvOffPeakTime yesterday(t.DayNoInWeek(), d.Hour(), d.Minute(), twoHours); iOffPeakList->AppendL(yesterday); t += TTimeIntervalDays(2); d = t.DateTime(); TMsvOffPeakTime tomorrow(t.DayNoInWeek(), d.Hour(), d.Minute(), twoHours); iOffPeakList->AppendL(tomorrow); }
TBool Util::DaylightSavingsAppliesL(const TTime& utc) { // This algorithm needs the first day of the week to be monday TDay oldStart; TLocale set; oldStart = set.StartOfWeek(); set.SetStartOfWeek(EMonday); set.Set(); TBuf<9> min; TBuf<9> max; utc.FormatL(min, KDaylightSavingsMinFormat); utc.FormatL(max, KDaylightSavingsMaxFormat); // Get times representing the first/last possible day of this // year that daylight savings time change could change on TTime timeMin; User::LeaveIfError(timeMin.Set(min)); TTime timeMax; User::LeaveIfError(timeMax.Set(max)); // Find the last sunday in the respective months TTimeIntervalDays addMin(6 - timeMin.DayNoInWeek()); TTimeIntervalDays addMax(6 - timeMax.DayNoInWeek()); timeMin += addMin; timeMax += addMax; // The change happens at 1AM. TTimeIntervalHours hour(1); timeMin += hour; timeMax += hour; // Now we know which day the change occurs on. // Compare it to what the UTC is. TBool result = ((timeMin <= utc) && (timeMax > utc)); // reset the first week day set.SetStartOfWeek(oldStart); set.Set(); return result; }
static struct tm& as_struct_tm (const time_t& t, struct tm& res) { TTime us = UNIX_BASE + TTimeIntervalSeconds(t); TDateTime dt = us.DateTime(); res.tm_sec = dt.Second(); res.tm_min = dt.Minute(); res.tm_hour = dt.Hour(); res.tm_mday = dt.Day() + 1; res.tm_mon = dt.Month(); res.tm_year = dt.Year() - 1900; // EPOC32 counts the year day as Jan 1st == day 1 res.tm_yday = us.DayNoInYear() - 1; // EPOC32 counts the weekdays from 0==Monday to 6==Sunday res.tm_wday = us.DayNoInWeek() + 1; if (res.tm_wday==7) res.tm_wday=0; // Sunday==0 in a struct tm // newlib just sets this field to -1 // tm_isdst doesn't really make sense here since we don't // know the locale for which to interpret this time. res.tm_isdst = -1; return res; }
EXPORT_C TBool StartsAt(const TMsvOffPeakTime& time1, const TTime& time2) { TDateTime dateTime2 = time2.DateTime(); if(time1.Day() != time2.DayNoInWeek()) return EFalse; if(time1.Hour() != dateTime2.Hour()) return EFalse; if(time1.Minute() != dateTime2.Minute()) return EFalse; return ETrue; }
// ---------------------------------------------------------------------------- // MPXDbUtil::DayNoInWeek // ---------------------------------------------------------------------------- // TInt MPXDbUtil::DayNoInWeek() { MPX_FUNC("MPXDbUtil::DayNoInWeek"); TTime now; // in microseconds now.HomeTime(); // Calculate number of days in this week TDay dayNo = now.DayNoInWeek(); TDay firstDay = TLocale().StartOfWeek(); TInt numDay(0); if (firstDay == ESunday) { numDay = dayNo + 1; } else { numDay = dayNo - firstDay; } return numDay; }