[webkit-changes] [WebKit/WebKit] d4d2f9: Implement Temporal.PlainDate[Time].{equals, add, s...

Ross Kirsling noreply at github.com
Sun Sep 11 16:46:47 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d4d2f95f408151897208a3c8a48b09f387335984
      https://github.com/WebKit/WebKit/commit/d4d2f95f408151897208a3c8a48b09f387335984
  Author: Ross Kirsling <rkirsling at gmail.com>
  Date:   2022-09-11 (Sun, 11 Sep 2022)

  Changed paths:
    M JSTests/stress/temporal-calendar.js
    M JSTests/stress/temporal-plaindate.js
    M JSTests/stress/temporal-plaindatetime.js
    M JSTests/test262/config.yaml
    M Source/JavaScriptCore/runtime/ISO8601.cpp
    M Source/JavaScriptCore/runtime/ISO8601.h
    M Source/JavaScriptCore/runtime/TemporalCalendar.cpp
    M Source/JavaScriptCore/runtime/TemporalCalendar.h
    M Source/JavaScriptCore/runtime/TemporalCalendarPrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalObject.cpp
    M Source/JavaScriptCore/runtime/TemporalObject.h
    M Source/JavaScriptCore/runtime/TemporalPlainDate.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainDatePrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainDateTimePrototype.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainTime.cpp
    M Source/JavaScriptCore/runtime/TemporalPlainTime.h
    M Source/JavaScriptCore/runtime/TemporalPlainTimePrototype.cpp
    M Source/WTF/wtf/DateMath.h

  Log Message:
  -----------
  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




More information about the webkit-changes mailing list