Changeset 272127 in webkit
- Timestamp:
- Jan 31, 2021 12:48:01 PM (18 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/complex.yaml (modified) (1 diff)
-
JSTests/complex/date-parse-milliseconds.js (added)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/DateMath.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r272099 r272127 1 2021-01-31 Yusuke Suzuki <ysuzuki@apple.com> 2 3 Date.parse returns non-integral time value 4 https://bugs.webkit.org/show_bug.cgi?id=220687 5 6 Reviewed by Ross Kirsling. 7 8 * complex.yaml: 9 * complex/date-parse-milliseconds.js: Added. 10 (shouldBe): 11 1 12 2021-01-29 Yusuke Suzuki <ysuzuki@apple.com> 2 13 -
trunk/JSTests/complex.yaml
r270861 r272127 41 41 - path: complex/timezone-range-cache-with-dst.js 42 42 cmd: runComplexTest [], [], "TZ=America/Los_Angeles", "--useDollarVM=1" 43 44 - path: complex/date-parse-milliseconds.js 45 cmd: runComplexTest [], [], "TZ=America/Los_Angeles", "--useDollarVM=1" -
trunk/Source/WTF/ChangeLog
r272120 r272127 1 2021-01-31 Yusuke Suzuki <ysuzuki@apple.com> 2 3 Date.parse returns non-integral time value 4 https://bugs.webkit.org/show_bug.cgi?id=220687 5 6 Reviewed by Ross Kirsling. 7 8 Use milliseconds instead of seconds as a base unit to avoid floating point rounding for milliseconds. 9 10 * wtf/DateMath.cpp: 11 (WTF::ymdhmsToMilliseconds): 12 (WTF::parseES5TimePortion): 13 (WTF::parseES5DateFromNullTerminatedCharacters): 14 (WTF::parseDateFromNullTerminatedCharacters): 15 (WTF::ymdhmsToSeconds): Deleted. 16 1 17 2021-01-30 Antti Koivisto <antti@apple.com> 2 18 -
trunk/Source/WTF/wtf/DateMath.cpp
r261661 r272127 372 372 } 373 373 374 static inline double ymdhmsTo Seconds(int year, long mon, long day, long hour, long minute, double second)374 static inline double ymdhmsToMilliseconds(int year, long mon, long day, long hour, long minute, long second, double milliseconds) 375 375 { 376 376 int mday = firstDayOfMonth[isLeapYear(year)][mon - 1]; 377 377 double ydays = daysFrom1970ToYear(year); 378 378 379 double date Seconds = second + minute * secondsPerMinute + hour * secondsPerHour + (mday + day - 1 + ydays) * secondsPerDay;379 double dateMilliseconds = milliseconds + second * msPerSecond + minute * (secondsPerMinute * msPerSecond) + hour * (secondsPerHour * msPerSecond) + (mday + day - 1 + ydays) * (secondsPerDay * msPerSecond); 380 380 381 381 // Clamp to EcmaScript standard (ecma262/#sec-time-values-and-time-range) of 382 382 // +/- 100,000,000 days from 01 January, 1970. 383 if (date Seconds < -8640000000000.0 || dateSeconds > 8640000000000.0)384 return std::numeric_limits<double>::quiet_NaN(); 385 386 return date Seconds;383 if (dateMilliseconds < -8640000000000000.0 || dateMilliseconds > 8640000000000000.0) 384 return std::numeric_limits<double>::quiet_NaN(); 385 386 return dateMilliseconds; 387 387 } 388 388 … … 507 507 // Fractional seconds parsing is lenient, allows any number of digits. 508 508 // Returns 0 if a parse error occurs, else returns the end of the parsed portion of the string. 509 static char* parseES5TimePortion(char* currentPosition, long& hours, long& minutes, double&seconds, bool& isLocalTime, long& timeZoneSeconds)509 static char* parseES5TimePortion(char* currentPosition, long& hours, long& minutes, long& seconds, double& milliseconds, bool& isLocalTime, long& timeZoneSeconds) 510 510 { 511 511 isLocalTime = false; … … 532 532 ++currentPosition; 533 533 534 long intSeconds;535 534 if (!isASCIIDigit(*currentPosition)) 536 535 return nullptr; 537 if (!parseLong(currentPosition, &postParsePosition, 10, & intSeconds))536 if (!parseLong(currentPosition, &postParsePosition, 10, &seconds)) 538 537 return nullptr; 539 538 if ((postParsePosition - currentPosition) != 2) 540 539 return nullptr; 541 seconds = intSeconds;542 540 if (*postParsePosition == '.') { 543 541 currentPosition = postParsePosition + 1; … … 555 553 556 554 long numFracDigits = postParsePosition - currentPosition; 557 seconds += fracSeconds * pow(10.0, static_cast<double>(-numFracDigits));555 milliseconds = fracSeconds * pow(10.0, static_cast<double>(-numFracDigits + 3)); 558 556 } 559 557 currentPosition = postParsePosition; … … 638 636 long hours = 0; 639 637 long minutes = 0; 640 double seconds = 0; 638 long seconds = 0; 639 double milliseconds = 0; 641 640 long timeZoneSeconds = 0; 642 641 … … 649 648 if (*currentPosition == 'T') { 650 649 // Parse the time HH:mm[:ss[.sss]][Z|(+|-)(00:00|0000|00)] 651 currentPosition = parseES5TimePortion(currentPosition + 1, hours, minutes, seconds, isLocalTime, timeZoneSeconds);650 currentPosition = parseES5TimePortion(currentPosition + 1, hours, minutes, seconds, milliseconds, isLocalTime, timeZoneSeconds); 652 651 if (!currentPosition) 653 652 return std::numeric_limits<double>::quiet_NaN(); … … 673 672 if (seconds < 0 || seconds >= 61) 674 673 return std::numeric_limits<double>::quiet_NaN(); 675 if (seconds >60) {674 if (seconds == 60) { 676 675 // Discard leap seconds by clamping to the end of a minute. 677 seconds = 60;676 milliseconds = 0; 678 677 } 679 678 680 double dateSeconds = ymdhmsToSeconds(year, month, day, hours, minutes, seconds) - timeZoneSeconds; 681 return dateSeconds * msPerSecond; 679 return ymdhmsToMilliseconds(year, month, day, hours, minutes, seconds, milliseconds) - (timeZoneSeconds * msPerSecond); 682 680 } 683 681 … … 984 982 ASSERT(year); 985 983 986 double dateSeconds = ymdhmsToSeconds(year.value(), month + 1, day, hour, minute, second) - offset * secondsPerMinute; 987 return dateSeconds * msPerSecond; 984 return ymdhmsToMilliseconds(year.value(), month + 1, day, hour, minute, second, 0) - offset * (secondsPerMinute * msPerSecond); 988 985 } 989 986
Note: See TracChangeset
for help on using the changeset viewer.