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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 return 365.0 * (year - 1970) + yearsToAddBy4Rule - yearsToExcludeBy100Rule + | 153 return 365.0 * (year - 1970) + yearsToAddBy4Rule - yearsToExcludeBy100Rule + |
154 yearsToAddBy400Rule; | 154 yearsToAddBy400Rule; |
155 } | 155 } |
156 | 156 |
157 static double msToDays(double ms) { | 157 static double msToDays(double ms) { |
158 return floor(ms / msPerDay); | 158 return floor(ms / msPerDay); |
159 } | 159 } |
160 | 160 |
161 static void appendTwoDigitNumber(StringBuilder& builder, int number) { | 161 static void appendTwoDigitNumber(StringBuilder& builder, int number) { |
162 ASSERT(number >= 0 && number < 100); | 162 DCHECK_GE(number, 0); |
| 163 DCHECK_LT(number, 100); |
163 if (number <= 9) | 164 if (number <= 9) |
164 builder.append('0'); | 165 builder.append('0'); |
165 builder.appendNumber(number); | 166 builder.appendNumber(number); |
166 } | 167 } |
167 | 168 |
168 int msToYear(double ms) { | 169 int msToYear(double ms) { |
169 DCHECK(std::isfinite(ms)); | 170 DCHECK(std::isfinite(ms)); |
170 DCHECK_GE(ms, kMinimumECMADateInMs); | 171 DCHECK_GE(ms, kMinimumECMADateInMs); |
171 DCHECK_LE(ms, kMaximumECMADateInMs); | 172 DCHECK_LE(ms, kMaximumECMADateInMs); |
172 int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970); | 173 int approxYear = static_cast<int>(floor(ms / (msPerDay * 365.2425)) + 1970); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 double dateToDaysFrom1970(int year, int month, int day) { | 268 double dateToDaysFrom1970(int year, int month, int day) { |
268 year += month / 12; | 269 year += month / 12; |
269 | 270 |
270 month %= 12; | 271 month %= 12; |
271 if (month < 0) { | 272 if (month < 0) { |
272 month += 12; | 273 month += 12; |
273 --year; | 274 --year; |
274 } | 275 } |
275 | 276 |
276 double yearday = floor(daysFrom1970ToYear(year)); | 277 double yearday = floor(daysFrom1970ToYear(year)); |
277 ASSERT((year >= 1970 && yearday >= 0) || (year < 1970 && yearday < 0)); | 278 DCHECK((year >= 1970 && yearday >= 0) || (year < 1970 && yearday < 0)); |
278 return yearday + dayInYear(year, month, day); | 279 return yearday + dayInYear(year, month, day); |
279 } | 280 } |
280 | 281 |
281 // There is a hard limit at 2038 that we currently do not have a workaround | 282 // There is a hard limit at 2038 that we currently do not have a workaround |
282 // for (rdar://problem/5052975). | 283 // for (rdar://problem/5052975). |
283 static inline int maximumYearForDST() { | 284 static inline int maximumYearForDST() { |
284 return 2037; | 285 return 2037; |
285 } | 286 } |
286 | 287 |
287 static inline double jsCurrentTime() { | 288 static inline double jsCurrentTime() { |
(...skipping 29 matching lines...) Expand all Loading... |
317 difference = minYear - year; | 318 difference = minYear - year; |
318 else if (year < minYear) | 319 else if (year < minYear) |
319 difference = maxYear - year; | 320 difference = maxYear - year; |
320 else | 321 else |
321 return year; | 322 return year; |
322 | 323 |
323 int quotient = difference / 28; | 324 int quotient = difference / 28; |
324 int product = (quotient)*28; | 325 int product = (quotient)*28; |
325 | 326 |
326 year += product; | 327 year += product; |
327 ASSERT((year >= minYear && year <= maxYear) || | 328 DCHECK((year >= minYear && year <= maxYear) || |
328 (product - year == | 329 (product - year == |
329 static_cast<int>(std::numeric_limits<double>::quiet_NaN()))); | 330 static_cast<int>(std::numeric_limits<double>::quiet_NaN()))); |
330 return year; | 331 return year; |
331 } | 332 } |
332 | 333 |
333 static double calculateUTCOffset() { | 334 static double calculateUTCOffset() { |
334 #if OS(WIN) | 335 #if OS(WIN) |
335 TIME_ZONE_INFORMATION timeZoneInformation; | 336 TIME_ZONE_INFORMATION timeZoneInformation; |
336 GetTimeZoneInformation(&timeZoneInformation); | 337 GetTimeZoneInformation(&timeZoneInformation); |
337 int32_t bias = timeZoneInformation.Bias + timeZoneInformation.StandardBias; | 338 int32_t bias = timeZoneInformation.Bias + timeZoneInformation.StandardBias; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 int dayInMonth = dayInMonthFromDayInYear(dayInYearLocal, leapYear); | 384 int dayInMonth = dayInMonthFromDayInYear(dayInYearLocal, leapYear); |
384 int month = monthFromDayInYear(dayInYearLocal, leapYear); | 385 int month = monthFromDayInYear(dayInYearLocal, leapYear); |
385 double day = dateToDaysFrom1970(equivalentYear, month, dayInMonth); | 386 double day = dateToDaysFrom1970(equivalentYear, month, dayInMonth); |
386 ms = (day * msPerDay) + msToMilliseconds(ms); | 387 ms = (day * msPerDay) + msToMilliseconds(ms); |
387 } | 388 } |
388 | 389 |
389 return calculateDSTOffsetSimple(ms / msPerSecond, utcOffset); | 390 return calculateDSTOffsetSimple(ms / msPerSecond, utcOffset); |
390 } | 391 } |
391 | 392 |
392 void initializeDates() { | 393 void initializeDates() { |
393 #if ENABLE(ASSERT) | 394 #if DCHECK_IS_ON() |
394 static bool alreadyInitialized; | 395 static bool alreadyInitialized; |
395 ASSERT(!alreadyInitialized); | 396 DCHECK(!alreadyInitialized); |
396 alreadyInitialized = true; | 397 alreadyInitialized = true; |
397 #endif | 398 #endif |
398 | 399 |
399 equivalentYearForDST( | 400 equivalentYearForDST( |
400 2000); // Need to call once to initialize a static used in this function. | 401 2000); // Need to call once to initialize a static used in this function. |
401 } | 402 } |
402 | 403 |
403 static inline double ymdhmsToSeconds(int year, | 404 static inline double ymdhmsToSeconds(int year, |
404 long mon, | 405 long mon, |
405 long day, | 406 long day, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 nesting--; | 439 nesting--; |
439 else if (nesting == 0) | 440 else if (nesting == 0) |
440 break; | 441 break; |
441 } | 442 } |
442 s++; | 443 s++; |
443 } | 444 } |
444 } | 445 } |
445 | 446 |
446 // returns 0-11 (Jan-Dec); -1 on failure | 447 // returns 0-11 (Jan-Dec); -1 on failure |
447 static int findMonth(const char* monthStr) { | 448 static int findMonth(const char* monthStr) { |
448 ASSERT(monthStr); | 449 DCHECK(monthStr); |
449 char needle[4]; | 450 char needle[4]; |
450 for (int i = 0; i < 3; ++i) { | 451 for (int i = 0; i < 3; ++i) { |
451 if (!*monthStr) | 452 if (!*monthStr) |
452 return -1; | 453 return -1; |
453 needle[i] = static_cast<char>(toASCIILower(*monthStr++)); | 454 needle[i] = static_cast<char>(toASCIILower(*monthStr++)); |
454 } | 455 } |
455 needle[3] = '\0'; | 456 needle[3] = '\0'; |
456 const char* haystack = "janfebmaraprmayjunjulaugsepoctnovdec"; | 457 const char* haystack = "janfebmaraprmayjunjulaugsepoctnovdec"; |
457 const char* str = strstr(haystack, needle); | 458 const char* str = strstr(haystack, needle); |
458 if (str) { | 459 if (str) { |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 return stringBuilder.toString(); | 833 return stringBuilder.toString(); |
833 } | 834 } |
834 | 835 |
835 double convertToLocalTime(double ms) { | 836 double convertToLocalTime(double ms) { |
836 double utcOffset = calculateUTCOffset(); | 837 double utcOffset = calculateUTCOffset(); |
837 double dstOffset = calculateDSTOffset(ms, utcOffset); | 838 double dstOffset = calculateDSTOffset(ms, utcOffset); |
838 return (ms + utcOffset + dstOffset); | 839 return (ms + utcOffset + dstOffset); |
839 } | 840 } |
840 | 841 |
841 } // namespace WTF | 842 } // namespace WTF |
OLD | NEW |