| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
| 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2009 Google Inc. All rights reserved. | 4 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 6 * Copyright (C) 2010 &yet, LLC. (nate@andyet.net) | 6 * Copyright (C) 2010 &yet, LLC. (nate@andyet.net) |
| 7 * | 7 * |
| 8 * The Original Code is Mozilla Communicator client code, released | 8 * The Original Code is Mozilla Communicator client code, released |
| 9 * March 31, 1998. | 9 * March 31, 1998. |
| 10 * | 10 * |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // See 15.9.1.14 of ECMA-262 5th edition. | 125 // See 15.9.1.14 of ECMA-262 5th edition. |
| 126 static const double maxECMAScriptTime = 8.64E15; | 126 static const double maxECMAScriptTime = 8.64E15; |
| 127 | 127 |
| 128 // Day of year for the first day of each month, where index 0 is January, and da
y 0 is January 1. | 128 // Day of year for the first day of each month, where index 0 is January, and da
y 0 is January 1. |
| 129 // First for non-leap years, then for leap years. | 129 // First for non-leap years, then for leap years. |
| 130 static const int firstDayOfMonth[2][12] = { | 130 static const int firstDayOfMonth[2][12] = { |
| 131 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, | 131 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, |
| 132 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} | 132 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 #if !OS(WINCE) | |
| 136 static inline void getLocalTime(const time_t* localTime, struct tm* localTM) | 135 static inline void getLocalTime(const time_t* localTime, struct tm* localTM) |
| 137 { | 136 { |
| 138 #if COMPILER(MSVC7_OR_LOWER) || COMPILER(MINGW) | 137 #if COMPILER(MSVC7_OR_LOWER) || COMPILER(MINGW) |
| 139 *localTM = *localtime(localTime); | 138 *localTM = *localtime(localTime); |
| 140 #elif COMPILER(MSVC) | 139 #elif COMPILER(MSVC) |
| 141 localtime_s(localTM, localTime); | 140 localtime_s(localTM, localTime); |
| 142 #else | 141 #else |
| 143 localtime_r(localTime, localTM); | 142 localtime_r(localTime, localTM); |
| 144 #endif | 143 #endif |
| 145 } | 144 } |
| 146 #endif | |
| 147 | 145 |
| 148 bool isLeapYear(int year) | 146 bool isLeapYear(int year) |
| 149 { | 147 { |
| 150 if (year % 4 != 0) | 148 if (year % 4 != 0) |
| 151 return false; | 149 return false; |
| 152 if (year % 400 == 0) | 150 if (year % 400 == 0) |
| 153 return true; | 151 return true; |
| 154 if (year % 100 == 0) | 152 if (year % 100 == 0) |
| 155 return false; | 153 return false; |
| 156 return true; | 154 return true; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 411 |
| 414 return static_cast<int32_t>(utcOffset * 1000); | 412 return static_cast<int32_t>(utcOffset * 1000); |
| 415 #endif | 413 #endif |
| 416 } | 414 } |
| 417 | 415 |
| 418 /* | 416 /* |
| 419 * Get the DST offset for the time passed in. | 417 * Get the DST offset for the time passed in. |
| 420 */ | 418 */ |
| 421 static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset
) | 419 static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset
) |
| 422 { | 420 { |
| 423 #if OS(WINCE) | |
| 424 UNUSED_PARAM(localTimeSeconds); | |
| 425 UNUSED_PARAM(utcOffset); | |
| 426 return 0; | |
| 427 #else | |
| 428 if (localTimeSeconds > maxUnixTime) | 421 if (localTimeSeconds > maxUnixTime) |
| 429 localTimeSeconds = maxUnixTime; | 422 localTimeSeconds = maxUnixTime; |
| 430 else if (localTimeSeconds < 0) // Go ahead a day to make localtime work (doe
s not work with 0) | 423 else if (localTimeSeconds < 0) // Go ahead a day to make localtime work (doe
s not work with 0) |
| 431 localTimeSeconds += secondsPerDay; | 424 localTimeSeconds += secondsPerDay; |
| 432 | 425 |
| 433 //input is UTC so we have to shift back to local time to determine DST thus
the + getUTCOffset() | 426 //input is UTC so we have to shift back to local time to determine DST thus
the + getUTCOffset() |
| 434 double offsetTime = (localTimeSeconds * msPerSecond) + utcOffset; | 427 double offsetTime = (localTimeSeconds * msPerSecond) + utcOffset; |
| 435 | 428 |
| 436 // Offset from UTC but doesn't include DST obviously | 429 // Offset from UTC but doesn't include DST obviously |
| 437 int offsetHour = msToHours(offsetTime); | 430 int offsetHour = msToHours(offsetTime); |
| 438 int offsetMinute = msToMinutes(offsetTime); | 431 int offsetMinute = msToMinutes(offsetTime); |
| 439 | 432 |
| 440 // FIXME: time_t has a potential problem in 2038 | 433 // FIXME: time_t has a potential problem in 2038 |
| 441 time_t localTime = static_cast<time_t>(localTimeSeconds); | 434 time_t localTime = static_cast<time_t>(localTimeSeconds); |
| 442 | 435 |
| 443 tm localTM; | 436 tm localTM; |
| 444 getLocalTime(&localTime, &localTM); | 437 getLocalTime(&localTime, &localTM); |
| 445 | 438 |
| 446 double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.
tm_min - offsetMinute) * 60); | 439 double diff = ((localTM.tm_hour - offsetHour) * secondsPerHour) + ((localTM.
tm_min - offsetMinute) * 60); |
| 447 | 440 |
| 448 if (diff < 0) | 441 if (diff < 0) |
| 449 diff += secondsPerDay; | 442 diff += secondsPerDay; |
| 450 | 443 |
| 451 return (diff * msPerSecond); | 444 return (diff * msPerSecond); |
| 452 #endif | |
| 453 } | 445 } |
| 454 | 446 |
| 455 // Get the DST offset, given a time in UTC | 447 // Get the DST offset, given a time in UTC |
| 456 double calculateDSTOffset(double ms, double utcOffset) | 448 double calculateDSTOffset(double ms, double utcOffset) |
| 457 { | 449 { |
| 458 // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will re
turn historically accurate | 450 // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will re
turn historically accurate |
| 459 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) how
ever the JavaScript | 451 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) how
ever the JavaScript |
| 460 // standard explicitly dictates that historical information should not be co
nsidered when | 452 // standard explicitly dictates that historical information should not be co
nsidered when |
| 461 // determining DST. For this reason we shift away from years that localtime
can handle but would | 453 // determining DST. For this reason we shift away from years that localtime
can handle but would |
| 462 // return historically accurate information. | 454 // return historically accurate information. |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 1093 |
| 1102 stringBuilder.append(utcOffset > 0 ? '+' : '-'); | 1094 stringBuilder.append(utcOffset > 0 ? '+' : '-'); |
| 1103 int absoluteUTCOffset = abs(utcOffset); | 1095 int absoluteUTCOffset = abs(utcOffset); |
| 1104 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60)); | 1096 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60)); |
| 1105 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60)); | 1097 stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60)); |
| 1106 | 1098 |
| 1107 return stringBuilder.toString(); | 1099 return stringBuilder.toString(); |
| 1108 } | 1100 } |
| 1109 | 1101 |
| 1110 } // namespace WTF | 1102 } // namespace WTF |
| OLD | NEW |