/* * Get the DST offset for the time passed in. */ static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset) { if (localTimeSeconds > maxUnixTime) localTimeSeconds = maxUnixTime; else if (localTimeSeconds < 0) // Go ahead a day to make localtime work (does not work with 0) localTimeSeconds += secondsPerDay; //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset() double offsetTime = (localTimeSeconds * msPerSecond) + utcOffset; // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); // FIXME: time_t has a potential problem in 2038 time_t localTime = static_cast<time_t>(localTimeSeconds); tm localTM; getLocalTime(&localTime, &localTM); double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60); if (diff < 0) diff += secondsPerDay; return (diff * msPerSecond); }
/* * Get the DST offset for the time passed in. */ static double calculateDSTOffset(time_t localTime, double utcOffset) { #if OS(WINCE) UNUSED_PARAM(localTime); UNUSED_PARAM(utcOffset); return 0; #else //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset() double offsetTime = (localTime * msPerSecond) + utcOffset; // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); tm localTM; getLocalTime(&localTime, &localTM); double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60); if (diff < 0) diff += secondsPerDay; return (diff * msPerSecond); #endif }
void msToGregorianDateTime(double ms, bool outputIsUTC, GregorianDateTime& tm) { // input is UTC double dstOff = 0.0; const double utcOff = getUTCOffset(); if (!outputIsUTC) { // convert to local time dstOff = getDSTOffset(ms, utcOff); ms += dstOff + utcOff; } const int year = msToYear(ms); tm.second = msToSeconds(ms); tm.minute = msToMinutes(ms); tm.hour = msToHours(ms); tm.weekDay = msToWeekDay(ms); tm.yearDay = dayInYear(ms, year); tm.monthDay = dayInMonthFromDayInYear(tm.yearDay, isLeapYear(year)); tm.month = monthFromDayInYear(tm.yearDay, isLeapYear(year)); tm.year = year - 1900; tm.isDST = dstOff != 0.0; tm.utcOffset = outputIsUTC ? 0 : static_cast<long>((dstOff + utcOff) / msPerSecond); tm.timeZone = NULL; }
/* * Get the DST offset for the time passed in. */ static double calculateDSTOffset(time_t localTime, double utcOffset) { #if OS(WINDOWS) FILETIME utcFileTime; UnixTimeToFileTime(localTime, &utcFileTime); SYSTEMTIME utcSystemTime, localSystemTime; if (!::FileTimeToSystemTime(&utcFileTime, &utcSystemTime)) return 0; if (!::SystemTimeToTzSpecificLocalTime(nullptr, &utcSystemTime, &localSystemTime)) return 0; double offsetTime = (localTime * msPerSecond) + utcOffset; // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); double diff = ((localSystemTime.wHour - offsetHour) * secondsPerHour) + ((localSystemTime.wMinute - offsetMinute) * 60); return diff * msPerSecond; #else //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset() double offsetTime = (localTime * msPerSecond) + utcOffset; // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); tm localTM; getLocalTime(&localTime, &localTM); double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60); if (diff < 0) diff += secondsPerDay; return (diff * msPerSecond); #endif }
// input is UTC void msToGregorianDateTime(VM& vm, double ms, WTF::TimeType outputTimeType, GregorianDateTime& tm) { LocalTimeOffset localTime; if (outputTimeType == WTF::LocalTime) { localTime = localTimeOffset(vm, ms); ms += localTime.offset; } const int year = msToYear(ms); tm.setSecond(msToSeconds(ms)); tm.setMinute(msToMinutes(ms)); tm.setHour(msToHours(ms)); tm.setWeekDay(msToWeekDay(ms)); tm.setYearDay(dayInYear(ms, year)); tm.setMonthDay(dayInMonthFromDayInYear(tm.yearDay(), isLeapYear(year))); tm.setMonth(monthFromDayInYear(tm.yearDay(), isLeapYear(year))); tm.setYear(year); tm.setIsDST(localTime.isDST); tm.setUtcOffset(localTime.offset / WTF::msPerSecond); }
// input is UTC void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, GregorianDateTime& tm) { LocalTimeOffset localTime(false, 0); if (!outputIsUTC) { localTime = localTimeOffset(exec, ms); ms += localTime.offset; } const int year = msToYear(ms); tm.second = msToSeconds(ms); tm.minute = msToMinutes(ms); tm.hour = msToHours(ms); tm.weekDay = msToWeekDay(ms); tm.yearDay = dayInYear(ms, year); tm.monthDay = dayInMonthFromDayInYear(tm.yearDay, isLeapYear(year)); tm.month = monthFromDayInYear(tm.yearDay, isLeapYear(year)); tm.year = year - 1900; tm.isDST = localTime.isDST; tm.utcOffset = localTime.offset / WTF::msPerSecond; tm.timeZone = NULL; }
// input is UTC void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, GregorianDateTime& tm) { double dstOff = 0.0; double utcOff = 0.0; if (!outputIsUTC) { utcOff = getUTCOffset(exec); dstOff = getDSTOffset(exec, ms, utcOff); ms += dstOff + utcOff; } const int year = msToYear(ms); tm.setSecond(msToSeconds(ms)); tm.setMinute(msToMinutes(ms)); tm.setHour(msToHours(ms)); tm.setWeekDay(msToWeekDay(ms)); tm.setYearDay(dayInYear(ms, year)); tm.setMonthDay(dayInMonthFromDayInYear(tm.yearDay(), isLeapYear(year))); tm.setMonth(monthFromDayInYear(tm.yearDay(), isLeapYear(year))); tm.setYear(year); tm.setIsDST(dstOff != 0.0); tm.setUtcOffset(static_cast<long>((dstOff + utcOff) / WTF::msPerSecond)); }
// input is UTC void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, GregorianDateTime& tm) { double dstOff = 0.0; double utcOff = 0.0; if (!outputIsUTC) { utcOff = getUTCOffset(exec); dstOff = getDSTOffset(exec, ms, utcOff); ms += dstOff + utcOff; } const int year = msToYear(ms); tm.second = msToSeconds(ms); tm.minute = msToMinutes(ms); tm.hour = msToHours(ms); tm.weekDay = msToWeekDay(ms); tm.yearDay = dayInYear(ms, year); tm.monthDay = dayInMonthFromDayInYear(tm.yearDay, isLeapYear(year)); tm.month = monthFromDayInYear(tm.yearDay, isLeapYear(year)); tm.year = year - 1900; tm.isDST = dstOff != 0.0; tm.utcOffset = static_cast<long>((dstOff + utcOff) / WTF::msPerSecond); tm.timeZone = NULL; }
void msToGregorianDateTime(double ms, bool outputIsUTC, GregorianDateTime& tm) { // input is UTC double dstOff = 0.0; if (!outputIsUTC) { // convert to local time dstOff = getDSTOffset(ms); ms += dstOff + getUTCOffset(); } tm.second = msToSeconds(ms); tm.minute = msToMinutes(ms); tm.hour = msToHours(ms); tm.weekDay = msToWeekDay(ms); tm.monthDay = msToDayInMonth(ms); tm.yearDay = dayInYear(ms, msToYear(ms)); tm.month = msToMonth(ms); tm.year = msToYear(ms) - 1900; tm.isDST = dstOff != 0.0; tm.utcOffset = static_cast<long>((dstOff + getUTCOffset()) / msPerSecond); tm.timeZone = NULL; }
/* * Get the DST offset for the time passed in. Takes * seconds (not milliseconds) and cannot handle dates before 1970 * on some OS' */ static double getDSTOffsetSimple(double localTimeSeconds) { if (localTimeSeconds > maxUnixTime) localTimeSeconds = maxUnixTime; else if(localTimeSeconds < 0) // Go ahead a day to make localtime work (does not work with 0) localTimeSeconds += secondsPerDay; //input is UTC so we have to shift back to local time to determine DST thus the + getUTCOffset() double offsetTime = (localTimeSeconds * msPerSecond) + getUTCOffset(); // Offset from UTC but doesn't include DST obviously int offsetHour = msToHours(offsetTime); int offsetMinute = msToMinutes(offsetTime); // FIXME: time_t has a potential problem in 2038 time_t localTime = static_cast<time_t>(localTimeSeconds); tm localTM; #if PLATFORM(WIN32) #if COMPILER(GCC) || PLATFORM(WINCE) localTM = *localtime(&localTime); #elif COMPILER(MSVC) localtime_s(&localTM, &localTime); #else #error no implements!! #endif #else localtime_r(&localTime, &localTM); #endif double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.tm_min - offsetMinute) * 60); if(diff < 0) diff += secondsPerDay; return (diff * msPerSecond); }
static SoupDate* msToSoupDate(double ms) { int year = msToYear(ms); int dayOfYear = dayInYear(ms, year); bool leapYear = isLeapYear(year); return soup_date_new(year, monthFromDayInYear(dayOfYear, leapYear), dayInMonthFromDayInYear(dayOfYear, leapYear), msToHours(ms), msToMinutes(ms), static_cast<int>(ms / 1000) % 60); }