Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Implement Temporal.PlainDate[Time].{equals, add, subtract}
https://bugs.webkit.org/show_bug.cgi?id=245021 Reviewed by Yusuke Suzuki. This patch implements three more methods -- equals, add, and subtract -- for the PlainDate and PlainDateTime classes. This is all fairly straightforward aside from `balanceISODate`: When adding / subtracting a significant number of days, we need to recalculate year and month based on total days away from Unix epoch. (We could, of course, add years in a loop, but that would penalize large additions / subtractions.) This function is based on existing logic in DateMath with two key differences. 1. We don't need to worry about units smaller than days (vs. msToYear). 2. We can calculate month and day together in a single loop (vs. dayInMonthFromDayInYear and monthFromDayInYear, which are wastefully separated for some reason. This should probably be fixed for Date in a separate patch.) * JSTests/stress/temporal-calendar.js: Add tests. * JSTests/stress/temporal-plaindate.js: Add tests. * JSTests/stress/temporal-plaindatetime.js: Add tests. * JSTests/test262/config.yaml: Update known failures (due to calendar support). * Source/JavaScriptCore/runtime/ISO8601.cpp: (JSC::ISO8601::weekOfYear): Use existing WTF helper. (JSC::ISO8601::isYearWithinLimits): Added. * Source/JavaScriptCore/runtime/ISO8601.h: * Source/JavaScriptCore/runtime/TemporalCalendar.cpp: (JSC::balanceISODate): Added. (JSC::TemporalCalendar::isoDateAdd): Added. (JSC::TemporalCalendar::equals): Added. * Source/JavaScriptCore/runtime/TemporalCalendar.h: * Source/JavaScriptCore/runtime/TemporalCalendarPrototype.cpp: * Source/JavaScriptCore/runtime/TemporalObject.cpp: (JSC::nonNegativeModulo): Moved from TemporalPlainTime. * Source/JavaScriptCore/runtime/TemporalObject.h: * Source/JavaScriptCore/runtime/TemporalPlainDate.cpp: (JSC::TemporalPlainDate::toPlainDate): * Source/JavaScriptCore/runtime/TemporalPlainDatePrototype.cpp: * Source/JavaScriptCore/runtime/TemporalPlainDateTimePrototype.cpp: * Source/JavaScriptCore/runtime/TemporalPlainTime.cpp: (JSC::TemporalPlainTime::addTime): Made public static. (JSC::nonNegativeModulo): Moved to TemporalObject. (JSC::TemporalPlainTime::add const): Refactored away. (JSC::TemporalPlainTime::subtract const): Refactored away. * Source/JavaScriptCore/runtime/TemporalPlainTime.h: * Source/JavaScriptCore/runtime/TemporalPlainTimePrototype.cpp: * Source/WTF/wtf/DateMath.h: Expose two functions that were missing from the list. Canonical link: https://commits.webkit.org/254366@main
- Loading branch information
Showing
18 changed files
with
494 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.