Chromium Code Reviews| Index: Source/wtf/DateMath.cpp |
| diff --git a/Source/wtf/DateMath.cpp b/Source/wtf/DateMath.cpp |
| index 1c901b712d3aee23be9ea78c6c68e416efcab2d2..990e0ca26c79f405067e4172f3c85dadb12f9ca8 100644 |
| --- a/Source/wtf/DateMath.cpp |
| +++ b/Source/wtf/DateMath.cpp |
| @@ -195,22 +195,6 @@ static inline double msToMilliseconds(double ms) |
| return result; |
| } |
| -static int msToMinutes(double ms) |
| -{ |
| - double result = fmod(floor(ms / msPerMinute), minutesPerHour); |
| - if (result < 0) |
| - result += minutesPerHour; |
| - return static_cast<int>(result); |
| -} |
| - |
| -static int msToHours(double ms) |
| -{ |
| - double result = fmod(floor(ms/msPerHour), hoursPerDay); |
| - if (result < 0) |
| - result += hoursPerDay; |
| - return static_cast<int>(result); |
| -} |
| - |
| int monthFromDayInYear(int dayInYear, bool leapYear) |
| { |
| const int d = dayInYear; |
| @@ -358,7 +342,7 @@ static int equivalentYearForDST(int year) |
| return year; |
| } |
| -int32_t calculateUTCOffset() |
| +static double calculateUTCOffset() |
| { |
| #if OS(WIN) |
| TIME_ZONE_INFORMATION timeZoneInformation; |
| @@ -370,32 +354,8 @@ int32_t calculateUTCOffset() |
| tm localt; |
| getLocalTime(&localTime, &localt); |
| - // Get the difference between this time zone and UTC on the 1st of January of this year. |
| - localt.tm_sec = 0; |
| - localt.tm_min = 0; |
| - localt.tm_hour = 0; |
| - localt.tm_mday = 1; |
| - localt.tm_mon = 0; |
| - // Not setting localt.tm_year! |
| - localt.tm_wday = 0; |
| - localt.tm_yday = 0; |
| - localt.tm_isdst = 0; |
| -#if HAVE(TM_GMTOFF) |
| - localt.tm_gmtoff = 0; |
| -#endif |
| -#if HAVE(TM_ZONE) |
| - localt.tm_zone = 0; |
| -#endif |
| - |
| -#if HAVE(TIMEGM) |
| - time_t utcOffset = timegm(&localt) - mktime(&localt); |
| -#else |
| - // Using a canned date of 01/01/2009 on platforms with weaker date-handling foo. |
| - localt.tm_year = 109; |
| - time_t utcOffset = 1230768000 - mktime(&localt); |
| -#endif |
| - |
| - return static_cast<int32_t>(utcOffset * 1000); |
| + // tm_gmtoff includes any daylight savings offset, so subtract it. |
| + return static_cast<double>(localt.tm_gmtoff * msPerSecond - (localt.tm_isdst > 0 ? 3600 * msPerSecond : 0)); |
|
tkent
2014/07/28 00:40:26
nit: 3600 * msPerSend -> msPerHour
kangil_
2014/07/31 00:45:46
Done.
|
| #endif |
| } |
| @@ -409,29 +369,17 @@ static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset |
| 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); |
| + return localTM.tm_isdst > 0 ? secondsPerHour * msPerSecond : 0; |
|
tkent
2014/07/28 00:40:26
nit: secondsPerHour * msPerSecond -> msPerHour
kangil_
2014/07/31 00:45:46
Done.
|
| } |
| // Get the DST offset, given a time in UTC |
| -double calculateDSTOffset(double ms, double utcOffset) |
| +static double calculateDSTOffset(double ms, double utcOffset) |
| { |
| // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will return historically accurate |
| // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript |
| @@ -881,4 +829,11 @@ String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, u |
| return stringBuilder.toString(); |
| } |
| +double convertToLocalTime(double ms) |
| +{ |
| + double utcOffset = calculateUTCOffset(); |
| + double dstOffset = calculateDSTOffset(ms, utcOffset); |
| + return (ms + utcOffset + dstOffset); |
| +} |
| + |
| } // namespace WTF |