Skip to content
Permalink
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
rkirsling committed Sep 11, 2022
1 parent 8b34749 commit d4d2f95f408151897208a3c8a48b09f387335984
Show file tree
Hide file tree
Showing 18 changed files with 494 additions and 55 deletions.
@@ -97,6 +97,10 @@ shouldThrow(() => {
shouldBe(JSON.parse(string, reviver).userCalendar instanceof Temporal.Calendar, true);
}

shouldBe(isoCalendar.toString(), isoCalendar.toJSON());
shouldThrow(() => { Temporal.Calendar.prototype.toString.call({}); }, TypeError);
shouldThrow(() => { Temporal.Calendar.prototype.toJSON.call({}); }, TypeError);

shouldBe(Temporal.Calendar.prototype.dateFromFields.length, 1);
shouldBe(isoCalendar.dateFromFields({ year: 2007, month: 1, day: 9 }).toString(), '2007-01-09');
shouldBe(isoCalendar.dateFromFields({ year: 2007, monthCode: 'M01', day: 9 }).toString(), '2007-01-09');
@@ -113,3 +117,23 @@ shouldThrow(() => { isoCalendar.dateFromFields({ year: 2007, monthCode: 'M00', d
shouldThrow(() => { isoCalendar.dateFromFields({ year: 2007, month: 1, day: 0 }); }, RangeError);
shouldThrow(() => { isoCalendar.dateFromFields({ year: 2007, month: 1, monthCode: 'M02', day: 9 }); }, RangeError);
shouldThrow(() => { isoCalendar.dateFromFields({ year: 2007, month: 20, day: 40 }, { overflow: 'reject' }); }, RangeError);

shouldBe(Temporal.Calendar.prototype.dateAdd.length, 2);
shouldBe(isoCalendar.dateAdd('2020-02-28', new Temporal.Duration()).toString(), '2020-02-28');
shouldBe(isoCalendar.dateAdd('2020-02-28', { years: 1, months: 1 }).toString(), '2021-03-28');
shouldBe(isoCalendar.dateAdd('2020-02-28', 'P1W1D').toString(), '2020-03-07');
shouldBe(isoCalendar.dateAdd('2020-02-28', { hours: 24 }).toString(), '2020-02-29');
shouldBe(isoCalendar.dateAdd('2020-02-28', { days: 36500000 }).toString(), '+101953-10-07');
shouldBe(isoCalendar.dateAdd('2020-02-28', new Temporal.Duration(-1, -1, 0, -1)).toString(), '2019-01-27');
shouldBe(isoCalendar.dateAdd('2020-01-30', { months: 1 }).toString(), '2020-02-29');
shouldThrow(() => { isoCalendar.dateAdd('2020-01-30', { months: 1 }, { overflow: 'reject' }); }, RangeError);
shouldThrow(() => { isoCalendar.dateAdd('2020-02-28', { years: 300000 }); }, RangeError);

shouldBe(isoCalendar.dateAdd('2020-02-28', { years: -1, months: -1 }).toString(), '2019-01-28');
shouldBe(isoCalendar.dateAdd('2020-02-28', '-P1W1D').toString(), '2020-02-20');
shouldBe(isoCalendar.dateAdd('2020-02-28', { hours: -24 }).toString(), '2020-02-27');
shouldBe(isoCalendar.dateAdd('2020-02-28', { days: -36500000 }).toString(), '-097914-07-21');
shouldBe(isoCalendar.dateAdd('2020-02-28', new Temporal.Duration(1, 1, 0, 1)).toString(), '2021-03-29');
shouldBe(isoCalendar.dateAdd('2020-03-30', { months: -1 }).toString(), '2020-02-29');
shouldThrow(() => { isoCalendar.dateAdd('2020-03-30', { months: -1 }, { overflow: 'reject' }); }, RangeError);
shouldThrow(() => { isoCalendar.dateAdd('2020-02-28', { years: -300000 }); }, RangeError);
@@ -344,3 +344,36 @@ shouldThrow(() => { Temporal.PlainDate.from('2007-01-09').valueOf(); }, TypeErro
let time = Temporal.PlainDate.from('2007-01-09');
shouldBe(JSON.stringify(time.getISOFields()), `{"calendar":"iso8601","isoDay":9,"isoMonth":1,"isoYear":2007}`);
}

{
const ones = new Temporal.PlainDate(1,1,1);
shouldBe(ones.equals(new Temporal.PlainDate(1,1,1)), true);
shouldBe(ones.equals(new Temporal.PlainDate(2,1,1)), false);
shouldBe(ones.equals(new Temporal.PlainDate(1,2,1)), false);
shouldBe(ones.equals(new Temporal.PlainDate(1,1,2)), false);
}

shouldBe(Temporal.PlainDateTime.prototype.add.length, 1);
shouldBe(Temporal.PlainDateTime.prototype.subtract.length, 1);
{
const date = Temporal.PlainDate.from('2020-02-28');
shouldBe(date.add(new Temporal.Duration()).toString(), '2020-02-28');
shouldBe(date.add({ years: 1, months: 1 }).toString(), '2021-03-28');
shouldBe(date.add('P1W1D').toString(), '2020-03-07');
shouldBe(date.add({ hours: 24 }).toString(), '2020-02-29');
shouldBe(date.add({ days: 36500000 }).toString(), '+101953-10-07');
shouldBe(date.add(new Temporal.Duration(-1, -1, 0, -1)).toString(), '2019-01-27');
shouldBe(Temporal.PlainDate.from('2020-01-30').add({ months: 1 }).toString(), '2020-02-29');
shouldThrow(() => { Temporal.PlainDate.from('2020-01-30').add({ months: 1 }, { overflow: 'reject' }); }, RangeError);
shouldThrow(() => { date.add({ years: 300000 }); }, RangeError);

shouldBe(date.subtract(new Temporal.Duration()).toString(), '2020-02-28');
shouldBe(date.subtract({ years: 1, months: 1 }).toString(), '2019-01-28');
shouldBe(date.subtract('P1W1D').toString(), '2020-02-20');
shouldBe(date.subtract({ hours: 24 }).toString(), '2020-02-27');
shouldBe(date.subtract({ days: 36500000 }).toString(), '-097914-07-21');
shouldBe(date.subtract(new Temporal.Duration(-1, -1, 0, -1)).toString(), '2021-03-29');
shouldBe(Temporal.PlainDate.from('2020-03-30').subtract({ months: 1 }).toString(), '2020-02-29');
shouldThrow(() => { Temporal.PlainDate.from('2020-03-30').subtract({ months: 1 }, { overflow: 'reject' }); }, RangeError);
shouldThrow(() => { date.subtract({ years: 300000 }); }, RangeError);
}
@@ -239,3 +239,34 @@ shouldBe(pdt.toPlainTime().toString(), '04:05:06.007008009');

shouldBe(Temporal.PlainDateTime.prototype.valueOf.length, 0);
shouldThrow(() => pdt.valueOf(), TypeError);

shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,4,5,6,7,8,9)), true);
shouldBe(pdt.equals(new Temporal.PlainDateTime(2,2,3,4,5,6,7,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,3,3,4,5,6,7,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,4,4,5,6,7,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,5,5,6,7,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,4,6,6,7,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,4,5,7,7,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,4,5,6,8,8,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,4,5,6,7,9,9)), false);
shouldBe(pdt.equals(new Temporal.PlainDateTime(1,2,3,4,5,6,7,8,1)), false);

shouldBe(Temporal.PlainDateTime.prototype.add.length, 1);
shouldBe(pdt.add(new Temporal.Duration()).toString(), '0001-02-03T04:05:06.007008009');
shouldBe(pdt.add(new Temporal.Duration(1,1,1,1,1,1,1,1,1,1)).toString(), '0002-03-11T05:06:07.00800901');
shouldBe(pdt.add('-P1Y1M1DT1H1M1.001001001S').toString(), '0000-01-02T03:04:05.006007008');
shouldBe(pdt.add({ hours: 24 }).toString(), '0001-02-04T04:05:06.007008009');
shouldBe(pdt.add(new Temporal.Duration(0,10,3,7,19,54,53,992,991,991)).toString(), '0002-01-01T00:00:00');
shouldBe(Temporal.PlainDateTime.from('2020-01-30').add({ months: 1 }).toString(), '2020-02-29T00:00:00');
shouldThrow(() => { Temporal.PlainDateTime.from('2020-01-30').add({ months: 1 }, { overflow: 'reject' }); }, RangeError);
shouldThrow(() => { pdt.add({ years: 300000 }); }, RangeError);

shouldBe(Temporal.PlainDateTime.prototype.subtract.length, 1);
shouldBe(pdt.subtract(new Temporal.Duration()).toString(), '0001-02-03T04:05:06.007008009');
shouldBe(pdt.subtract(new Temporal.Duration(1,1,0,1,1,1,1,1,1,1)).toString(), '0000-01-02T03:04:05.006007008');
shouldBe(pdt.subtract('-P1Y1M1W1DT1H1M1.001001001S').toString(), '0002-03-11T05:06:07.00800901');
shouldBe(pdt.subtract({ hours: 24 }).toString(), '0001-02-02T04:05:06.007008009');
shouldBe(pdt.subtract(new Temporal.Duration(0,1,5,3,4,5,6,7,8,10)).toString(), '0000-11-25T23:59:59.999999999');
shouldBe(Temporal.PlainDateTime.from('2020-03-30').subtract({ months: 1 }).toString(), '2020-02-29T00:00:00');
shouldThrow(() => { Temporal.PlainDateTime.from('2020-03-30').subtract({ months: 1 }, { overflow: 'reject' }); }, RangeError);
shouldThrow(() => { pdt.subtract({ years: 300000 }); }, RangeError);
@@ -36,21 +36,15 @@ skip:
- test/built-ins/Temporal/Now/plainTimeISO
- test/built-ins/Temporal/Now/zonedDateTime
- test/built-ins/Temporal/Now/zonedDateTimeISO
- test/built-ins/Temporal/PlainDate/prototype/add
- test/built-ins/Temporal/PlainDate/prototype/equals
- test/built-ins/Temporal/PlainDate/prototype/since
- test/built-ins/Temporal/PlainDate/prototype/subtract
- test/built-ins/Temporal/PlainDate/prototype/toPlainMonthDay
- test/built-ins/Temporal/PlainDate/prototype/toPlainYearMonth
- test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime
- test/built-ins/Temporal/PlainDate/prototype/until
- test/built-ins/Temporal/PlainDate/prototype/with
- test/built-ins/Temporal/PlainDate/prototype/withCalendar
- test/built-ins/Temporal/PlainDateTime/prototype/add
- test/built-ins/Temporal/PlainDateTime/prototype/equals
- test/built-ins/Temporal/PlainDateTime/prototype/round
- test/built-ins/Temporal/PlainDateTime/prototype/since
- test/built-ins/Temporal/PlainDateTime/prototype/subtract
- test/built-ins/Temporal/PlainDateTime/prototype/toPlainMonthDay
- test/built-ins/Temporal/PlainDateTime/prototype/toPlainYearMonth
- test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime
@@ -368,6 +362,7 @@ skip:
# Depends on Calendar support
- test/built-ins/Temporal/PlainDate/basic.js
- test/built-ins/Temporal/PlainDate/calendar-number.js
- test/built-ins/Temporal/PlainDate/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDate/calendar-wrong-type.js
- test/built-ins/Temporal/PlainDate/compare/argument-calendar-datefromfields-called-with-null-prototype-fields.js
- test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-leap-second.js
@@ -388,16 +383,34 @@ skip:
- test/built-ins/Temporal/PlainDate/from/calendar-fields-custom.js
- test/built-ins/Temporal/PlainDate/from/calendar-fields-iterable.js
- test/built-ins/Temporal/PlainDate/from/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDate/prototype/add/balance-smaller-units.js
- test/built-ins/Temporal/PlainDate/prototype/add/calendar-invalid-return.js
- test/built-ins/Temporal/PlainDate/prototype/add/custom.js
- test/built-ins/Temporal/PlainDate/prototype/day/calendar-returns-infinity.js
- test/built-ins/Temporal/PlainDate/prototype/dayOfWeek/custom.js
- test/built-ins/Temporal/PlainDate/prototype/dayOfYear/custom.js
- test/built-ins/Temporal/PlainDate/prototype/daysInMonth/custom.js
- test/built-ins/Temporal/PlainDate/prototype/daysInWeek/custom.js
- test/built-ins/Temporal/PlainDate/prototype/daysInYear/custom.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-calendar-datefromfields-called-with-null-prototype-fields.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-object-valid.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-leap-second.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-invalid.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-string.js
- test/built-ins/Temporal/PlainDate/prototype/equals/calendar-call-different.js
- test/built-ins/Temporal/PlainDate/prototype/equals/calendar-call-same.js
- test/built-ins/Temporal/PlainDate/prototype/equals/calendar-datefromfields-called-with-options-undefined.js
- test/built-ins/Temporal/PlainDate/prototype/equals/calendar-fields-iterable.js
- test/built-ins/Temporal/PlainDate/prototype/equals/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDate/prototype/getISOFields/custom.js
- test/built-ins/Temporal/PlainDate/prototype/inLeapYear/custom.js
- test/built-ins/Temporal/PlainDate/prototype/month/calendar-returns-infinity.js
- test/built-ins/Temporal/PlainDate/prototype/monthsInYear/custom.js
- test/built-ins/Temporal/PlainDate/prototype/subtract/balance-smaller-units.js
- test/built-ins/Temporal/PlainDate/prototype/subtract/calendar-invalid-return.js
- test/built-ins/Temporal/PlainDate/prototype/subtract/custom.js
- test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-object.js
- test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/basic.js
- test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/calendar-temporal-object.js
@@ -414,13 +427,13 @@ skip:
- test/built-ins/Temporal/PlainDateTime/calendar-number.js
- test/built-ins/Temporal/PlainDateTime/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js
- test/built-ins/Temporal/PlainDateTime/constructor-full.js
- test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-leap-second.js
- test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js
- test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js
- test/built-ins/Temporal/PlainDateTime/compare/calendar-datefromfields-called-with-null-prototype-fields.js
- test/built-ins/Temporal/PlainDateTime/compare/calendar-fields-iterable.js
- test/built-ins/Temporal/PlainDateTime/compare/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDateTime/constructor-full.js
- test/built-ins/Temporal/PlainDateTime/from/argument-plaindate.js
- test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-leap-second.js
- test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js
@@ -431,16 +444,25 @@ skip:
- test/built-ins/Temporal/PlainDateTime/from/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDateTime/from/overflow-invalid-string.js
- test/built-ins/Temporal/PlainDateTime/from/overflow-wrong-type.js
- test/built-ins/Temporal/PlainDateTime/prototype/add/calendar-dateadd.js
- test/built-ins/Temporal/PlainDateTime/prototype/day/calendar-returns-infinity.js
- test/built-ins/Temporal/PlainDateTime/prototype/dayOfWeek/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/dayOfYear/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/daysInMonth/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/daysInWeek/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/daysInYear/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-leap-second.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-checked.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-datefromfields-called-with-null-prototype-fields.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-fields-iterable.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDateTime/prototype/getISOFields/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/inLeapYear/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/month/calendar-returns-infinity.js
- test/built-ins/Temporal/PlainDateTime/prototype/monthsInYear/custom.js
- test/built-ins/Temporal/PlainDateTime/prototype/subtract/calendar-dateadd.js
- test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-always.js
- test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-auto.js
- test/built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string.js
@@ -472,7 +494,6 @@ skip:
- test/built-ins/Temporal/Duration/prototype/total/unit-plurals-accepted-string.js
- test/built-ins/Temporal/Duration/prototype/total/unit-plurals-accepted.js
- test/built-ins/Temporal/Instant/prototype/toString/smallestunit-plurals-accepted.js
- test/built-ins/Temporal/PlainDate/calendar-temporal-object.js
- test/built-ins/Temporal/PlainDateTime/prototype/toString/smallestunit-plurals-accepted.js
- test/built-ins/Temporal/PlainTime/prototype/round/smallestunit-plurals-accepted.js
- test/built-ins/Temporal/PlainTime/prototype/toString/smallestunit-plurals-accepted.js
@@ -551,6 +572,12 @@ skip:
- test/built-ins/Temporal/PlainDate/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js
- test/built-ins/Temporal/PlainDate/from/argument-zoneddatetime.js
- test/built-ins/Temporal/PlainDate/from/overflow-invalid-string.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-zoneddatetime-convert.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-zoneddatetime-slots.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js
- test/built-ins/Temporal/PlainDate/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js
- test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-zoneddatetime-balance-negative-time-units.js
- test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-zoneddatetime-negative-epochnanoseconds.js
- test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js
@@ -568,6 +595,12 @@ skip:
- test/built-ins/Temporal/PlainDateTime/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js
- test/built-ins/Temporal/PlainDateTime/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js
- test/built-ins/Temporal/PlainDateTime/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-balance-negative-time-units.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-negative-epochnanoseconds.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js
- test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js
- test/built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-negative-epochnanoseconds.js
- test/built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js
- test/built-ins/Temporal/PlainTime/compare/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js
@@ -45,6 +45,9 @@ static constexpr int64_t nsPerSecond = 1000LL * 1000 * 1000;
static constexpr int64_t nsPerMillisecond = 1000LL * 1000;
static constexpr int64_t nsPerMicrosecond = 1000LL;

static constexpr int32_t maxYear = 275760;
static constexpr int32_t minYear = -271821;

std::optional<TimeZoneID> parseTimeZoneName(StringView string)
{
const auto& timeZones = intlAvailableTimeZones();
@@ -1166,8 +1169,7 @@ uint8_t weekOfYear(PlainDate plainDate)

if (week == 53) {
// Check whether this is in next year's week 1.
int32_t daysInYear = isLeapYear(plainDate.year()) ? 366 : 365;
if ((daysInYear - dayOfYear) < (4 - dayOfWeek))
if ((daysInYear(plainDate.year()) - dayOfYear) < (4 - dayOfWeek))
return 1;
}

@@ -1460,5 +1462,11 @@ bool isDateTimeWithinLimits(int32_t year, uint8_t month, uint8_t day, unsigned h
return true;
}

// More effective for our purposes than isInBounds<int32_t>.
bool isYearWithinLimits(double year)
{
return year >= minYear && year <= maxYear;
}

} // namespace ISO8601
} // namespace JSC

0 comments on commit d4d2f95

Please sign in to comment.