Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,15 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar
// 1. If NewTarget is undefined, then
// a. Throw a TypeError exception.
assertThrows(() => Temporal.Calendar("iso8601"), TypeError);
assertThrows(() => new Temporal.Calendar(), RangeError);
assertEquals("iso8601", (new Temporal.Calendar("IsO8601")).id)
assertEquals("iso8601", (new Temporal.Calendar("iso8601")).id)

View File

@ -0,0 +1,95 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateadd
let cal = new Temporal.Calendar("iso8601");
let p1y = new Temporal.Duration(1);
let p4y = new Temporal.Duration(4);
let p5m = new Temporal.Duration(0, 5);
let p1y2m = new Temporal.Duration(1,2);
let p1y4d = new Temporal.Duration(1,0,0,4);
let p1y2m4d = new Temporal.Duration(1,2,0,4);
let p10d = new Temporal.Duration(0,0,0,10);
let p1w = new Temporal.Duration(0,0,1);
let p6w = new Temporal.Duration(0,0,6);
let p2w3d = new Temporal.Duration(0,0,2,3);
let p1y2w = new Temporal.Duration(1,0,2);
let p2m3w = new Temporal.Duration(0,2,3);
assertEquals("2021-02-28", cal.dateAdd("2020-02-29", p1y).toJSON());
assertEquals("2024-02-29", cal.dateAdd("2020-02-29", p4y).toJSON());
assertEquals("2022-07-16", cal.dateAdd("2021-07-16", p1y).toJSON());
assertEquals("2021-12-16", cal.dateAdd("2021-07-16", p5m).toJSON());
assertEquals("2022-01-16", cal.dateAdd("2021-08-16", p5m).toJSON());
assertEquals("2022-03-31", cal.dateAdd("2021-10-31", p5m).toJSON());
assertEquals("2022-02-28", cal.dateAdd("2021-09-30", p5m).toJSON());
assertEquals("2020-02-29", cal.dateAdd("2019-09-30", p5m).toJSON());
assertEquals("2020-03-01", cal.dateAdd("2019-10-01", p5m).toJSON());
assertEquals("2022-09-16", cal.dateAdd("2021-07-16", p1y2m).toJSON());
assertEquals("2023-01-30", cal.dateAdd("2021-11-30", p1y2m).toJSON());
assertEquals("2023-02-28", cal.dateAdd("2021-12-31", p1y2m).toJSON());
assertEquals("2024-02-29", cal.dateAdd("2022-12-31", p1y2m).toJSON());
assertEquals("2022-07-20", cal.dateAdd("2021-07-16", p1y4d).toJSON());
assertEquals("2022-03-03", cal.dateAdd("2021-02-27", p1y4d).toJSON());
assertEquals("2024-03-02", cal.dateAdd("2023-02-27", p1y4d).toJSON());
assertEquals("2023-01-03", cal.dateAdd("2021-12-30", p1y4d).toJSON());
assertEquals("2022-08-03", cal.dateAdd("2021-07-30", p1y4d).toJSON());
assertEquals("2022-07-04", cal.dateAdd("2021-06-30", p1y4d).toJSON());
assertEquals("2022-09-20", cal.dateAdd("2021-07-16", p1y2m4d).toJSON());
assertEquals("2022-05-01", cal.dateAdd("2021-02-27", p1y2m4d).toJSON());
assertEquals("2022-04-30", cal.dateAdd("2021-02-26", p1y2m4d).toJSON());
assertEquals("2024-04-30", cal.dateAdd("2023-02-26", p1y2m4d).toJSON());
assertEquals("2023-03-04", cal.dateAdd("2021-12-30", p1y2m4d).toJSON());
assertEquals("2022-10-04", cal.dateAdd("2021-07-30", p1y2m4d).toJSON());
assertEquals("2022-09-03", cal.dateAdd("2021-06-30", p1y2m4d).toJSON());
assertEquals("2021-07-26", cal.dateAdd("2021-07-16", p10d).toJSON());
assertEquals("2021-08-05", cal.dateAdd("2021-07-26", p10d).toJSON());
assertEquals("2022-01-05", cal.dateAdd("2021-12-26", p10d).toJSON());
assertEquals("2020-03-07", cal.dateAdd("2020-02-26", p10d).toJSON());
assertEquals("2021-03-08", cal.dateAdd("2021-02-26", p10d).toJSON());
assertEquals("2020-02-29", cal.dateAdd("2020-02-19", p10d).toJSON());
assertEquals("2021-03-01", cal.dateAdd("2021-02-19", p10d).toJSON());
assertEquals("2021-02-26", cal.dateAdd("2021-02-19", p1w).toJSON());
assertEquals("2021-03-06", cal.dateAdd("2021-02-27", p1w).toJSON());
assertEquals("2020-03-05", cal.dateAdd("2020-02-27", p1w).toJSON());
assertEquals("2021-12-31", cal.dateAdd("2021-12-24", p1w).toJSON());
assertEquals("2022-01-03", cal.dateAdd("2021-12-27", p1w).toJSON());
assertEquals("2021-02-03", cal.dateAdd("2021-01-27", p1w).toJSON());
assertEquals("2021-07-04", cal.dateAdd("2021-06-27", p1w).toJSON());
assertEquals("2021-08-03", cal.dateAdd("2021-07-27", p1w).toJSON());
assertEquals("2021-04-02", cal.dateAdd("2021-02-19", p6w).toJSON());
assertEquals("2021-04-10", cal.dateAdd("2021-02-27", p6w).toJSON());
assertEquals("2020-04-09", cal.dateAdd("2020-02-27", p6w).toJSON());
assertEquals("2022-02-04", cal.dateAdd("2021-12-24", p6w).toJSON());
assertEquals("2022-02-07", cal.dateAdd("2021-12-27", p6w).toJSON());
assertEquals("2021-03-10", cal.dateAdd("2021-01-27", p6w).toJSON());
assertEquals("2021-08-08", cal.dateAdd("2021-06-27", p6w).toJSON());
assertEquals("2021-09-07", cal.dateAdd("2021-07-27", p6w).toJSON());
assertEquals("2020-03-17", cal.dateAdd("2020-02-29", p2w3d).toJSON());
assertEquals("2020-03-16", cal.dateAdd("2020-02-28", p2w3d).toJSON());
assertEquals("2021-03-17", cal.dateAdd("2021-02-28", p2w3d).toJSON());
assertEquals("2021-01-14", cal.dateAdd("2020-12-28", p2w3d).toJSON());
assertEquals("2021-03-14", cal.dateAdd("2020-02-29", p1y2w).toJSON());
assertEquals("2021-03-14", cal.dateAdd("2020-02-28", p1y2w).toJSON());
assertEquals("2022-03-14", cal.dateAdd("2021-02-28", p1y2w).toJSON());
assertEquals("2022-01-11", cal.dateAdd("2020-12-28", p1y2w).toJSON());
assertEquals("2020-05-20", cal.dateAdd("2020-02-29", p2m3w).toJSON());
assertEquals("2020-05-19", cal.dateAdd("2020-02-28", p2m3w).toJSON());
assertEquals("2021-05-19", cal.dateAdd("2021-02-28", p2m3w).toJSON());
assertEquals("2021-03-21", cal.dateAdd("2020-12-28", p2m3w).toJSON());
assertEquals("2020-03-20", cal.dateAdd("2019-12-28", p2m3w).toJSON());
assertEquals("2020-01-18", cal.dateAdd("2019-10-28", p2m3w).toJSON());
assertEquals("2020-01-21", cal.dateAdd("2019-10-31", p2m3w).toJSON());

View File

@ -0,0 +1,197 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.datefromfields
let cal = new Temporal.Calendar("iso8601")
// Check throw for first arg
assertThrows(() => cal.dateFromFields(),
TypeError);
[undefined, true, false, 123, 456n, Symbol(), "string",
123.456, NaN, null].forEach(
function(fields) {
assertThrows(() => cal.dateFromFields(fields), TypeError);
assertThrows(() => cal.dateFromFields(fields, undefined), TypeError);
assertThrows(() => cal.dateFromFields(fields, {overflow: "constrain"}),
TypeError);
assertThrows(() => cal.dateFromFields(fields, {overflow: "reject"}),
TypeError);
});
assertThrows(() => cal.dateFromFields({month: 1, day: 17}), TypeError);
assertThrows(() => cal.dateFromFields({year: 2021, day: 17}), TypeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 12}), TypeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "m1", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "M1", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "m01", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 12, monthCode: "M11",
day: 17}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "M00", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "M19", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "M99", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, monthCode: "M13", day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: -1, day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: -Infinity, day: 17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 7, day: -17}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 7, day: -Infinity}),
RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 12, day: 0},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 12, day: 32},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 1, day: 32},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 2, day: 29},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 6, day: 31},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 9, day: 31},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 0, day: 5},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields({year: 2021, month: 13, day: 5},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M12", day: 0}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M12", day: 32}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M01", day: 32}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M02", day: 29}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M06", day: 31}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M09", day: 31}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M00", day: 5}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, monthCode: "M13", day: 5}, {overflow: "reject"}),
RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 12, day: 0}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 0, day: 3}), RangeError);
// Check throw for the second arg
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 7, day: 13}, {overflow: "invalid"}),
RangeError);
assertEquals("2021-07-15",
cal.dateFromFields({year: 2021, month: 7, day: 15}).toJSON());
assertEquals("2021-07-03",
cal.dateFromFields({year: 2021, month: 7, day: 3}).toJSON());
assertEquals("2021-12-31",
cal.dateFromFields({year: 2021, month: 12, day: 31}).toJSON());
assertEquals("2021-07-15",
cal.dateFromFields({year: 2021, monthCode: "M07", day: 15}).toJSON());
assertEquals("2021-07-03",
cal.dateFromFields({year: 2021, monthCode: "M07", day: 3}).toJSON());
assertEquals("2021-12-31",
cal.dateFromFields({year: 2021, monthCode: "M12", day: 31}).toJSON());
assertEquals("2021-01-31",
cal.dateFromFields({year: 2021, month: 1, day: 133}).toJSON());
assertEquals("2021-02-28",
cal.dateFromFields({year: 2021, month: 2, day: 133}).toJSON());
assertEquals("2021-03-31",
cal.dateFromFields({year: 2021, month: 3, day: 9033}).toJSON());
assertEquals("2021-04-30",
cal.dateFromFields({year: 2021, month: 4, day: 50}).toJSON());
assertEquals("2021-05-31",
cal.dateFromFields({year: 2021, month: 5, day: 77}).toJSON());
assertEquals("2021-06-30",
cal.dateFromFields({year: 2021, month: 6, day: 33}).toJSON());
assertEquals("2021-07-31",
cal.dateFromFields({year: 2021, month: 7, day: 33}).toJSON());
assertEquals("2021-08-31",
cal.dateFromFields({year: 2021, month: 8, day: 300}).toJSON());
assertEquals("2021-09-30",
cal.dateFromFields({year: 2021, month: 9, day: 400}).toJSON());
assertEquals("2021-10-31",
cal.dateFromFields({year: 2021, month: 10, day: 400}).toJSON());
assertEquals("2021-11-30",
cal.dateFromFields({year: 2021, month: 11, day: 400}).toJSON());
assertEquals("2021-12-31",
cal.dateFromFields({year: 2021, month: 12, day: 500}).toJSON());
assertEquals("2021-12-31",
cal.dateFromFields({year: 2021, month: 13, day: 500}).toJSON());
assertEquals("2021-12-31",
cal.dateFromFields({year: 2021, month: 999999, day: 500}).toJSON());
assertEquals("2021-01-31",
cal.dateFromFields({year: 2021, monthCode: "M01", day: 133}).toJSON());
assertEquals("2021-02-28",
cal.dateFromFields({year: 2021, monthCode: "M02", day: 133}).toJSON());
assertEquals("2021-03-31",
cal.dateFromFields({year: 2021, monthCode: "M03", day: 9033}).toJSON());
assertEquals("2021-04-30",
cal.dateFromFields({year: 2021, monthCode: "M04", day: 50}).toJSON());
assertEquals("2021-05-31",
cal.dateFromFields({year: 2021, monthCode: "M05", day: 77}).toJSON());
assertEquals("2021-06-30",
cal.dateFromFields({year: 2021, monthCode: "M06", day: 33}).toJSON());
assertEquals("2021-07-31",
cal.dateFromFields({year: 2021, monthCode: "M07", day: 33}).toJSON());
assertEquals("2021-08-31",
cal.dateFromFields({year: 2021, monthCode: "M08", day: 300}).toJSON());
assertEquals("2021-09-30",
cal.dateFromFields({year: 2021, monthCode: "M09", day: 400}).toJSON());
assertEquals("2021-10-31",
cal.dateFromFields({year: 2021, monthCode: "M10", day: 400}).toJSON());
assertEquals("2021-11-30",
cal.dateFromFields({year: 2021, monthCode: "M11", day: 400}).toJSON());
assertEquals("2021-12-31",
cal.dateFromFields({year: 2021, monthCode: "M12", day: 500}).toJSON());
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 1, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 2, day: 29}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 3, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 4, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 5, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 6, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 7, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 8, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 9, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 10, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 11, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 12, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.dateFromFields(
{year: 2021, month: 13, day: 5}, {overflow: "reject"}), RangeError);

View File

@ -0,0 +1,224 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dateuntil
let cal = new Temporal.Calendar("iso8601");
// Test throw
[ "hour", "minute", "second", "millisecond", "microsecond", "nanosecond" ]
.forEach(function(largestUnit) {
assertThrows(() => cal.dateUntil("2021-07-16", "2021-07-17",
{largestUnit}), RangeError);
});
assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16").toJSON());
assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17").toJSON());
assertEquals("P32D", cal.dateUntil("2021-07-16", "2021-08-17").toJSON());
assertEquals("P62D", cal.dateUntil("2021-07-16", "2021-09-16").toJSON());
assertEquals("P365D", cal.dateUntil("2021-07-16", "2022-07-16").toJSON());
assertEquals("P3652D", cal.dateUntil("2021-07-16", "2031-07-16").toJSON());
assertEquals("-P1D", cal.dateUntil("2021-07-17", "2021-07-16").toJSON());
assertEquals("-P32D", cal.dateUntil("2021-08-17", "2021-07-16").toJSON());
assertEquals("-P62D", cal.dateUntil("2021-09-16", "2021-07-16").toJSON());
assertEquals("-P365D", cal.dateUntil("2022-07-16", "2021-07-16").toJSON());
assertEquals("-P3652D", cal.dateUntil("2031-07-16", "2021-07-16").toJSON());
["day", "days"].forEach(function(largestUnit) {
let opt = {largestUnit};
assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());
assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());
assertEquals("P32D", cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());
assertEquals("P62D", cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());
assertEquals("P365D",
cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());
assertEquals("P3652D"
,cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());
assertEquals("-P1D",
cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());
assertEquals("-P32D",
cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());
assertEquals("-P62D",
cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());
assertEquals("-P365D",
cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());
assertEquals("-P3652D",
cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());
});
["week", "weeks"].forEach(function(largestUnit) {
let opt = {largestUnit};
assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());
assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());
assertEquals("P1W", cal.dateUntil("2021-07-16", "2021-07-23", opt).toJSON());
assertEquals("P4W4D",
cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());
assertEquals("P4W", cal.dateUntil("2021-07-16", "2021-08-13", opt).toJSON());
assertEquals("P8W6D",
cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());
assertEquals("P52W1D",
cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());
assertEquals("P521W5D"
,cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());
assertEquals("-P1D",
cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());
assertEquals("-P4W4D",
cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());
assertEquals("-P4W",
cal.dateUntil("2021-08-13", "2021-07-16", opt).toJSON());
assertEquals("-P8W6D",
cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());
assertEquals("-P52W1D",
cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());
assertEquals("-P521W5D",
cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());
});
["month", "months"].forEach(function(largestUnit) {
let opt = {largestUnit};
assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());
assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());
assertEquals("P7D", cal.dateUntil("2021-07-16", "2021-07-23", opt).toJSON());
assertEquals("P1M", cal.dateUntil("2021-07-16", "2021-08-16", opt).toJSON());
assertEquals("P1M", cal.dateUntil("2020-12-16", "2021-01-16", opt).toJSON());
assertEquals("P1M", cal.dateUntil("2021-01-05", "2021-02-05", opt).toJSON());
assertEquals("P2M", cal.dateUntil("2021-01-07", "2021-03-07", opt).toJSON());
assertEquals("P1M1D",
cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());
assertEquals("P28D", cal.dateUntil("2021-07-16", "2021-08-13", opt).toJSON());
assertEquals("P2M", cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());
assertEquals("P12M",
cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());
assertEquals("P120M"
,cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());
assertEquals("-P1D",
cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());
assertEquals("-P1M1D",
cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());
assertEquals("-P28D",
cal.dateUntil("2021-08-13", "2021-07-16", opt).toJSON());
assertEquals("-P1M",
cal.dateUntil("2021-08-16", "2021-07-16", opt).toJSON());
assertEquals("-P1M3D",
cal.dateUntil("2021-08-16", "2021-07-13", opt).toJSON());
assertEquals("-P2M",
cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());
assertEquals("-P2M5D",
cal.dateUntil("2021-09-21", "2021-07-16", opt).toJSON());
assertEquals("-P12M",
cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());
assertEquals("-P12M1D",
cal.dateUntil("2022-07-17", "2021-07-16", opt).toJSON());
assertEquals("-P120M",
cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());
});
["year", "years"].forEach(function(largestUnit) {
let opt = {largestUnit};
assertEquals("PT0S", cal.dateUntil("2021-07-16", "2021-07-16", opt).toJSON());
assertEquals("P1D", cal.dateUntil("2021-07-16", "2021-07-17", opt).toJSON());
assertEquals("P7D", cal.dateUntil("2021-07-16", "2021-07-23", opt).toJSON());
assertEquals("P1M", cal.dateUntil("2021-07-16", "2021-08-16", opt).toJSON());
assertEquals("P1M", cal.dateUntil("2020-12-16", "2021-01-16", opt).toJSON());
assertEquals("P1M", cal.dateUntil("2021-01-05", "2021-02-05", opt).toJSON());
assertEquals("P2M", cal.dateUntil("2021-01-07", "2021-03-07", opt).toJSON());
assertEquals("P1M1D", cal.dateUntil("2021-07-16", "2021-08-17", opt).toJSON());
assertEquals("P28D", cal.dateUntil("2021-07-16", "2021-08-13", opt).toJSON());
assertEquals("P2M", cal.dateUntil("2021-07-16", "2021-09-16", opt).toJSON());
assertEquals("P1Y",
cal.dateUntil("2021-07-16", "2022-07-16", opt).toJSON());
assertEquals("P1Y3D",
cal.dateUntil("2021-07-16", "2022-07-19", opt).toJSON());
assertEquals("P1Y2M3D",
cal.dateUntil("2021-07-16", "2022-09-19", opt).toJSON());
assertEquals("P10Y",
cal.dateUntil("2021-07-16", "2031-07-16", opt).toJSON());
assertEquals("P10Y5M",
cal.dateUntil("2021-07-16", "2031-12-16", opt).toJSON());
assertEquals("P23Y7M",
cal.dateUntil("1997-12-16", "2021-07-16", opt).toJSON());
assertEquals("P24Y",
cal.dateUntil("1997-07-16", "2021-07-16", opt).toJSON());
assertEquals("P23Y11M29D",
cal.dateUntil("1997-07-16", "2021-07-15", opt).toJSON());
assertEquals("P23Y11M30D",
cal.dateUntil("1997-06-16", "2021-06-15", opt).toJSON());
assertEquals("P60Y1M",
cal.dateUntil("1960-02-16", "2020-03-16", opt).toJSON());
assertEquals("P61Y27D",
cal.dateUntil("1960-02-16", "2021-03-15", opt).toJSON());
assertEquals("P60Y28D",
cal.dateUntil("1960-02-16", "2020-03-15", opt).toJSON());
assertEquals("P3M16D",
cal.dateUntil("2021-03-30", "2021-07-16", opt).toJSON());
assertEquals("P1Y3M16D",
cal.dateUntil("2020-03-30", "2021-07-16", opt).toJSON());
assertEquals("P61Y3M16D",
cal.dateUntil("1960-03-30", "2021-07-16", opt).toJSON());
assertEquals("P1Y6M16D",
cal.dateUntil("2019-12-30", "2021-07-16", opt).toJSON());
assertEquals("P6M16D",
cal.dateUntil("2020-12-30", "2021-07-16", opt).toJSON());
assertEquals("P23Y6M16D",
cal.dateUntil("1997-12-30", "2021-07-16", opt).toJSON());
assertEquals("P2019Y6M21D",
cal.dateUntil("0001-12-25", "2021-07-16", opt).toJSON());
assertEquals("P1Y2M5D",
cal.dateUntil("2019-12-30", "2021-03-05", opt).toJSON());
assertEquals("-P1D",
cal.dateUntil("2021-07-17", "2021-07-16", opt).toJSON());
assertEquals("-P1M1D",
cal.dateUntil("2021-08-17", "2021-07-16", opt).toJSON());
assertEquals("-P28D",
cal.dateUntil("2021-08-13", "2021-07-16", opt).toJSON());
assertEquals("-P1M",
cal.dateUntil("2021-08-16", "2021-07-16", opt).toJSON());
assertEquals("-P1M3D",
cal.dateUntil("2021-08-16", "2021-07-13", opt).toJSON());
assertEquals("-P2M",
cal.dateUntil("2021-09-16", "2021-07-16", opt).toJSON());
assertEquals("-P2M5D",
cal.dateUntil("2021-09-21", "2021-07-16", opt).toJSON());
assertEquals("-P1Y",
cal.dateUntil("2022-07-16", "2021-07-16", opt).toJSON());
assertEquals("-P1Y1D",
cal.dateUntil("2022-07-17", "2021-07-16", opt).toJSON());
assertEquals("-P1Y3M1D",
cal.dateUntil("2022-10-17", "2021-07-16", opt).toJSON());
assertEquals("-P10Y",
cal.dateUntil("2031-07-16", "2021-07-16", opt).toJSON());
assertEquals("-P10Y11M",
cal.dateUntil("2032-07-16", "2021-08-16", opt).toJSON());
assertEquals("-P10Y5M",
cal.dateUntil("2031-12-16", "2021-07-16", opt).toJSON());
assertEquals("-P13Y7M",
cal.dateUntil("2011-07-16", "1997-12-16", opt).toJSON());
assertEquals("-P24Y",
cal.dateUntil("2021-07-16", "1997-07-16", opt).toJSON());
assertEquals("-P23Y11M30D",
cal.dateUntil("2021-07-15", "1997-07-16", opt).toJSON());
assertEquals("-P23Y11M29D",
cal.dateUntil("2021-06-15", "1997-06-16", opt).toJSON());
assertEquals("-P60Y1M",
cal.dateUntil("2020-03-16", "1960-02-16", opt).toJSON());
assertEquals("-P61Y28D",
cal.dateUntil("2021-03-15", "1960-02-16", opt).toJSON());
assertEquals("-P60Y28D",
cal.dateUntil("2020-03-15", "1960-02-16", opt).toJSON());
assertEquals("-P61Y3M17D",
cal.dateUntil("2021-07-16", "1960-03-30", opt).toJSON());
assertEquals("-P2019Y6M22D",
cal.dateUntil("2021-07-16", "0001-12-25", opt).toJSON());
assertEquals("-P23Y6M17D",
cal.dateUntil("2021-07-16", "1997-12-30", opt).toJSON());
});

View File

@ -0,0 +1,80 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dayofweek
let cal = new Temporal.Calendar("iso8601");
assertEquals(4, cal.dayOfWeek(new Temporal.PlainDate(1970, 1, 1)));
assertEquals(6, cal.dayOfWeek(new Temporal.PlainDate(2000, 1, 1)));
assertEquals(5, cal.dayOfWeek(new Temporal.PlainDate(2021, 1, 15)));
// leap year
assertEquals(6, cal.dayOfWeek(new Temporal.PlainDate(2020, 2, 15)));
assertEquals(2, cal.dayOfWeek(new Temporal.PlainDate(2000, 2, 15)));
// non-leap year
assertEquals(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 2, 15)));
assertEquals(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 3, 15)));
assertEquals(4, cal.dayOfWeek(new Temporal.PlainDate(2021, 4, 15)));
assertEquals(6, cal.dayOfWeek(new Temporal.PlainDate(2021, 5, 15)));
assertEquals(2, cal.dayOfWeek(new Temporal.PlainDate(2021, 6, 15)));
assertEquals(4, cal.dayOfWeek(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(7, cal.dayOfWeek(new Temporal.PlainDate(2021, 8, 15)));
assertEquals(3, cal.dayOfWeek(new Temporal.PlainDate(2021, 9, 15)));
assertEquals(5, cal.dayOfWeek(new Temporal.PlainDate(2021, 10, 15)));
assertEquals(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 11, 15)));
assertEquals(3, cal.dayOfWeek(new Temporal.PlainDate(2021, 12, 15)));
assertEquals(4,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13)));
// leap year
assertEquals(5,
cal.dayOfWeek(new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13)));
assertEquals(3,
cal.dayOfWeek(new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13)));
// non leap year
assertEquals(7,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13)));
assertEquals(7,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13)));
assertEquals(3,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13)));
assertEquals(5,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13)));
assertEquals(1,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13)));
assertEquals(3,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13)));
assertEquals(6,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(2,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13)));
assertEquals(4,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13)));
assertEquals(7,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13)));
assertEquals(2,
cal.dayOfWeek(new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13)));
assertEquals(5, cal.dayOfWeek("2019-01-18"));
// leap year
assertEquals(2, cal.dayOfWeek("2020-02-18"));
// non leap
assertEquals(1, cal.dayOfWeek("2019-02-18"));
assertEquals(1, cal.dayOfWeek("2019-03-18"));
assertEquals(4, cal.dayOfWeek("2019-04-18"));
assertEquals(6, cal.dayOfWeek("2019-05-18"));
assertEquals(2, cal.dayOfWeek("2019-06-18"));
assertEquals(4, cal.dayOfWeek("2019-07-18"));
assertEquals(7, cal.dayOfWeek("2019-08-18"));
assertEquals(3, cal.dayOfWeek("2019-09-18"));
assertEquals(5, cal.dayOfWeek("2019-10-18"));
assertEquals(1, cal.dayOfWeek("2019-11-18"));
assertEquals(3, cal.dayOfWeek("2019-12-18"));
// TODO test the following later
//assertEquals(7, cal.dayOfWeek(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(31, cal.dayOfWeek(new Temporal.ZonedDateTime(86400n * 366n * 50n,
// "UTC")))
//assertEquals(30, cal.dayOfWeek({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,43 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dayofyear
let cal = new Temporal.Calendar("iso8601");
assertEquals(1, cal.dayOfYear(new Temporal.PlainDate(1970, 1, 1)));
assertEquals(1, cal.dayOfYear(new Temporal.PlainDate(2000, 1, 1)));
assertEquals(15, cal.dayOfYear(new Temporal.PlainDate(2021, 1, 15)));
assertEquals(46, cal.dayOfYear(new Temporal.PlainDate(2020, 2, 15)));
assertEquals(46, cal.dayOfYear(new Temporal.PlainDate(2000, 2, 15)));
assertEquals(75, cal.dayOfYear(new Temporal.PlainDate(2020, 3, 15)));
assertEquals(75, cal.dayOfYear(new Temporal.PlainDate(2000, 3, 15)));
assertEquals(74, cal.dayOfYear(new Temporal.PlainDate(2001, 3, 15)));
assertEquals(366, cal.dayOfYear(new Temporal.PlainDate(2000, 12, 31)));
assertEquals(365, cal.dayOfYear(new Temporal.PlainDate(2001, 12, 31)));
assertEquals(23,
cal.dayOfYear(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13)));
assertEquals(54,
cal.dayOfYear(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13)));
assertEquals(83,
cal.dayOfYear(new Temporal.PlainDateTime(1996, 3, 23, 5, 30, 13)));
assertEquals(82,
cal.dayOfYear(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13)));
assertEquals(365,
cal.dayOfYear(new Temporal.PlainDateTime(1997, 12, 31, 5, 30, 13)));
assertEquals(366,
cal.dayOfYear(new Temporal.PlainDateTime(1996, 12, 31, 5, 30, 13)));
assertEquals(18, cal.dayOfYear("2019-01-18"));
assertEquals(49, cal.dayOfYear("2020-02-18"));
assertEquals(365, cal.dayOfYear("2019-12-31"));
assertEquals(366, cal.dayOfYear("2000-12-31"));
// TODO test the following later
//assertEquals(7, cal.dayOfYear(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(31, cal.dayOfYear(new Temporal.ZonedDateTime(
// 86400n * 366n * 50n, "UTC")))
//assertEquals(30, cal.dayOfYear({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,17 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.day
let cal = new Temporal.Calendar("iso8601");
assertEquals(15, cal.day(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(23, cal.day(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(6, cal.day(new Temporal.PlainMonthDay(2, 6)));
assertEquals(18, cal.day("2019-03-18"));
// TODO test the following later
//assertEquals(??, cal.day(new Temporal.ZonedDateTime(86400n * 366n * 50n,
// "UTC")))
//assertEquals(11, cal.day({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,77 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.daysinmonth
let cal = new Temporal.Calendar("iso8601");
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 1, 15)));
// leap year
assertEquals(29, cal.daysInMonth(new Temporal.PlainDate(2020, 2, 15)));
assertEquals(29, cal.daysInMonth(new Temporal.PlainDate(2000, 2, 15)));
// non-leap year
assertEquals(28, cal.daysInMonth(new Temporal.PlainDate(2021, 2, 15)));
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 3, 15)));
assertEquals(30, cal.daysInMonth(new Temporal.PlainDate(2021, 4, 15)));
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 5, 15)));
assertEquals(30, cal.daysInMonth(new Temporal.PlainDate(2021, 6, 15)));
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 8, 15)));
assertEquals(30, cal.daysInMonth(new Temporal.PlainDate(2021, 9, 15)));
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 10, 15)));
assertEquals(30, cal.daysInMonth(new Temporal.PlainDate(2021, 11, 15)));
assertEquals(31, cal.daysInMonth(new Temporal.PlainDate(2021, 12, 15)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13)));
// leap year
assertEquals(29,
cal.daysInMonth(new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13)));
assertEquals(29,
cal.daysInMonth(new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13)));
// non leap year
assertEquals(28,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13)));
assertEquals(30,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13)));
assertEquals(30,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(30,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13)));
assertEquals(30,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13)));
assertEquals(31,
cal.daysInMonth(new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13)));
assertEquals(31, cal.daysInMonth("2019-01-18"));
// leap year
assertEquals(29, cal.daysInMonth("2020-02-18"));
// non leap
assertEquals(28, cal.daysInMonth("2019-02-18"));
assertEquals(31, cal.daysInMonth("2019-03-18"));
assertEquals(30, cal.daysInMonth("2019-04-18"));
assertEquals(31, cal.daysInMonth("2019-05-18"));
assertEquals(30, cal.daysInMonth("2019-06-18"));
assertEquals(31, cal.daysInMonth("2019-07-18"));
assertEquals(31, cal.daysInMonth("2019-08-18"));
assertEquals(30, cal.daysInMonth("2019-09-18"));
assertEquals(31, cal.daysInMonth("2019-10-18"));
assertEquals(30, cal.daysInMonth("2019-11-18"));
assertEquals(31, cal.daysInMonth("2019-12-18"));
// TODO test the following later
//assertEquals(7, cal.daysInMonth(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(31, cal.daysInMonth(new Temporal.ZonedDateTime(
// 86400n * 366n * 50n, "UTC")))
//assertEquals(30, cal.daysInMonth({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,18 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.weekofyear
let cal = new Temporal.Calendar("iso8601");
assertEquals(7, cal.daysInWeek(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(7,
cal.daysInWeek(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(7, cal.daysInWeek("2019-03-18"));
// TODO test the following later
//assertEquals(7, cal.daysInWeek(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(??, cal.day(new Temporal.ZonedDateTime(86400n * 366n * 50n,
// "UTC")))
//assertEquals(11, cal.day({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,57 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.daysinyear
let cal = new Temporal.Calendar("iso8601");
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(1995, 7, 15)));
assertEquals(366, cal.daysInYear(new Temporal.PlainDate(1996, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(1997, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(1998, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(1999, 7, 15)));
assertEquals(366, cal.daysInYear(new Temporal.PlainDate(2000, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(2001, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(2002, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(2003, 7, 15)));
assertEquals(366, cal.daysInYear(new Temporal.PlainDate(2004, 7, 15)));
assertEquals(365, cal.daysInYear(new Temporal.PlainDate(2005, 7, 15)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13)));
assertEquals(366,
cal.daysInYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13)));
assertEquals(366,
cal.daysInYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13)));
assertEquals(366,
cal.daysInYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13)));
assertEquals(365,
cal.daysInYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13)));
assertEquals(365, cal.daysInYear("2019-03-18"));
assertEquals(366, cal.daysInYear("2020-03-18"));
assertEquals(365, cal.daysInYear("2021-03-18"));
assertEquals(365, cal.daysInYear("2022-03-18"));
assertEquals(365, cal.daysInYear("2023-03-18"));
assertEquals(366, cal.daysInYear("2024-03-18"));
assertEquals(365, cal.daysInYear("2025-03-18"));
assertEquals(365, cal.daysInYear("2026-03-18"));
// TODO test the following later
//assertEquals(365, cal.daysInYear(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(365, cal.daysInYear(new Temporal.ZonedDateTime(
// 86400n * 366n * 50n, "UTC")))
//assertEquals(365, cal.daysInYear({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,58 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.fields
let cal = new Temporal.Calendar("iso8601")
assertEquals("iso8601", cal.id)
let i = 1;
const repeated = {
*[Symbol.iterator]() {
yield "year";
i++;
yield "year";
i++;
}
}
assertThrows(() => cal.fields(repeated), RangeError);
assertEquals(2, i);
let repeatedArray = Array.from(repeated);
assertThrows(() => cal.fields(repeatedArray), RangeError);
const week = {
*[Symbol.iterator]() {
yield "week";
}
}
assertThrows(() => cal.fields(week), RangeError);
assertThrows(() => cal.fields(['week']), RangeError);
assertThrows(() => cal.fields(new Set(['week'])), RangeError);
const allValid = {
*[Symbol.iterator]() {
yield "nanosecond";
yield "microsecond";
yield "millisecond";
yield "second";
yield "minute";
yield "hour";
yield "day";
yield "monthCode";
yield "month";
yield "year";
}
}
let allValidArray = Array.from(allValid);
let allValidSet = new Set(allValid);
assertArrayEquals(allValidArray, cal.fields(allValid));
assertArrayEquals(allValidArray, cal.fields(allValidArray));
assertArrayEquals(allValidArray, cal.fields(allValidSet));
// cannot just return the same array
assertTrue(allValidArray != cal.fields(allValidArray));

View File

@ -0,0 +1,21 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.from
// 1. If NewTarget is undefined, then
// a. Throw a TypeError exception.
assertEquals("iso8601",
(Temporal.Calendar.from("iso8601")).id);
assertEquals("iso8601",
(Temporal.Calendar.from(new Temporal.PlainDate(2021, 7, 3))).id);
assertEquals("iso8601",
(Temporal.Calendar.from(new Temporal.PlainDateTime(2021, 7, 3, 4, 5))).id);
assertEquals("iso8601",
(Temporal.Calendar.from(new Temporal.PlainTime())).id);
assertEquals("iso8601",
(Temporal.Calendar.from(new Temporal.PlainYearMonth(2011, 4))).id);
assertEquals("iso8601",
(Temporal.Calendar.from(new Temporal.PlainMonthDay(2, 6))).id);

View File

@ -0,0 +1,57 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.inleapyear
let cal = new Temporal.Calendar("iso8601");
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(1995, 7, 15)));
assertEquals(true, cal.inLeapYear(new Temporal.PlainDate(1996, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(1997, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(1998, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(1999, 7, 15)));
assertEquals(true, cal.inLeapYear(new Temporal.PlainDate(2000, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(2001, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(2002, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(2003, 7, 15)));
assertEquals(true, cal.inLeapYear(new Temporal.PlainDate(2004, 7, 15)));
assertEquals(false, cal.inLeapYear(new Temporal.PlainDate(2005, 7, 15)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13)));
assertEquals(true,
cal.inLeapYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13)));
assertEquals(true,
cal.inLeapYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13)));
assertEquals(true,
cal.inLeapYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13)));
assertEquals(false,
cal.inLeapYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13)));
assertEquals(false, cal.inLeapYear("2019-03-18"));
assertEquals(true, cal.inLeapYear("2020-03-18"));
assertEquals(false, cal.inLeapYear("2021-03-18"));
assertEquals(false, cal.inLeapYear("2022-03-18"));
assertEquals(false, cal.inLeapYear("2023-03-18"));
assertEquals(true, cal.inLeapYear("2024-03-18"));
assertEquals(false, cal.inLeapYear("2025-03-18"));
assertEquals(false, cal.inLeapYear("2026-03-18"));
// TODO Test the following later
//assertEquals(false, cal.inLeapYear(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(false, cal.inLeapYear(new Temporal.ZonedDateTime(
// 86400n * truen * 50n, "UTC")))
//assertEquals(false, cal.inLeapYear({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,58 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.mergefields
let cal = new Temporal.Calendar("iso8601")
// Test throwing
assertThrows(() => cal.mergeFields(), TypeError);
assertThrows(() => cal.mergeFields(undefined, {}), TypeError);
assertThrows(() => cal.mergeFields(null, {}), TypeError);
assertThrows(() => cal.mergeFields({}, undefined), TypeError);
assertThrows(() => cal.mergeFields({}, null), TypeError);
// Test String, number, true, false, NaN, BigInt, Symbol types
// pending on https://github.com/tc39/proposal-temporal/issues/1647
// Assert only string will be merged
assertArrayEquals({}, cal.mergeFields({1: 2}, {3: 4}));
assertArrayEquals({}, cal.mergeFields({true: 2}, {false: 4}));
assertArrayEquals({}, cal.mergeFields({1n: 2}, {2n: 4}));
assertArrayEquals({}, cal.mergeFields({Infinity: 2}, {Infinity: 4}));
assertArrayEquals({}, cal.mergeFields({undefined: 2}, {NaN: 4}));
assertArrayEquals({}, cal.mergeFields({["foo"]: 2}, {["bar"]: 4}));
assertArrayEquals({a:1, b:2, c:4}, cal.mergeFields({a: 1, b: 2}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, month:5},
cal.mergeFields({a: 1, b: 2}, {b:3, c:4, month:5}));
assertArrayEquals({a:1, b:2, c:4, month:5, month:'M06'},
cal.mergeFields({a: 1, b: 2}, {b:3, c:4, month:5, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:'M06'}, cal.mergeFields({a: 1, b: 2},
{b:3, c:4, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:5},
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4, month:5}));
assertArrayEquals({a:1, b:2, c:4, month:5},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'},
{b:3, c:4, month:5}));
assertArrayEquals({a:1, b:2, c:4, monthCode:'M06'},
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, monthCode:'M06'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'},
{b:3, c:4, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:5, monthCode:'M06'},
cal.mergeFields({a: 1, b: 2, month:7},
{b:3, c:4, month:5, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:5, monthCode:'M06'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'},
{b:3, c:4, month:5, monthCode:'M06'}));
assertArrayEquals({a:1, b:2, c:4, month:7},
cal.mergeFields({a: 1, b: 2, month:7}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, month:5, monthCode:'M08'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, month:7, monthCode:'M08'},
cal.mergeFields({a: 1, b: 2, month:7, monthCode:'M08'}, {b:3, c:4}));
assertArrayEquals({a:1, b:2, c:4, monthCode:'M08'},
cal.mergeFields({a: 1, b: 2, monthCode:'M08'}, {b:3, c:4}));

View File

@ -0,0 +1,19 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.monthcode
let cal = new Temporal.Calendar("iso8601");
assertEquals("M07", cal.monthCode(new Temporal.PlainDate(2021, 7, 15)));
assertEquals("M08",
cal.monthCode(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals("M06", cal.monthCode(new Temporal.PlainYearMonth(1999, 6)));
assertEquals("M02", cal.monthCode(new Temporal.PlainMonthDay(2, 6)));
assertEquals("M03", cal.monthCode("2019-03-15"));
// TODO Test the following later
//assertEquals("M01", cal.monthCode(new Temporal.ZonedDateTime(
// 86400n * 366n * 50n, "UTC")))
//assertEquals("M09", cal.monthCode({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,187 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.monthdayfromfields
let cal = new Temporal.Calendar("iso8601")
// Check throw for first arg
assertThrows(() => cal.monthDayFromFields(), TypeError);
[undefined, true, false, 123, 456n, Symbol(), "string"].forEach(
function(fields) {
assertThrows(() => cal.monthDayFromFields(fields), TypeError);
assertThrows(() => cal.monthDayFromFields(fields, undefined), TypeError);
assertThrows(() => cal.monthDayFromFields(fields,
{overflow: "constrain"}), TypeError);
assertThrows(() => cal.monthDayFromFields(fields, {overflow: "reject"}),
TypeError);
});
assertThrows(() => cal.monthDayFromFields({month: 1, day: 17}), TypeError);
assertThrows(() => cal.monthDayFromFields({year: 2021, day: 17}), TypeError);
assertThrows(() => cal.monthDayFromFields({year: 2021, month: 12}), TypeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "m1", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M1", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "m01", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 12, monthCode: "M11", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M00", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M19", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M99", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M13", day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: -1, day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: -Infinity, day: 17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 7, day: -17}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 7, day: -Infinity}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 12, day: 0}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 12, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 1, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 2, day: 29}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 6, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 9, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 0, day: 5}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 13, day: 5}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M12", day: 0}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M12", day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M01", day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M06", day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M09", day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M00", day: 5}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, monthCode: "M13", day: 5}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 12, day: 0}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 0, day: 3}), RangeError);
// Check throw for the second arg
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 7, day: 13}, {overflow: "invalid"}), RangeError);
assertEquals("07-15", cal.monthDayFromFields(
{year: 2021, month: 7, day: 15}).toJSON());
assertEquals("07-03", cal.monthDayFromFields(
{year: 2021, month: 7, day: 3}).toJSON());
assertEquals("12-31", cal.monthDayFromFields(
{year: 2021, month: 12, day: 31}).toJSON());
assertEquals("07-15", cal.monthDayFromFields(
{year: 2021, monthCode: "M07", day: 15}).toJSON());
assertEquals("07-03", cal.monthDayFromFields(
{year: 2021, monthCode: "M07", day: 3}).toJSON());
assertEquals("12-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M12", day: 31}).toJSON());
assertEquals("02-29", cal.monthDayFromFields(
{year: 2021, monthCode: "M02", day: 29}).toJSON());
assertEquals("01-31", cal.monthDayFromFields(
{year: 2021, month: 1, day: 133}).toJSON());
assertEquals("02-28", cal.monthDayFromFields(
{year: 2021, month: 2, day: 133}).toJSON());
assertEquals("03-31", cal.monthDayFromFields(
{year: 2021, month: 3, day: 9033}).toJSON());
assertEquals("04-30", cal.monthDayFromFields(
{year: 2021, month: 4, day: 50}).toJSON());
assertEquals("05-31", cal.monthDayFromFields(
{year: 2021, month: 5, day: 77}).toJSON());
assertEquals("06-30", cal.monthDayFromFields(
{year: 2021, month: 6, day: 33}).toJSON());
assertEquals("07-31", cal.monthDayFromFields(
{year: 2021, month: 7, day: 33}).toJSON());
assertEquals("08-31", cal.monthDayFromFields(
{year: 2021, month: 8, day: 300}).toJSON());
assertEquals("09-30", cal.monthDayFromFields(
{year: 2021, month: 9, day: 400}).toJSON());
assertEquals("10-31", cal.monthDayFromFields(
{year: 2021, month: 10, day: 400}).toJSON());
assertEquals("11-30", cal.monthDayFromFields(
{year: 2021, month: 11, day: 400}).toJSON());
assertEquals("12-31", cal.monthDayFromFields(
{year: 2021, month: 12, day: 500}).toJSON());
assertEquals("12-31", cal.monthDayFromFields(
{year: 2021, month: 13, day: 500}).toJSON());
assertEquals("12-31", cal.monthDayFromFields(
{year: 2021, month: 999999, day: 500}).toJSON());
assertEquals("01-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M01", day: 133}).toJSON());
assertEquals("02-29", cal.monthDayFromFields(
{year: 2021, monthCode: "M02", day: 133}).toJSON());
assertEquals("03-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M03", day: 9033}).toJSON());
assertEquals("04-30", cal.monthDayFromFields(
{year: 2021, monthCode: "M04", day: 50}).toJSON());
assertEquals("05-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M05", day: 77}).toJSON());
assertEquals("06-30", cal.monthDayFromFields(
{year: 2021, monthCode: "M06", day: 33}).toJSON());
assertEquals("07-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M07", day: 33}).toJSON());
assertEquals("08-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M08", day: 300}).toJSON());
assertEquals("09-30", cal.monthDayFromFields(
{year: 2021, monthCode: "M09", day: 400}).toJSON());
assertEquals("10-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M10", day: 400}).toJSON());
assertEquals("11-30", cal.monthDayFromFields(
{year: 2021, monthCode: "M11", day: 400}).toJSON());
assertEquals("12-31", cal.monthDayFromFields(
{year: 2021, monthCode: "M12", day: 500}).toJSON());
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 1, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 2, day: 29}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 3, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 4, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 5, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 6, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 7, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 8, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 9, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 10, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 11, day: 31}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 12, day: 32}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.monthDayFromFields(
{year: 2021, month: 13, day: 5}, {overflow: "reject"}), RangeError);

View File

@ -0,0 +1,18 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.month
let cal = new Temporal.Calendar("iso8601");
assertEquals(7, cal.month(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(8, cal.month(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(6, cal.month(new Temporal.PlainYearMonth(1999, 6)));
assertEquals(3, cal.month("2019-03-15"));
assertThrows(() => cal.month(new Temporal.PlainMonthDay(3, 16)), TypeError);
// TODO Test the following later.
//assertEquals(1, cal.month(new Temporal.ZonedDateTime(86400n * 366n * 50n,
// "UTC")))
//assertEquals(9, cal.month({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,22 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.monthsinyear
let cal = new Temporal.Calendar("iso8601");
assertEquals(12, cal.monthsInYear(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(12, cal.monthsInYear(new Temporal.PlainDate(1234, 7, 15)));
assertEquals(12,
cal.monthsInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assertEquals(12,
cal.monthsInYear(new Temporal.PlainDateTime(1234, 8, 23, 5, 30, 13)));
assertEquals(12, cal.monthsInYear("2019-03-18"));
assertEquals(12, cal.monthsInYear("1234-03-18"));
// TODO Test the following later.
//assertEquals(12, cal.monthsInYear(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(12, cal.monthsInYear(new Temporal.ZonedDateTime(
// 86400n * 366n * 50n, "UTC")))
//assertEquals(12, cal.monthsInYear({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,68 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.weekofyear
let cal = new Temporal.Calendar("iso8601");
// From https://en.wikipedia.org/wiki/ISO_week_date#Relation_with_the_Gregorian_calendar
assertEquals(53, cal.weekOfYear(new Temporal.PlainDate(1977, 01, 01)));
assertEquals(53, cal.weekOfYear(new Temporal.PlainDate(1977, 01, 02)));
assertEquals(52, cal.weekOfYear(new Temporal.PlainDate(1977, 12, 31)));
assertEquals(52, cal.weekOfYear(new Temporal.PlainDate(1978, 01, 01)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1978, 01, 02)));
assertEquals(52, cal.weekOfYear(new Temporal.PlainDate(1978, 12, 31)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1979, 01, 01)));
assertEquals(52, cal.weekOfYear(new Temporal.PlainDate(1979, 12, 30)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1979, 12, 31)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1980, 01, 01)));
assertEquals(52, cal.weekOfYear(new Temporal.PlainDate(1980, 12, 28)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1980, 12, 29)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1980, 12, 30)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1980, 12, 31)));
assertEquals(1, cal.weekOfYear(new Temporal.PlainDate(1981, 01, 01)));
assertEquals(53, cal.weekOfYear(new Temporal.PlainDate(1981, 12, 31)));
assertEquals(53, cal.weekOfYear(new Temporal.PlainDate(1982, 01, 01)));
assertEquals(53, cal.weekOfYear(new Temporal.PlainDate(1982, 01, 02)));
assertEquals(53, cal.weekOfYear(new Temporal.PlainDate(1982, 01, 03)));
assertEquals(53, cal.weekOfYear("1977-01-01"));
assertEquals(53, cal.weekOfYear("1977-01-02"));
assertEquals(52, cal.weekOfYear("1977-12-31"));
assertEquals(52, cal.weekOfYear("1978-01-01"));
assertEquals(1, cal.weekOfYear("1978-01-02"));
assertEquals(52, cal.weekOfYear("1978-12-31"));
assertEquals(1, cal.weekOfYear("1979-01-01"));
assertEquals(52, cal.weekOfYear("1979-12-30"));
assertEquals(1, cal.weekOfYear("1979-12-31"));
assertEquals(1, cal.weekOfYear("1980-01-01"));
assertEquals(52, cal.weekOfYear("1980-12-28"));
assertEquals(1, cal.weekOfYear("1980-12-29"));
assertEquals(1, cal.weekOfYear("1980-12-30"));
assertEquals(1, cal.weekOfYear("1980-12-31"));
assertEquals(1, cal.weekOfYear("1981-01-01"));
assertEquals(53, cal.weekOfYear("1981-12-31"));
assertEquals(53, cal.weekOfYear("1982-01-01"));
assertEquals(53, cal.weekOfYear("1982-01-02"));
assertEquals(53, cal.weekOfYear("1982-01-03"));
// TODO test the following later
//assertEquals(4, cal.weekOfYear(new Temporal.PlainDateTime(1997, 1, 23, 5,
// 30, 13)));
//assertEquals(7, cal.weekOfYear(new Temporal.PlainMonthDay(2, 6)));
//assertEquals(31, cal.weekOfYear(new Temporal.ZonedDateTime(
// 86400n * 366n * 50n, "UTC")))
//assertEquals(30, cal.weekOfYear({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,130 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.yearmonthfromfields
let cal = new Temporal.Calendar("iso8601")
// Check throw for first arg
assertThrows(() => cal.yearMonthFromFields(),
TypeError);
[undefined, true, false, 123, 456n, Symbol(), "string"].forEach(
function(fields) {
assertThrows(() => cal.yearMonthFromFields(fields), TypeError);
assertThrows(() => cal.yearMonthFromFields(fields, undefined), TypeError);
assertThrows(() => cal.yearMonthFromFields(fields,
{overflow: "constrain"}), TypeError);
assertThrows(() => cal.yearMonthFromFields(fields,
{overflow: "reject"}), TypeError);
});
assertThrows(() => cal.yearMonthFromFields({month: 1}), TypeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021}), TypeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "m1"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M1"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "m01"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: 12,
monthCode: "M11"}), RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M00"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M19"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M99"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M13"}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: -1}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: -Infinity}),
RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: 0, day: 5},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: 13, day: 5},
{overflow: "reject"}), RangeError);
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, monthCode: "M00"}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, monthCode: "M13"}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 0}), RangeError);
// Check throw for the second arg
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 7}, {overflow: "invalid"}), RangeError);
assertEquals("2021-07",
cal.yearMonthFromFields({year: 2021, month: 7}).toJSON());
assertEquals("2021-12",
cal.yearMonthFromFields({year: 2021, month: 12}).toJSON());
assertEquals("2021-07",
cal.yearMonthFromFields({year: 2021, monthCode: "M07"}).toJSON());
assertEquals("2021-12",
cal.yearMonthFromFields({year: 2021, monthCode: "M12"}).toJSON());
assertEquals("2021-01",
cal.yearMonthFromFields({year: 2021, month: 1}).toJSON());
assertEquals("2021-02",
cal.yearMonthFromFields({year: 2021, month: 2}).toJSON());
assertEquals("2021-03",
cal.yearMonthFromFields({year: 2021, month: 3}).toJSON());
assertEquals("2021-04",
cal.yearMonthFromFields({year: 2021, month: 4}).toJSON());
assertEquals("2021-05",
cal.yearMonthFromFields({year: 2021, month: 5}).toJSON());
assertEquals("2021-06",
cal.yearMonthFromFields({year: 2021, month: 6}).toJSON());
assertEquals("2021-07",
cal.yearMonthFromFields({year: 2021, month: 7}).toJSON());
assertEquals("2021-08",
cal.yearMonthFromFields({year: 2021, month: 8}).toJSON());
assertEquals("2021-09",
cal.yearMonthFromFields({year: 2021, month: 9}).toJSON());
assertEquals("2021-10",
cal.yearMonthFromFields({year: 2021, month: 10}).toJSON());
assertEquals("2021-11",
cal.yearMonthFromFields({year: 2021, month: 11}).toJSON());
assertEquals("2021-12",
cal.yearMonthFromFields({year: 2021, month: 12}).toJSON());
assertEquals("2021-12",
cal.yearMonthFromFields({year: 2021, month: 13}).toJSON());
assertEquals("2021-12",
cal.yearMonthFromFields({year: 2021, month: 999999}).toJSON());
assertEquals("2021-01",
cal.yearMonthFromFields({year: 2021, monthCode: "M01"}).toJSON());
assertEquals("2021-02",
cal.yearMonthFromFields({year: 2021, monthCode: "M02"}).toJSON());
assertEquals("2021-03",
cal.yearMonthFromFields({year: 2021, monthCode: "M03"}).toJSON());
assertEquals("2021-04",
cal.yearMonthFromFields({year: 2021, monthCode: "M04"}).toJSON());
assertEquals("2021-05",
cal.yearMonthFromFields({year: 2021, monthCode: "M05"}).toJSON());
assertEquals("2021-06",
cal.yearMonthFromFields({year: 2021, monthCode: "M06"}).toJSON());
assertEquals("2021-07",
cal.yearMonthFromFields({year: 2021, monthCode: "M07"}).toJSON());
assertEquals("2021-08",
cal.yearMonthFromFields({year: 2021, monthCode: "M08"}).toJSON());
assertEquals("2021-09",
cal.yearMonthFromFields({year: 2021, monthCode: "M09"}).toJSON());
assertEquals("2021-10",
cal.yearMonthFromFields({year: 2021, monthCode: "M10"}).toJSON());
assertEquals("2021-11",
cal.yearMonthFromFields({year: 2021, monthCode: "M11"}).toJSON());
assertEquals("2021-12",
cal.yearMonthFromFields({year: 2021, monthCode: "M12"}).toJSON());
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 13}, {overflow: "reject"}), RangeError);
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 9995}, {overflow: "reject"}), RangeError);

View File

@ -0,0 +1,18 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.year
let cal = new Temporal.Calendar("iso8601");
assertEquals(2021, cal.year(new Temporal.PlainDate(2021, 7, 15)));
assertEquals(1997, cal.year(new Temporal.PlainDateTime(
1997, 8, 23, 5, 30, 13)));
assertEquals(1999, cal.year(new Temporal.PlainYearMonth(1999, 6)));
assertEquals(2019, cal.year("2019-03-15"));
// TODO Test the following later.
//assertEquals(2020, cal.year(new Temporal.ZonedDateTime(86400n * 366n * 50n, "UTC")))
//assertEquals(2001, cal.year({year: 2001, month: 9, day: 11}));

View File

@ -0,0 +1,9 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --harmony-temporal
// For now, just make sure to call this function at least once in our tests.
// TODO(temporal): Functional tests.
new Date().toTemporalInstant();

View File

@ -0,0 +1,22 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.Duration();
assertDuration(d1.abs(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
let d2 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertDuration(d2.abs(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
// Test large number
let d3 = new Temporal.Duration(
1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5);
assertDuration(d3.abs(),
1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5, 1, false);
// Test negative values
let d4 = new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10);
assertDuration(d4.abs(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);

View File

@ -0,0 +1,50 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.Duration();
let badDur = {add: d1.add};
assertThrows(() => badDur.add(d1), TypeError);
let relativeToOptions = {relativeTo: "2021-08-01"};
let d2 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertThrows(() => d2.add(d1), RangeError);
assertThrows(() => d1.add(d2), RangeError);
assertThrows(() => d2.add(d2), RangeError);
assertDuration(d2.add(d1, relativeToOptions),
1, 2, 0, 25, 5, 6, 7, 8, 9, 10, 1, false);
assertDuration(d1.add(d2, relativeToOptions),
1, 2, 0, 25, 5, 6, 7, 8, 9, 10, 1, false);
assertDuration(d1.add(d1, relativeToOptions),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
assertDuration(d2.add(d2, relativeToOptions),
2, 5, 0, 19, 10, 12, 14, 16, 18, 20, 1, false);
// Test large number
let d3 = new Temporal.Duration(
1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5);
assertThrows(() => d3.add(d3), RangeError);
//assertDuration(d3.add(d3, relativeToOptions),
// 2e5, 4e5, 6e5, 8e5, 1e6, 12e5, 14e5, 16e5, 18e5, 2e6, 1, false);
// Test negative values
let d4 = new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10);
assertThrows(() => d4.add(d1), RangeError);
assertThrows(() => d1.add(d4), RangeError);
assertThrows(() => d4.add(d4), RangeError);
assertThrows(() => d2.add(d4), RangeError);
assertThrows(() => d4.add(d2), RangeError);
assertDuration(d4.add(d1, relativeToOptions),
-1, -2, 0, -25, -5, -6, -7, -8, -9, -10, -1, false);
assertDuration(d1.add(d4, relativeToOptions),
-1, -2, 0, -25, -5, -6, -7, -8, -9, -10, -1, false);
assertDuration(d4.add(d4, relativeToOptions),
-2, -5, 0, -19, -10, -12, -14, -16, -18, -20, -1, false);
assertDuration(d2.add(d4, relativeToOptions),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
assertDuration(d4.add(d2, relativeToOptions),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);

View File

@ -0,0 +1,81 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.Duration();
assertDuration(d1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
let d2 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertDuration(d2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
// Test large number
let d3 = new Temporal.Duration(
1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5);
assertDuration(
d3, 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5, 1, false);
// Test negative values
let d4 = new Temporal.Duration(
-1, -2, -3, -4, -5, -6, -7, -8, -9, -10);
assertDuration(
d4, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1, false);
// Test NaN
let d5 = new Temporal.Duration(NaN, NaN, NaN);
assertDuration(d5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
// 1. If NewTarget is undefined, then
// a. Throw a TypeError exception.
assertThrows(() => Temporal.Duration(), TypeError);
// 1. Let number be ? ToNumber(argument).
assertDuration(new Temporal.Duration(undefined, 234, true, false, "567"),
0, 234, 1, 0, 567, 0, 0, 0, 0, 0, 1, false);
assertThrows(() => new Temporal.Duration(Symbol(123)), TypeError);
assertThrows(() => new Temporal.Duration(123n), TypeError);
// Test Infinity
// 7.5.4 IsValidDuration ( years, months, weeks, days, hours, minutes, seconds,
// milliseconds, microseconds, nanoseconds )
// a. If v is not finite, return false.
assertThrows(() => new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(1, 2, 3, 4, 5, 6, Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(1, 2, 3, 4, 5, Infinity), RangeError);
assertThrows(() => new Temporal.Duration(1, 2, 3, 4, Infinity), RangeError);
assertThrows(() => new Temporal.Duration(1, 2, 3, Infinity), RangeError);
assertThrows(() => new Temporal.Duration(1, 2, Infinity), RangeError);
assertThrows(() => new Temporal.Duration(1, Infinity), RangeError);
assertThrows(() => new Temporal.Duration(Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9,
-Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8,
-Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7,
-Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -4, -5, -6, -Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -4, -5, -Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -4, -Infinity),
RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -3, -Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-1, -2, -Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-1, -Infinity), RangeError);
assertThrows(() => new Temporal.Duration(-Infinity), RangeError);
// Sign different
assertThrows(() => new Temporal.Duration(1, -2), RangeError);
assertThrows(() => new Temporal.Duration(1, 0, -2), RangeError);
assertThrows(() => new Temporal.Duration(-1, 0, 0, 3), RangeError);
assertThrows(() => new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 1, -1),
RangeError);
assertThrows(() => new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -1, 1),
RangeError);

View File

@ -0,0 +1,205 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertDuration(d1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
let d2 = Temporal.Duration.from(d1);
assertDuration(d2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
assertNotSame(d1, d2);
assertDuration(Temporal.Duration.from("PT0S"),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
assertDuration(Temporal.Duration.from("P1Y"),
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P2M"),
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P3W"),
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P4D"),
0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT5H"),
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT6M"),
0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT7S"),
0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT0.008S"),
0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT0.000009S"),
0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 1, false);
assertDuration(Temporal.Duration.from("PT0.000000001S"),
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("P1Y2M3W4DT5H6M7.008009001S"),
1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, false);
assertDuration(Temporal.Duration.from(
"P111111111Y222222222M333333333W444444444D" +
"T555555555H666666666M777777777.987654321S"),
111111111, 222222222, 333333333, 444444444,
555555555, 666666666, 777777777, 987, 654, 321, 1, false);
assertDuration(Temporal.Duration.from("P1Y3WT5H7.000009001S"),
1, 0, 3, 0, 5, 0, 7, 0, 9, 1, 1, false);
assertDuration(Temporal.Duration.from("P2M4DT6M0.008000001S"),
0, 2, 0, 4, 0, 6, 0, 8, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("P1Y4DT7.000000001S"),
1, 0, 0, 4, 0, 0, 7, 0, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("P2MT5H0.008S"),
0, 2, 0, 0, 5, 0, 0, 8, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P3WT6M0.000009S"),
0, 0, 3, 0, 0, 6, 0, 0, 9, 0, 1, false);
assertDuration(Temporal.Duration.from("P1YT5H0.000009000S"),
1, 0, 0, 0, 5, 0, 0, 0, 9, 0, 1, false);
assertDuration(Temporal.Duration.from("P2MT6M0.000000001S"),
0, 2, 0, 0, 0, 6, 0, 0, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("P3WT7S"),
0, 0, 3, 0, 0, 0, 7, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P4DT0.008S"),
0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P1YT5H0.000000001S"),
1, 0, 0, 0, 5, 0, 0, 0, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("P2MT6M"),
0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P3WT7S"),
0, 0, 3, 0, 0, 0, 7, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P4DT0.008S"),
0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT5H0.000009S"),
0, 0, 0, 0, 5, 0, 0, 0, 9, 0, 1, false);
assertDuration(Temporal.Duration.from("P1YT6M"),
1, 0, 0, 0, 0, 6, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P2MT7S"),
0, 2, 0, 0, 0, 0, 7, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P3WT0.008S"),
0, 0, 3, 0, 0, 0, 0, 8, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P4DT0.000009S"),
0, 0, 0, 4, 0, 0, 0, 0, 9, 0, 1, false);
assertDuration(Temporal.Duration.from("PT5H0.000000001S"),
0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("P1YT7S"),
1, 0, 0, 0, 0, 0, 7, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P2MT0.008S"),
0, 2, 0, 0, 0, 0, 0, 8, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("P3WT0.000009S"),
0, 0, 3, 0, 0, 0, 0, 0, 9, 0, 1, false);
assertDuration(Temporal.Duration.from("P4DT0.000000001S"),
0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 1, false);
assertDuration(Temporal.Duration.from("PT5H"),
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("-P1Y2M3W4DT5H6M7.008009001S"),
-1, -2, -3, -4, -5, -6, -7, -8, -9, -1, -1, false);
assertDuration(Temporal.Duration.from(
"-P111111111Y222222222M333333333W444444444D" +
"T555555555H666666666M777777777.987654321S"),
-111111111, -222222222, -333333333, -444444444,
-555555555, -666666666, -777777777, -987, -654, -321, -1, false);
// \\u2212
assertDuration(Temporal.Duration.from("\u2212P1Y2M3W4DT5H6M7.008009001S"),
-1, -2, -3, -4, -5, -6, -7, -8, -9, -1, -1, false);
// positive sign
assertDuration(Temporal.Duration.from("+P1Y2M3W4DT5H6M7.008009001S"),
1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, false);
assertDuration(Temporal.Duration.from("PT2.5H"),
0, 0, 0, 0, 2, 30, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2.25H"),
0, 0, 0, 0, 2, 15, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2.05H"),
0, 0, 0, 0, 2, 03, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2.005H"),
0, 0, 0, 0, 2, 0, 18, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2.505H"),
0, 0, 0, 0, 2, 30, 18, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2.0025H"),
0, 0, 0, 0, 2, 0, 9, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.5M"),
0, 0, 0, 0, 0, 3, 30, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.25M"),
0, 0, 0, 0, 0, 3, 15, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.125M"),
0, 0, 0, 0, 0, 3, 7, 500, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.025M"),
0, 0, 0, 0, 0, 3, 1, 500, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.01M"),
0, 0, 0, 0, 0, 3, 0, 600, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.005M"),
0, 0, 0, 0, 0, 3, 0, 300, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.001M"),
0, 0, 0, 0, 0, 3, 0, 60, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3.006M"),
0, 0, 0, 0, 0, 3, 0, 360, 0, 0, 1, false);
// Use , instead of .
assertDuration(Temporal.Duration.from("PT2,5H"),
0, 0, 0, 0, 2, 30, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2,25H"),
0, 0, 0, 0, 2, 15, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2,05H"),
0, 0, 0, 0, 2, 03, 0, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2,005H"),
0, 0, 0, 0, 2, 0, 18, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2,505H"),
0, 0, 0, 0, 2, 30, 18, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT2,0025H"),
0, 0, 0, 0, 2, 0, 9, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,5M"),
0, 0, 0, 0, 0, 3, 30, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,25M"),
0, 0, 0, 0, 0, 3, 15, 0, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,125M"),
0, 0, 0, 0, 0, 3, 7, 500, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,025M"),
0, 0, 0, 0, 0, 3, 1, 500, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,01M"),
0, 0, 0, 0, 0, 3, 0, 600, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,005M"),
0, 0, 0, 0, 0, 3, 0, 300, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,001M"),
0, 0, 0, 0, 0, 3, 0, 60, 0, 0, 1, false);
assertDuration(Temporal.Duration.from("PT3,006M"),
0, 0, 0, 0, 0, 3, 0, 360, 0, 0, 1, false);
assertThrows(() => Temporal.Duration.from("P2H"), RangeError);
assertThrows(() => Temporal.Duration.from("P2.5M"), RangeError);
assertThrows(() => Temporal.Duration.from("P2,5M"), RangeError);
assertThrows(() => Temporal.Duration.from("P2S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2.H3M"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2,H3M"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2.H3S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2,H3S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2.H0.5M"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2,H0,5M"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2.H0.5S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2,H0,5S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2H3.2M3S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2H3,2M3S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2H3.2M0.3S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT2H3,2M0,3S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT.1H"), RangeError);
assertThrows(() => Temporal.Duration.from("PT,1H"), RangeError);
assertThrows(() => Temporal.Duration.from("PT.1M"), RangeError);
assertThrows(() => Temporal.Duration.from("PT,1M"), RangeError);
assertThrows(() => Temporal.Duration.from("PT.1S"), RangeError);
assertThrows(() => Temporal.Duration.from("PT,1S"), RangeError);
assertDuration(Temporal.Duration.from(
{years: 0, months: 0, weeks: 0, days: 0,
hours: 0, minutes: 0, seconds: 0,
milliseconds: 0, microseconds: 0, nanoseconds:0}),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
assertDuration(Temporal.Duration.from(
{years: 1, months: 2, weeks: 3, days: 4,
hours: 5, minutes: 6, seconds: 7,
milliseconds: 8, microseconds: 9, nanoseconds:10}),
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
assertDuration(Temporal.Duration.from(
{years: -1, months: -2, weeks: -3, days: -4,
hours: -5, minutes: -6, seconds: -7,
milliseconds: -8, microseconds: -9, nanoseconds:-10}),
-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1, false);

View File

@ -0,0 +1,28 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.Duration();
assertDuration(d1.negated(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
let d2 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertDuration(d2.negated(), -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1, false);
// Test large number
let d3 = new Temporal.Duration(
1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5);
assertDuration(d3.negated(),
-1e5, -2e5, -3e5, -4e5, -5e5, -6e5, -7e5, -8e5, -9e5, -10e5, -1, false);
// Test negative values
let d4 = new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10);
assertDuration(d4.negated(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
let d5 = new Temporal.Duration(
-1e5, -2e5, -3e5, -4e5, -5e5, -6e5, -7e5, -8e5, -9e5, -10e5);
assertDuration(d5.negated(),
1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5, 1, false);

View File

@ -0,0 +1,126 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// Test Temporal.Duration toJSON with extreme cases.
//
// Test Number.MAX_VALUE
//
// This is out of the range of Number.MAX_SAFE_INTEGER so the specification
// does not mandate the precision. But we should still check certain property of
// the result.
// Number.MAX_VALUE is 1.7976931348623157e+308 so the first 16 characters should
// be "P179769313486231" which is 15 digits and only require 50 bits so that
// should be precious in 64 bit floating point.
// There are total 309 digits so it should be 179769313486231 with another
// 294 digits (309-15 = 294)
let MAX_UINT32 = Math.pow(2,32);
assertThrows(() => (new Temporal.Duration(MAX_UINT32)), RangeError);
assertThrows(() => (new Temporal.Duration(-MAX_UINT32)), RangeError);
assertThrows(() => (new Temporal.Duration(0, MAX_UINT32)), RangeError);
assertThrows(() => (new Temporal.Duration(0, -MAX_UINT32)), RangeError);
assertThrows(() => (new Temporal.Duration(0, 0, MAX_UINT32)), RangeError);
assertThrows(() => (new Temporal.Duration(0, 0, -MAX_UINT32)), RangeError);
assertThrows(() => (new Temporal.Duration(0, 0, 0, (Number.MAX_SAFE_INTEGER/86400 +1))), RangeError);
assertEquals("P" + Math.floor(Number.MAX_SAFE_INTEGER/86400) +"D",
(new Temporal.Duration(0, 0, 0, Math.floor(Number.MAX_SAFE_INTEGER/86400))).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, -(Number.MAX_SAFE_INTEGER/86400 +1))), RangeError);
assertEquals("-P" + Math.floor(Number.MAX_SAFE_INTEGER/86400) +"D",
(new Temporal.Duration(0, 0, 0, -Math.floor(Number.MAX_SAFE_INTEGER/86400))).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, (Number.MAX_SAFE_INTEGER/3600 +1))), RangeError);
assertEquals("PT" + Math.floor(Number.MAX_SAFE_INTEGER/3600) +"H",
(new Temporal.Duration(0, 0, 0, 0, Math.floor(Number.MAX_SAFE_INTEGER/3600))).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, -(Number.MAX_SAFE_INTEGER/3600 +1))), RangeError);
assertEquals("-PT" + Math.floor(Number.MAX_SAFE_INTEGER/3600) +"H",
(new Temporal.Duration(0, 0, 0, 0, -Math.floor(Number.MAX_SAFE_INTEGER/3600))).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, (Number.MAX_SAFE_INTEGER/60 +1))), RangeError);
assertEquals("PT" + Math.floor(Number.MAX_SAFE_INTEGER/60) +"M",
(new Temporal.Duration(0, 0, 0, 0, 0, Math.floor(Number.MAX_SAFE_INTEGER/60))).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, -(Number.MAX_SAFE_INTEGER/60 +1))), RangeError);
assertEquals("-PT" + Math.floor(Number.MAX_SAFE_INTEGER/60) +"M",
(new Temporal.Duration(0, 0, 0, 0, 0, -Math.floor(Number.MAX_SAFE_INTEGER/60))).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER+1)), RangeError);
assertEquals("PT" + Number.MAX_SAFE_INTEGER +"S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, -(Number.MAX_SAFE_INTEGER+1))), RangeError);
assertEquals("-PT" + Number.MAX_SAFE_INTEGER +"S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER, 1000)), RangeError);
assertEquals("PT" + Number.MAX_SAFE_INTEGER +".999S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER, 999)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER, -1000)), RangeError);
assertEquals("-PT" + Number.MAX_SAFE_INTEGER +".999S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER, -999)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER, 999, 1000)), RangeError);
assertEquals("PT" + Number.MAX_SAFE_INTEGER +".999999S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER, 999, 999)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER, -999, -1000)), RangeError);
assertEquals("-PT" + Number.MAX_SAFE_INTEGER +".999999S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER, -999, -999)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER, 999, 999, 1000)), RangeError);
assertEquals("PT" + Number.MAX_SAFE_INTEGER +".999999999S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, Number.MAX_SAFE_INTEGER, 999, 999, 999)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER, -999, -999, -1000)), RangeError);
assertEquals("-PT" + Number.MAX_SAFE_INTEGER +".999999999S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -Number.MAX_SAFE_INTEGER, -999, -999, -999)).toJSON());
// Put Number.MAX_SAFE_INTEGER in ms
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, // y, m, wk, d, h, m
Number.MAX_SAFE_INTEGER - Math.floor(Number.MAX_SAFE_INTEGER/1e3) + 1, // s
Number.MAX_SAFE_INTEGER, // ms
0, // mic
0 // ns
)), RangeError);
assertEquals("PT" + Number.MAX_SAFE_INTEGER + "." + (Number.MAX_SAFE_INTEGER % 1000) + "S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, // y, m, wk, d, h, m
Number.MAX_SAFE_INTEGER - Math.floor(Number.MAX_SAFE_INTEGER/1e3), // s
Number.MAX_SAFE_INTEGER, // ms
0, // mic
0 // ns
)).toJSON());
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, // y, m, wk, d, h, m
-(Number.MAX_SAFE_INTEGER - Math.floor(Number.MAX_SAFE_INTEGER/1e3) + 1), // s
-Number.MAX_SAFE_INTEGER, // ms
0, // mic
0 // ns
)), RangeError);
assertEquals("-PT" + Number.MAX_SAFE_INTEGER + "." + (Number.MAX_SAFE_INTEGER % 1000) + "S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, // y, m, wk, d, h, m
-(Number.MAX_SAFE_INTEGER - Math.floor(Number.MAX_SAFE_INTEGER/1e3)), // s
-Number.MAX_SAFE_INTEGER, // ms
0, // mic
0 // ns
)).toJSON());
// Put Number.MAX_SAFE_INTEGER in mic
assertThrows(() => (new Temporal.Duration(0, 0, 0, 0, 0, 0, // y, m, wk, d, h, m
Number.MAX_SAFE_INTEGER - Math.floor(Number.MAX_SAFE_INTEGER/1e6) + 1, // s
0, // ms
Number.MAX_SAFE_INTEGER, // mic
0 // ns
)), RangeError);
assertEquals("PT" + Number.MAX_SAFE_INTEGER + "." + (Number.MAX_SAFE_INTEGER % 1000000) + "S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, // y, m, wk, d, h, m
Number.MAX_SAFE_INTEGER - Math.floor(Number.MAX_SAFE_INTEGER/1e6), // s
0, // ms
Number.MAX_SAFE_INTEGER, // mic
0 // ns
)).toJSON());
assertEquals("P" + (MAX_UINT32-1) + "Y", (new Temporal.Duration(MAX_UINT32-1)).toJSON());
assertEquals("-P" + (MAX_UINT32-1) + "Y", (new Temporal.Duration(-(MAX_UINT32-1))).toJSON());
assertEquals("P" + (MAX_UINT32-1) + "M", (new Temporal.Duration(0, MAX_UINT32-1)).toJSON());
assertEquals("-P" + (MAX_UINT32-1) + "M", (new Temporal.Duration(0, -(MAX_UINT32-1))).toJSON());
assertEquals("P" + (MAX_UINT32-1) + "W", (new Temporal.Duration(0, 0, MAX_UINT32-1)).toJSON());
assertEquals("-P" + (MAX_UINT32-1) + "W", (new Temporal.Duration(0, 0, -(MAX_UINT32-1))).toJSON());
assertEquals("P" + (MAX_UINT32-1) + "D", (new Temporal.Duration(0, 0, 0, MAX_UINT32-1)).toJSON());
assertEquals("-P" + (MAX_UINT32-1) + "D", (new Temporal.Duration(0, 0, 0, -(MAX_UINT32-1))).toJSON());
assertEquals("PT" + (MAX_UINT32-1) + "H", (new Temporal.Duration(0, 0, 0, 0, MAX_UINT32-1)).toJSON());
assertEquals("-PT" + (MAX_UINT32-1) + "H", (new Temporal.Duration(0, 0, 0, 0, -(MAX_UINT32-1))).toJSON());
assertEquals("PT" + (MAX_UINT32-1) + "M", (new Temporal.Duration(0, 0, 0, 0, 0, MAX_UINT32-1)).toJSON());
assertEquals("-PT" + (MAX_UINT32-1) + "M", (new Temporal.Duration(0, 0, 0, 0, 0, -(MAX_UINT32-1))).toJSON());
assertEquals("PT" + (MAX_UINT32-1) + "S", (new Temporal.Duration(0, 0, 0, 0, 0, 0, MAX_UINT32-1)).toJSON());
assertEquals("-PT" + (MAX_UINT32-1) + "S", (new Temporal.Duration(0, 0, 0, 0, 0, 0, -(MAX_UINT32-1))).toJSON());

View File

@ -0,0 +1,184 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
assertEquals("PT0S", (new Temporal.Duration()).toJSON());
assertEquals("P1Y", (new Temporal.Duration(1)).toJSON());
assertEquals("-P1Y", (new Temporal.Duration(-1)).toJSON());
assertEquals("P1234567890Y", (new Temporal.Duration(1234567890)).toJSON());
assertEquals("-P1234567890Y", (new Temporal.Duration(-1234567890)).toJSON());
assertEquals("P1Y2M", (new Temporal.Duration(1, 2)).toJSON());
assertEquals("-P1Y2M", (new Temporal.Duration(-1, -2)).toJSON());
assertEquals("P2M", (new Temporal.Duration(0, 2)).toJSON());
assertEquals("-P2M", (new Temporal.Duration(0,-2)).toJSON());
assertEquals("P1234567890M", (new Temporal.Duration(0, 1234567890)).toJSON());
assertEquals("-P1234567890M", (new Temporal.Duration(0,-1234567890)).toJSON());
assertEquals("P1Y2M3W", (new Temporal.Duration(1, 2, 3)).toJSON());
assertEquals("-P1Y2M3W", (new Temporal.Duration(-1, -2, -3)).toJSON());
assertEquals("P3W", (new Temporal.Duration(0, 0, 3)).toJSON());
assertEquals("-P3W", (new Temporal.Duration(0, 0, -3)).toJSON());
assertEquals("P1Y3W", (new Temporal.Duration(1, 0, 3)).toJSON());
assertEquals("-P1Y3W", (new Temporal.Duration(-1, 0, -3)).toJSON());
assertEquals("P2M3W", (new Temporal.Duration(0, 2, 3)).toJSON());
assertEquals("-P2M3W", (new Temporal.Duration(0, -2, -3)).toJSON());
assertEquals("P1234567890W",
(new Temporal.Duration(0, 0, 1234567890)).toJSON());
assertEquals("-P1234567890W",
(new Temporal.Duration(0, 0, -1234567890)).toJSON());
assertEquals("P1Y2M3W4D", (new Temporal.Duration(1, 2, 3, 4)).toJSON());
assertEquals("-P1Y2M3W4D", (new Temporal.Duration(-1, -2, -3, -4)).toJSON());
assertEquals("P1234567890D",
(new Temporal.Duration(0, 0, 0, 1234567890)).toJSON());
assertEquals("-P1234567890D",
(new Temporal.Duration(0, 0, 0, -1234567890)).toJSON());
assertEquals("P4D", (new Temporal.Duration(0, 0, 0, 4)).toJSON());
assertEquals("-P4D", (new Temporal.Duration(0, 0, 0, -4)).toJSON());
assertEquals("P1Y4D", (new Temporal.Duration(1, 0, 0, 4)).toJSON());
assertEquals("-P1Y4D", (new Temporal.Duration(-1, 0, 0, -4)).toJSON());
assertEquals("P2M4D", (new Temporal.Duration(0, 2, 0, 4)).toJSON());
assertEquals("-P2M4D", (new Temporal.Duration(0, -2, 0, -4)).toJSON());
assertEquals("P3W4D", (new Temporal.Duration(0, 0, 3, 4)).toJSON());
assertEquals("-P3W4D", (new Temporal.Duration(0, 0, -3, -4)).toJSON());
assertEquals("PT5H", (new Temporal.Duration(0, 0, 0, 0, 5)).toJSON());
assertEquals("-PT5H", (new Temporal.Duration(0, 0, 0, 0, -5)).toJSON());
assertEquals("P1YT5H", (new Temporal.Duration(1, 0, 0, 0, 5)).toJSON());
assertEquals("-P1YT5H", (new Temporal.Duration(-1, 0, 0, 0, -5)).toJSON());
assertEquals("P2MT5H", (new Temporal.Duration(0, 2, 0, 0, 5)).toJSON());
assertEquals("-P2MT5H", (new Temporal.Duration(0, -2, 0, 0, -5)).toJSON());
assertEquals("PT6M", (new Temporal.Duration(0, 0, 0, 0, 0, 6)).toJSON());
assertEquals("-PT6M", (new Temporal.Duration(0, 0, 0, 0, 0, -6)).toJSON());
assertEquals("PT5H6M", (new Temporal.Duration(0, 0, 0, 0, 5, 6)).toJSON());
assertEquals("-PT5H6M", (new Temporal.Duration(0, 0, 0, 0, -5, -6)).toJSON());
assertEquals("P3WT6M", (new Temporal.Duration(0, 0, 3, 0, 0, 6)).toJSON());
assertEquals("-P3WT6M", (new Temporal.Duration(0, 0, -3, 0, 0, -6)).toJSON());
assertEquals("P4DT6M", (new Temporal.Duration(0, 0, 0, 4, 0, 6)).toJSON());
assertEquals("-P4DT6M", (new Temporal.Duration(0, 0, 0, -4, 0, -6)).toJSON());
assertEquals("PT7S", (new Temporal.Duration(0, 0, 0, 0, 0, 0, 7)).toJSON());
assertEquals("-PT7S", (new Temporal.Duration(0, 0, 0, 0, 0, 0, -7)).toJSON());
assertEquals("PT5H7S", (new Temporal.Duration(0, 0, 0, 0, 5, 0, 7)).toJSON());
assertEquals("-PT5H7S",
(new Temporal.Duration(0, 0, 0, 0, -5, 0, -7)).toJSON());
assertEquals("PT6M7S", (new Temporal.Duration(0, 0, 0, 0, 0, 6, 7)).toJSON());
assertEquals("-PT6M7S",
(new Temporal.Duration(0, 0, 0, 0, 0, -6, -7)).toJSON());
assertEquals("PT5H6M7S", (new Temporal.Duration(0, 0, 0, 0, 5, 6, 7)).toJSON());
assertEquals("-PT5H6M7S",
(new Temporal.Duration(0, 0, 0, 0, -5, -6, -7)).toJSON());
assertEquals("P1YT5H6M7S",
(new Temporal.Duration(1, 0, 0, 0, 5, 6, 7)).toJSON());
assertEquals("-P1YT5H6M7S",
(new Temporal.Duration(-1, 0, 0, 0, -5, -6, -7)).toJSON());
assertEquals("PT0.008S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 8)).toJSON());
assertEquals("-PT0.008S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -8)).toJSON());
assertEquals("PT0.08S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 80)).toJSON());
assertEquals("-PT0.08S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -80)).toJSON());
assertEquals("PT0.087S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 87)).toJSON());
assertEquals("-PT0.087S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -87)).toJSON());
assertEquals("PT0.876S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 876)).toJSON());
assertEquals("-PT0.876S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -876)).toJSON());
assertEquals("PT876.543S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 876543)).toJSON());
assertEquals("-PT876.543S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -876543)).toJSON());
assertEquals("PT0.000009S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 9)).toJSON());
assertEquals("-PT0.000009S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -9)).toJSON());
assertEquals("PT0.00009S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 90)).toJSON());
assertEquals("-PT0.00009S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -90)).toJSON());
assertEquals("PT0.000098S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 98)).toJSON());
assertEquals("-PT0.000098S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -98)).toJSON());
assertEquals("PT0.0009S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 900)).toJSON());
assertEquals("-PT0.0009S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -900)).toJSON());
assertEquals("PT0.000987S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 987)).toJSON());
assertEquals("-PT0.000987S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -987)).toJSON());
assertEquals("PT0.987654S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 987654)).toJSON());
assertEquals("-PT0.987654S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -987654)).toJSON());
assertEquals("PT987.654321S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 987654321)).toJSON());
assertEquals("-PT987.654321S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -987654321)).toJSON());
assertEquals("PT0.000000001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)).toJSON());
assertEquals("-PT0.000000001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -1)).toJSON());
assertEquals("PT0.00000001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 10)).toJSON());
assertEquals("-PT0.00000001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -10)).toJSON());
assertEquals("PT0.000000012S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 12)).toJSON());
assertEquals("-PT0.000000012S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -12)).toJSON());
assertEquals("PT0.0000001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 100)).toJSON());
assertEquals("-PT0.0000001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -100)).toJSON());
assertEquals("PT0.000000123S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 123)).toJSON());
assertEquals("-PT0.000000123S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -123)).toJSON());
assertEquals("PT0.000123456S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 123456)).toJSON());
assertEquals("-PT0.000123456S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -123456)).toJSON());
assertEquals("PT0.123456789S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 123456789)).toJSON());
assertEquals("-PT0.123456789S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -123456789)).toJSON());
assertEquals("PT1.234567891S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 1234567891)).toJSON());
assertEquals("-PT1.234567891S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -1234567891)).toJSON());
assertEquals("PT4.003002001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 4, 3, 2, 1)).toJSON());
assertEquals("-PT4.003002001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -4, -3, -2, -1)).toJSON());
assertEquals("PT4.003092001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 4, 3, 2, 90001)).toJSON());
assertEquals("-PT4.003092001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -4, -3, -2, -90001)).toJSON());
assertEquals("PT4.093082001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, 4, 3, 2, 90080001)).toJSON());
assertEquals("-PT4.093082001S",
(new Temporal.Duration(0, 0, 0, 0, 0, 0, -4, -3, -2, -90080001)).toJSON());
assertEquals("P1Y2M3W4DT5H6M7.008009001S",
(new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 1)).toJSON());
assertEquals("-P1Y2M3W4DT5H6M7.008009001S",
(new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -1)).toJSON());
assertEquals("P1234Y2345M3456W4567DT5678H6789M7890.890901123S",
(new Temporal.Duration(1234, 2345, 3456, 4567, 5678, 6789, 7890,
890, 901, 123)).toJSON());
assertEquals("-P1234Y2345M3456W4567DT5678H6789M7890.890901123S",
(new Temporal.Duration(-1234, -2345, -3456, -4567, -5678, -6789, -7890,
-890, -901, -123)).toJSON());

View File

@ -0,0 +1,7 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.Duration();
assertThrows(() => d1.valueOf(), TypeError);

View File

@ -0,0 +1,82 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let like1 = {years:9, months:8, weeks:7, days:6, hours: 5, minutes: 4,
seconds: 3, milliseconds: 2, microseconds: 1, nanoseconds: 10};
let like2 = {years: 9, hours:5};
let like3 = {months: 8, minutes:4};
let like4 = {weeks: 7, seconds:3};
let like5 = {days: 6, milliseconds:2};
let like6 = {microseconds: 987, nanoseconds: 123};
let like7 = {years:-9, months:-8, weeks:-7, days:-6, hours: -5, minutes: -4,
seconds: -3, milliseconds: -2, microseconds: -1, nanoseconds: -10};
let d1 = new Temporal.Duration();
assertDuration(d1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
assertDuration(d1.with(like1), 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 1, false);
assertDuration(d1.with(like2), 9, 0, 0, 0, 5, 0, 0, 0, 0, 0, 1, false);
assertDuration(d1.with(like3), 0, 8, 0, 0, 0, 4, 0, 0, 0, 0, 1, false);
assertDuration(d1.with(like4), 0, 0, 7, 0, 0, 0, 3, 0, 0, 0, 1, false);
assertDuration(d1.with(like5), 0, 0, 0, 6, 0, 0, 0, 2, 0, 0, 1, false);
assertDuration(d1.with(like6), 0, 0, 0, 0, 0, 0, 0, 0, 987, 123, 1, false);
assertDuration(d1.with(like7), -9, -8, -7, -6, -5, -4, -3, -2, -1, -10, -1,
false);
let d2 = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertDuration(d2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, false);
assertDuration(d2.with(like1), 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 1, false);
assertDuration(d2.with(like7), -9, -8, -7, -6, -5, -4, -3, -2, -1, -10, -1,
false);
// Different sign
assertThrows(() => d2.with({years: -1}), RangeError);
assertThrows(() => d2.with({months: -2}), RangeError);
assertThrows(() => d2.with({weeks: -3}), RangeError);
assertThrows(() => d2.with({days: -4}), RangeError);
assertThrows(() => d2.with({hours: -5}), RangeError);
assertThrows(() => d2.with({minutes: -6}), RangeError);
assertThrows(() => d2.with({seconds: -7}), RangeError);
assertThrows(() => d2.with({milliseconds: -8}), RangeError);
assertThrows(() => d2.with({microseconds: -9}), RangeError);
assertThrows(() => d2.with({nanoseconds: -10}), RangeError);
// Test large number
let d3 = new Temporal.Duration(1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5,
10e5);
assertDuration(d3, 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 10e5, 1,
false);
assertDuration(d3.with(like1), 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 1, false);
assertDuration(d3.with(like7), -9, -8, -7, -6, -5, -4, -3, -2, -1, -10, -1,
false);
// Test negative values
let d4 = new Temporal.Duration(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10);
assertDuration(d4, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1, false);
assertDuration(d4.with(like1), 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 1, false);
// Throw when sign flip
assertThrows(() => d4.with({years: 1}), RangeError);
assertThrows(() => d4.with({months: 2}), RangeError);
assertThrows(() => d4.with({weeks: 3}), RangeError);
assertThrows(() => d4.with({days: 4}), RangeError);
assertThrows(() => d4.with({hours: 5}), RangeError);
assertThrows(() => d4.with({minutes: 6}), RangeError);
assertThrows(() => d4.with({seconds: 7}), RangeError);
assertThrows(() => d4.with({milliseconds: 8}), RangeError);
assertThrows(() => d4.with({microseconds: 9}), RangeError);
assertThrows(() => d4.with({nanoseconds: 10}), RangeError);
// singular throw
assertThrows(() => d1.with({year:1}), TypeError);
assertThrows(() => d1.with({month:1}), TypeError);
assertThrows(() => d1.with({week:1}), TypeError);
assertThrows(() => d1.with({day:1}), TypeError);
assertThrows(() => d1.with({hour:1}), TypeError);
assertThrows(() => d1.with({minute:1}), TypeError);
assertThrows(() => d1.with({second:1}), TypeError);
assertThrows(() => d1.with({millisecond:1}), TypeError);
assertThrows(() => d1.with({microsecond:1}), TypeError);
assertThrows(() => d1.with({nanosecond:1}), TypeError);

View File

@ -0,0 +1,329 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// This file is similar to function-exist but w/o era or eraYear
// The following are generated by
// proposal-temporal/spec$ egrep "<h1>" *.html|egrep ">Temporal\.|>get"|egrep "get|\(" | \
// cut -d'>' -f2|cut -d'<' -f 1 |egrep -v "era" |egrep -v "\. \. \." |sort -u
const funcs = [
"get Temporal.Calendar.prototype.id",
"get Temporal.Duration.prototype.blank",
"get Temporal.Duration.prototype.days",
"get Temporal.Duration.prototype.hours",
"get Temporal.Duration.prototype.microseconds",
"get Temporal.Duration.prototype.milliseconds",
"get Temporal.Duration.prototype.minutes",
"get Temporal.Duration.prototype.months",
"get Temporal.Duration.prototype.nanoseconds",
"get Temporal.Duration.prototype.seconds",
"get Temporal.Duration.prototype.sign",
"get Temporal.Duration.prototype.weeks",
"get Temporal.Duration.prototype.years",
"get Temporal.Instant.prototype.epochMicroseconds",
"get Temporal.Instant.prototype.epochMilliseconds",
"get Temporal.Instant.prototype.epochNanoseconds",
"get Temporal.Instant.prototype.epochSeconds",
"get Temporal.PlainDate.prototype.calendar",
"get Temporal.PlainDate.prototype.day",
"get Temporal.PlainDate.prototype.dayOfWeek",
"get Temporal.PlainDate.prototype.dayOfYear",
"get Temporal.PlainDate.prototype.daysInMonth",
"get Temporal.PlainDate.prototype.daysInWeek",
"get Temporal.PlainDate.prototype.daysInYear",
"get Temporal.PlainDate.prototype.inLeapYear",
"get Temporal.PlainDate.prototype.month",
"get Temporal.PlainDate.prototype.monthCode",
"get Temporal.PlainDate.prototype.monthsInYear",
"get Temporal.PlainDate.prototype.weekOfYear",
"get Temporal.PlainDate.prototype.year",
"get Temporal.PlainDateTime.prototype.calendar",
"get Temporal.PlainDateTime.prototype.day",
"get Temporal.PlainDateTime.prototype.dayOfWeek",
"get Temporal.PlainDateTime.prototype.dayOfYear",
"get Temporal.PlainDateTime.prototype.daysInMonth",
"get Temporal.PlainDateTime.prototype.daysInWeek",
"get Temporal.PlainDateTime.prototype.daysInYear",
"get Temporal.PlainDateTime.prototype.hour",
"get Temporal.PlainDateTime.prototype.inLeapYear",
"get Temporal.PlainDateTime.prototype.microsecond",
"get Temporal.PlainDateTime.prototype.millisecond",
"get Temporal.PlainDateTime.prototype.minute",
"get Temporal.PlainDateTime.prototype.month",
"get Temporal.PlainDateTime.prototype.monthCode",
"get Temporal.PlainDateTime.prototype.monthsInYear",
"get Temporal.PlainDateTime.prototype.nanosecond",
"get Temporal.PlainDateTime.prototype.second",
"get Temporal.PlainDateTime.prototype.weekOfYear",
"get Temporal.PlainDateTime.prototype.year",
"get Temporal.PlainMonthDay.prototype.calendar",
"get Temporal.PlainMonthDay.prototype.day",
"get Temporal.PlainMonthDay.prototype.monthCode",
"get Temporal.PlainTime.prototype.calendar",
"get Temporal.PlainTime.prototype.hour",
"get Temporal.PlainTime.prototype.microsecond",
"get Temporal.PlainTime.prototype.millisecond",
"get Temporal.PlainTime.prototype.minute",
"get Temporal.PlainTime.prototype.nanosecond",
"get Temporal.PlainTime.prototype.second",
"get Temporal.PlainYearMonth.prototype.calendar",
"get Temporal.PlainYearMonth.prototype.daysInMonth",
"get Temporal.PlainYearMonth.prototype.daysInYear",
"get Temporal.PlainYearMonth.prototype.inLeapYear",
"get Temporal.PlainYearMonth.prototype.month",
"get Temporal.PlainYearMonth.prototype.monthCode",
"get Temporal.PlainYearMonth.prototype.monthsInYear",
"get Temporal.PlainYearMonth.prototype.year",
"get Temporal.TimeZone.prototype.id",
"get Temporal.ZonedDateTime.prototype.calendar",
"get Temporal.ZonedDateTime.prototype.day",
"get Temporal.ZonedDateTime.prototype.dayOfWeek",
"get Temporal.ZonedDateTime.prototype.dayOfYear",
"get Temporal.ZonedDateTime.prototype.daysInMonth",
"get Temporal.ZonedDateTime.prototype.daysInWeek",
"get Temporal.ZonedDateTime.prototype.daysInYear",
"get Temporal.ZonedDateTime.prototype.epochMicroseconds",
"get Temporal.ZonedDateTime.prototype.epochMilliseconds",
"get Temporal.ZonedDateTime.prototype.epochNanoseconds",
"get Temporal.ZonedDateTime.prototype.epochSeconds",
"get Temporal.ZonedDateTime.prototype.hour",
"get Temporal.ZonedDateTime.prototype.hoursInDay",
"get Temporal.ZonedDateTime.prototype.inLeapYear",
"get Temporal.ZonedDateTime.prototype.microsecond",
"get Temporal.ZonedDateTime.prototype.millisecond",
"get Temporal.ZonedDateTime.prototype.minute",
"get Temporal.ZonedDateTime.prototype.month",
"get Temporal.ZonedDateTime.prototype.monthCode",
"get Temporal.ZonedDateTime.prototype.monthsInYear",
"get Temporal.ZonedDateTime.prototype.nanosecond",
"get Temporal.ZonedDateTime.prototype.offset",
"get Temporal.ZonedDateTime.prototype.offsetNanoseconds",
"get Temporal.ZonedDateTime.prototype.second",
"get Temporal.ZonedDateTime.prototype.timeZone",
"get Temporal.ZonedDateTime.prototype.weekOfYear",
"get Temporal.ZonedDateTime.prototype.year",
"Temporal.Calendar.from ( _item_ )",
"Temporal.Calendar ( _id_ )",
"Temporal.Calendar.prototype.dateAdd ( _date_, _duration_ [ , _options_ ] )",
"Temporal.Calendar.prototype.dateFromFields ( _fields_ [ , _options_ ] )",
"Temporal.Calendar.prototype.dateUntil ( _one_, _two_ [ , _options_ ] )",
"Temporal.Calendar.prototype.dayOfWeek ( _dateOrDateTime_ )",
"Temporal.Calendar.prototype.dayOfWeek ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.dayOfYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.daysInMonth ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.daysInWeek ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.daysInYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.day ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.fields ( _fields_ )",
"Temporal.Calendar.prototype.inLeapYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.mergeFields ( _fields_, _additionalFields_ )",
"Temporal.Calendar.prototype.monthCode ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.monthDayFromFields ( _fields_ [ , _options_ ] )",
"Temporal.Calendar.prototype.monthsInYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.month ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.toJSON ( )",
"Temporal.Calendar.prototype.toString ( )",
"Temporal.Calendar.prototype.weekOfYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.yearMonthFromFields ( _fields_ [ , _options_ ] )",
"Temporal.Calendar.prototype.year ( _temporalDateLike_ )",
"Temporal.Duration.compare ( _one_, _two_ [ , _options_ ] )",
"Temporal.Duration.from ( _item_ )",
"Temporal.Duration.prototype.abs ( )",
"Temporal.Duration.prototype.add ( _other_ [ , _options_ ] )",
"Temporal.Duration.prototype.negated ( )",
"Temporal.Duration.prototype.round ( _options_ )",
"Temporal.Duration.prototype.subtract ( _other_ [ , _options_ ] )",
"Temporal.Duration.prototype.toJSON ( )",
"Temporal.Duration.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.Duration.prototype.toString ( [ _options_ ] )",
"Temporal.Duration.prototype.total ( _options_ )",
"Temporal.Duration.prototype.valueOf ( )",
"Temporal.Duration.prototype.with ( _temporalDurationLike_ )",
"Temporal.Duration ( [ _years_ [ , _months_ [ , _weeks_ [ , _days_ [ , _hours_ [ , _minutes_ [ , _seconds_ [ , _milliseconds_ [ , _microseconds_ [ , _nanoseconds_ ] ] ] ] ] ] ] ] ] ] )",
"Temporal.Instant.compare ( _one_, _two_ )",
"Temporal.Instant ( _epochNanoseconds_ )",
"Temporal.Instant.fromEpochMicroseconds ( _epochMicroseconds_ )",
"Temporal.Instant.fromEpochMilliseconds ( _epochMilliseconds_ )",
"Temporal.Instant.fromEpochNanoseconds ( _epochNanoseconds_ )",
"Temporal.Instant.fromEpochSeconds ( _epochSeconds_ )",
"Temporal.Instant.from ( _item_ )",
"Temporal.Instant.prototype.add ( _temporalDurationLike_ )",
"Temporal.Instant.prototype.equals ( _other_ )",
"Temporal.Instant.prototype.round ( _options_ )",
"Temporal.Instant.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.Instant.prototype.subtract ( _temporalDurationLike_ )",
"Temporal.Instant.prototype.toJSON ( )",
"Temporal.Instant.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.Instant.prototype.toString ( [ _options_ ] )",
"Temporal.Instant.prototype.toZonedDateTimeISO ( _item_ )",
"Temporal.Instant.prototype.toZonedDateTime ( _item_ )",
"Temporal.Instant.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.Instant.prototype.valueOf ( )",
"Temporal.Now.instant ( )",
"Temporal.Now.plainDate ( _calendar_ [ , _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainDateISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainDateTime ( _calendar_ [ , _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainDateTimeISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainTimeISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.Now.timeZone ( )",
"Temporal.Now.zonedDateTime ( _calendar_ [ , _temporalTimeZoneLike_ ] )",
"Temporal.Now.zonedDateTimeISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.PlainDate.compare ( _one_, _two_ )",
"Temporal.PlainDate.from ( _item_ [ , _options_ ] )",
"Temporal.PlainDate ( _isoYear_, _isoMonth_, _isoDay_ [ , _calendarLike_ ] )",
"Temporal.PlainDate.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.equals ( _other_ )",
"Temporal.PlainDate.prototype.getISOFields ( )",
"Temporal.PlainDate.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.toJSON ( )",
"Temporal.PlainDate.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainDate.prototype.toPlainDateTime ( [ _temporalTime_ ] )",
"Temporal.PlainDate.prototype.toPlainMonthDay ( )",
"Temporal.PlainDate.prototype.toPlainYearMonth ( )",
"Temporal.PlainDate.prototype.toString ( [ _options_ ] )",
"Temporal.PlainDate.prototype.toZonedDateTime ( _item_ )",
"Temporal.PlainDate.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.valueOf ( )",
"Temporal.PlainDate.prototype.withCalendar ( _calendar_ )",
"Temporal.PlainDate.prototype.with ( _temporalDateLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.compare ( _one_, _two_ )",
"Temporal.PlainDateTime.from ( _item_ [ , _options_ ] )",
"Temporal.PlainDateTime ( _isoYear_, _isoMonth_, _isoDay_ [ , _hour_ [ , _minute_ [ , _second_ [ , _millisecond_ [ , _microsecond_ [ , _nanosecond_ [ , _calendarLike_ ] ] ] ] ] ] ] )",
"Temporal.PlainDateTime.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.equals ( _other_ )",
"Temporal.PlainDateTime.prototype.getISOFields ( )",
"Temporal.PlainDateTime.prototype.round ( _options_ )",
"Temporal.PlainDateTime.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.toJSON ( )",
"Temporal.PlainDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainDateTime.prototype.toPlainDate ( )",
"Temporal.PlainDateTime.prototype.toPlainMonthDay ( )",
"Temporal.PlainDateTime.prototype.toPlainTime ( )",
"Temporal.PlainDateTime.prototype.toPlainYearMonth ( )",
"Temporal.PlainDateTime.prototype.toString ( [ _options_ ] )",
"Temporal.PlainDateTime.prototype.toZonedDateTime ( _temporalTimeZoneLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.valueOf ( )",
"Temporal.PlainDateTime.prototype.withCalendar ( _calendar_ )",
"Temporal.PlainDateTime.prototype.withPlainDate ( _plainDateLike_ )",
"Temporal.PlainDateTime.prototype.withPlainTime ( [ _plainTimeLike_ ] )",
"Temporal.PlainDateTime.prototype.with ( _temporalDateTimeLike_ [ , _options_ ] )",
"Temporal.PlainMonthDay.from ( _item_ [ , _options_ ] )",
"Temporal.PlainMonthDay ( _isoMonth_, _isoDay_ [ , _calendarLike_ [ , _referenceISOYear_ ] ] )",
"Temporal.PlainMonthDay.prototype.equals ( _other_ )",
"Temporal.PlainMonthDay.prototype.getISOFields ( )",
"Temporal.PlainMonthDay.prototype.toJSON ( )",
"Temporal.PlainMonthDay.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainMonthDay.prototype.toPlainDate ( _item_ )",
"Temporal.PlainMonthDay.prototype.toString ( [ _options_ ] )",
"Temporal.PlainMonthDay.prototype.valueOf ( )",
"Temporal.PlainMonthDay.prototype.with ( _temporalMonthDayLike_ [ , _options_ ] )",
"Temporal.PlainTime.compare ( _one_, _two_ )",
"Temporal.PlainTime.from ( _item_ [ , _options_ ] )",
"Temporal.PlainTime ( [ _hour_ [ , _minute_ [ , _second_ [ , _millisecond_ [ , _microsecond_ [ , _nanosecond_ ] ] ] ] ] ] )",
"Temporal.PlainTime.prototype.add ( _temporalDurationLike_ )",
"Temporal.PlainTime.prototype.equals ( _other_ )",
"Temporal.PlainTime.prototype.getISOFields ( )",
"Temporal.PlainTime.prototype.round ( _options_ )",
"Temporal.PlainTime.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainTime.prototype.subtract ( _temporalDurationLike_ )",
"Temporal.PlainTime.prototype.toJSON ( )",
"Temporal.PlainTime.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainTime.prototype.toPlainDateTime ( _temporalDate_ )",
"Temporal.PlainTime.prototype.toString ( [ _options_ ] )",
"Temporal.PlainTime.prototype.toZonedDateTime ( _item_ )",
"Temporal.PlainTime.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainTime.prototype.valueOf ( )",
"Temporal.PlainTime.prototype.with ( _temporalTimeLike_ [ , _options_ ] )",
"Temporal.PlainYearMonth.compare ( _one_, _two_ )",
"Temporal.PlainYearMonth.from ( _item_ [ , _options_ ] )",
"Temporal.PlainYearMonth ( _isoYear_, _isoMonth_ [ , _calendarLike_ [ , _referenceISODay_ ] ] )",
"Temporal.PlainYearMonth.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.equals ( _other_ )",
"Temporal.PlainYearMonth.prototype.getISOFields ( )",
"Temporal.PlainYearMonth.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.toJSON ( )",
"Temporal.PlainYearMonth.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainYearMonth.prototype.toPlainDate ( _item_ )",
"Temporal.PlainYearMonth.prototype.toString ( [ _options_ ] )",
"Temporal.PlainYearMonth.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.valueOf ( )",
"Temporal.PlainYearMonth.prototype.with ( _temporalYearMonthLike_ [ , _options_ ] )",
"Temporal.TimeZone.from ( _item_ )",
"Temporal.TimeZone ( _identifier_ )",
"Temporal.TimeZone.prototype.getInstantFor ( _dateTime_ [ , _options_ ] )",
"Temporal.TimeZone.prototype.getNextTransition ( _startingPoint_ )",
"Temporal.TimeZone.prototype.getOffsetNanosecondsFor ( _instant_ )",
"Temporal.TimeZone.prototype.getOffsetStringFor ( _instant_ )",
"Temporal.TimeZone.prototype.getPlainDateTimeFor ( _instant_ [ , _calendarLike_ ] )",
"Temporal.TimeZone.prototype.getPossibleInstantsFor ( _dateTime_ )",
"Temporal.TimeZone.prototype.getPreviousTransition ( _startingPoint_ )",
"Temporal.TimeZone.prototype.toJSON ( )",
"Temporal.TimeZone.prototype.toString ( )",
"Temporal.ZonedDateTime.compare ( _one_, _two_ )",
"Temporal.ZonedDateTime ( _epochNanoseconds_, _timeZoneLike_ [ , _calendarLike_ ] )",
"Temporal.ZonedDateTime.from ( _item_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.equals ( _other_ )",
"Temporal.ZonedDateTime.prototype.getISOFields ( )",
"Temporal.ZonedDateTime.prototype.round ( _options_ )",
"Temporal.ZonedDateTime.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.startOfDay ( )",
"Temporal.ZonedDateTime.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.toInstant ( )",
"Temporal.ZonedDateTime.prototype.toJSON ( )",
"Temporal.ZonedDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.ZonedDateTime.prototype.toPlainDate ( )",
"Temporal.ZonedDateTime.prototype.toPlainDateTime ( )",
"Temporal.ZonedDateTime.prototype.toPlainMonthDay ( )",
"Temporal.ZonedDateTime.prototype.toPlainTime ( )",
"Temporal.ZonedDateTime.prototype.toPlainYearMonth ( )",
"Temporal.ZonedDateTime.prototype.toString ( [ _options_ ] )",
"Temporal.ZonedDateTime.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.valueOf ( )",
"Temporal.ZonedDateTime.prototype.withCalendar ( _calendarLike_ )",
"Temporal.ZonedDateTime.prototype.withPlainDate ( _plainDateLike_ )",
"Temporal.ZonedDateTime.prototype.withPlainTime ( [ _plainTimeLike_ ] )",
"Temporal.ZonedDateTime.prototype.with ( _temporalZonedDateTimeLike_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.withTimeZone ( _timeZoneLike_ )",
];
// Find out the minimum number of arguments of that function
function numberOfArgs(tokens) {
let argc = 0;
for (i = 2; i < tokens.length; i++) {
if (tokens[i] == "[" || tokens[i] == ")") {
return argc;
}
if (tokens[i] != ",") {
argc++;
}
}
}
funcs.forEach(function(line) {
let tokens = line.split(" ");
if (tokens[0] == "get") {
let lastDot = tokens[1].lastIndexOf(".");
let prototype = eval(tokens[1].substring(0, lastDot));
let property = tokens[1].substring(lastDot + 1);
let desc = Object.getOwnPropertyDescriptor(prototype, property);
assertNotEquals(desc, undefined, "Getter should be defined:" + line);
assertEquals(desc.set, undefined, "Setter should NOT be defined:" + line);
} else {
let obj = eval(tokens[0]);
// Verify the method is defined
assertNotEquals(obj, undefined,
"Method should be defined:" + line);
// Verify the number of minimum arguments.
assertEquals(obj.length, numberOfArgs(tokens),
"Method should be defined with " + numberOfArgs(tokens) +
" arguments but got " + obj.length + " arguments:\n" +line);
}
});

View File

@ -0,0 +1,339 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// The following are generated by
// proposal-temporal/spec$ egrep "<h1>" *.html|egrep ">Temporal\.|>get"|egrep "get|\(" | \
// cut -d'>' -f2|cut -d'<' -f 1 |egrep -v "\. \. \." |sort -u
const funcs = [
"get Temporal.Calendar.prototype.id",
"get Temporal.Duration.prototype.blank",
"get Temporal.Duration.prototype.days",
"get Temporal.Duration.prototype.hours",
"get Temporal.Duration.prototype.microseconds",
"get Temporal.Duration.prototype.milliseconds",
"get Temporal.Duration.prototype.minutes",
"get Temporal.Duration.prototype.months",
"get Temporal.Duration.prototype.nanoseconds",
"get Temporal.Duration.prototype.seconds",
"get Temporal.Duration.prototype.sign",
"get Temporal.Duration.prototype.weeks",
"get Temporal.Duration.prototype.years",
"get Temporal.Instant.prototype.epochMicroseconds",
"get Temporal.Instant.prototype.epochMilliseconds",
"get Temporal.Instant.prototype.epochNanoseconds",
"get Temporal.Instant.prototype.epochSeconds",
"get Temporal.PlainDate.prototype.calendar",
"get Temporal.PlainDate.prototype.day",
"get Temporal.PlainDate.prototype.dayOfWeek",
"get Temporal.PlainDate.prototype.dayOfYear",
"get Temporal.PlainDate.prototype.daysInMonth",
"get Temporal.PlainDate.prototype.daysInWeek",
"get Temporal.PlainDate.prototype.daysInYear",
"get Temporal.PlainDate.prototype.era",
"get Temporal.PlainDate.prototype.eraYear",
"get Temporal.PlainDate.prototype.inLeapYear",
"get Temporal.PlainDate.prototype.month",
"get Temporal.PlainDate.prototype.monthCode",
"get Temporal.PlainDate.prototype.monthsInYear",
"get Temporal.PlainDate.prototype.weekOfYear",
"get Temporal.PlainDate.prototype.year",
"get Temporal.PlainDateTime.prototype.calendar",
"get Temporal.PlainDateTime.prototype.day",
"get Temporal.PlainDateTime.prototype.dayOfWeek",
"get Temporal.PlainDateTime.prototype.dayOfYear",
"get Temporal.PlainDateTime.prototype.daysInMonth",
"get Temporal.PlainDateTime.prototype.daysInWeek",
"get Temporal.PlainDateTime.prototype.daysInYear",
"get Temporal.PlainDateTime.prototype.era",
"get Temporal.PlainDateTime.prototype.eraYear",
"get Temporal.PlainDateTime.prototype.hour",
"get Temporal.PlainDateTime.prototype.inLeapYear",
"get Temporal.PlainDateTime.prototype.microsecond",
"get Temporal.PlainDateTime.prototype.millisecond",
"get Temporal.PlainDateTime.prototype.minute",
"get Temporal.PlainDateTime.prototype.month",
"get Temporal.PlainDateTime.prototype.monthCode",
"get Temporal.PlainDateTime.prototype.monthsInYear",
"get Temporal.PlainDateTime.prototype.nanosecond",
"get Temporal.PlainDateTime.prototype.second",
"get Temporal.PlainDateTime.prototype.weekOfYear",
"get Temporal.PlainDateTime.prototype.year",
"get Temporal.PlainMonthDay.prototype.calendar",
"get Temporal.PlainMonthDay.prototype.day",
"get Temporal.PlainMonthDay.prototype.monthCode",
"get Temporal.PlainTime.prototype.calendar",
"get Temporal.PlainTime.prototype.hour",
"get Temporal.PlainTime.prototype.microsecond",
"get Temporal.PlainTime.prototype.millisecond",
"get Temporal.PlainTime.prototype.minute",
"get Temporal.PlainTime.prototype.nanosecond",
"get Temporal.PlainTime.prototype.second",
"get Temporal.PlainYearMonth.prototype.calendar",
"get Temporal.PlainYearMonth.prototype.daysInMonth",
"get Temporal.PlainYearMonth.prototype.daysInYear",
"get Temporal.PlainYearMonth.prototype.era",
"get Temporal.PlainYearMonth.prototype.eraYear",
"get Temporal.PlainYearMonth.prototype.inLeapYear",
"get Temporal.PlainYearMonth.prototype.month",
"get Temporal.PlainYearMonth.prototype.monthCode",
"get Temporal.PlainYearMonth.prototype.monthsInYear",
"get Temporal.PlainYearMonth.prototype.year",
"get Temporal.TimeZone.prototype.id",
"get Temporal.ZonedDateTime.prototype.calendar",
"get Temporal.ZonedDateTime.prototype.day",
"get Temporal.ZonedDateTime.prototype.dayOfWeek",
"get Temporal.ZonedDateTime.prototype.dayOfYear",
"get Temporal.ZonedDateTime.prototype.daysInMonth",
"get Temporal.ZonedDateTime.prototype.daysInWeek",
"get Temporal.ZonedDateTime.prototype.daysInYear",
"get Temporal.ZonedDateTime.prototype.epochMicroseconds",
"get Temporal.ZonedDateTime.prototype.epochMilliseconds",
"get Temporal.ZonedDateTime.prototype.epochNanoseconds",
"get Temporal.ZonedDateTime.prototype.epochSeconds",
"get Temporal.ZonedDateTime.prototype.era",
"get Temporal.ZonedDateTime.prototype.eraYear",
"get Temporal.ZonedDateTime.prototype.hour",
"get Temporal.ZonedDateTime.prototype.hoursInDay",
"get Temporal.ZonedDateTime.prototype.inLeapYear",
"get Temporal.ZonedDateTime.prototype.microsecond",
"get Temporal.ZonedDateTime.prototype.millisecond",
"get Temporal.ZonedDateTime.prototype.minute",
"get Temporal.ZonedDateTime.prototype.month",
"get Temporal.ZonedDateTime.prototype.monthCode",
"get Temporal.ZonedDateTime.prototype.monthsInYear",
"get Temporal.ZonedDateTime.prototype.nanosecond",
"get Temporal.ZonedDateTime.prototype.offset",
"get Temporal.ZonedDateTime.prototype.offsetNanoseconds",
"get Temporal.ZonedDateTime.prototype.second",
"get Temporal.ZonedDateTime.prototype.timeZone",
"get Temporal.ZonedDateTime.prototype.weekOfYear",
"get Temporal.ZonedDateTime.prototype.year",
"Date.prototype.toTemporalInstant ( )",
"Temporal.Calendar.from ( _item_ )",
"Temporal.Calendar ( _id_ )",
"Temporal.Calendar.prototype.dateAdd ( _date_, _duration_ [ , _options_ ] )",
"Temporal.Calendar.prototype.dateFromFields ( _fields_ [ , _options_ ] )",
"Temporal.Calendar.prototype.dateUntil ( _one_, _two_ [ , _options_ ] )",
"Temporal.Calendar.prototype.dayOfWeek ( _dateOrDateTime_ )",
"Temporal.Calendar.prototype.dayOfWeek ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.dayOfYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.daysInMonth ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.daysInWeek ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.daysInYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.day ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.era ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.eraYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.fields ( _fields_ )",
"Temporal.Calendar.prototype.inLeapYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.mergeFields ( _fields_, _additionalFields_ )",
"Temporal.Calendar.prototype.monthCode ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.monthDayFromFields ( _fields_ [ , _options_ ] )",
"Temporal.Calendar.prototype.monthsInYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.month ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.toJSON ( )",
"Temporal.Calendar.prototype.toString ( )",
"Temporal.Calendar.prototype.weekOfYear ( _temporalDateLike_ )",
"Temporal.Calendar.prototype.yearMonthFromFields ( _fields_ [ , _options_ ] )",
"Temporal.Calendar.prototype.year ( _temporalDateLike_ )",
"Temporal.Duration.compare ( _one_, _two_ [ , _options_ ] )",
"Temporal.Duration.from ( _item_ )",
"Temporal.Duration.prototype.abs ( )",
"Temporal.Duration.prototype.add ( _other_ [ , _options_ ] )",
"Temporal.Duration.prototype.negated ( )",
"Temporal.Duration.prototype.round ( _options_ )",
"Temporal.Duration.prototype.subtract ( _other_ [ , _options_ ] )",
"Temporal.Duration.prototype.toJSON ( )",
"Temporal.Duration.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.Duration.prototype.toString ( [ _options_ ] )",
"Temporal.Duration.prototype.total ( _options_ )",
"Temporal.Duration.prototype.valueOf ( )",
"Temporal.Duration.prototype.with ( _temporalDurationLike_ )",
"Temporal.Duration ( [ _years_ [ , _months_ [ , _weeks_ [ , _days_ [ , _hours_ [ , _minutes_ [ , _seconds_ [ , _milliseconds_ [ , _microseconds_ [ , _nanoseconds_ ] ] ] ] ] ] ] ] ] ] )",
"Temporal.Instant.compare ( _one_, _two_ )",
"Temporal.Instant ( _epochNanoseconds_ )",
"Temporal.Instant.fromEpochMicroseconds ( _epochMicroseconds_ )",
"Temporal.Instant.fromEpochMilliseconds ( _epochMilliseconds_ )",
"Temporal.Instant.fromEpochNanoseconds ( _epochNanoseconds_ )",
"Temporal.Instant.fromEpochSeconds ( _epochSeconds_ )",
"Temporal.Instant.from ( _item_ )",
"Temporal.Instant.prototype.add ( _temporalDurationLike_ )",
"Temporal.Instant.prototype.equals ( _other_ )",
"Temporal.Instant.prototype.round ( _options_ )",
"Temporal.Instant.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.Instant.prototype.subtract ( _temporalDurationLike_ )",
"Temporal.Instant.prototype.toJSON ( )",
"Temporal.Instant.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.Instant.prototype.toString ( [ _options_ ] )",
"Temporal.Instant.prototype.toZonedDateTimeISO ( _item_ )",
"Temporal.Instant.prototype.toZonedDateTime ( _item_ )",
"Temporal.Instant.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.Instant.prototype.valueOf ( )",
"Temporal.Now.instant ( )",
"Temporal.Now.plainDate ( _calendar_ [ , _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainDateISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainDateTime ( _calendar_ [ , _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainDateTimeISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.Now.plainTimeISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.Now.timeZone ( )",
"Temporal.Now.zonedDateTime ( _calendar_ [ , _temporalTimeZoneLike_ ] )",
"Temporal.Now.zonedDateTimeISO ( [ _temporalTimeZoneLike_ ] )",
"Temporal.PlainDate.compare ( _one_, _two_ )",
"Temporal.PlainDate.from ( _item_ [ , _options_ ] )",
"Temporal.PlainDate ( _isoYear_, _isoMonth_, _isoDay_ [ , _calendarLike_ ] )",
"Temporal.PlainDate.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.equals ( _other_ )",
"Temporal.PlainDate.prototype.getISOFields ( )",
"Temporal.PlainDate.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.toJSON ( )",
"Temporal.PlainDate.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainDate.prototype.toPlainDateTime ( [ _temporalTime_ ] )",
"Temporal.PlainDate.prototype.toPlainMonthDay ( )",
"Temporal.PlainDate.prototype.toPlainYearMonth ( )",
"Temporal.PlainDate.prototype.toString ( [ _options_ ] )",
"Temporal.PlainDate.prototype.toZonedDateTime ( _item_ )",
"Temporal.PlainDate.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainDate.prototype.valueOf ( )",
"Temporal.PlainDate.prototype.withCalendar ( _calendar_ )",
"Temporal.PlainDate.prototype.with ( _temporalDateLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.compare ( _one_, _two_ )",
"Temporal.PlainDateTime.from ( _item_ [ , _options_ ] )",
"Temporal.PlainDateTime ( _isoYear_, _isoMonth_, _isoDay_ [ , _hour_ [ , _minute_ [ , _second_ [ , _millisecond_ [ , _microsecond_ [ , _nanosecond_ [ , _calendarLike_ ] ] ] ] ] ] ] )",
"Temporal.PlainDateTime.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.equals ( _other_ )",
"Temporal.PlainDateTime.prototype.getISOFields ( )",
"Temporal.PlainDateTime.prototype.round ( _options_ )",
"Temporal.PlainDateTime.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.toJSON ( )",
"Temporal.PlainDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainDateTime.prototype.toPlainDate ( )",
"Temporal.PlainDateTime.prototype.toPlainMonthDay ( )",
"Temporal.PlainDateTime.prototype.toPlainTime ( )",
"Temporal.PlainDateTime.prototype.toPlainYearMonth ( )",
"Temporal.PlainDateTime.prototype.toString ( [ _options_ ] )",
"Temporal.PlainDateTime.prototype.toZonedDateTime ( _temporalTimeZoneLike_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainDateTime.prototype.valueOf ( )",
"Temporal.PlainDateTime.prototype.withCalendar ( _calendar_ )",
"Temporal.PlainDateTime.prototype.withPlainDate ( _plainDateLike_ )",
"Temporal.PlainDateTime.prototype.withPlainTime ( [ _plainTimeLike_ ] )",
"Temporal.PlainDateTime.prototype.with ( _temporalDateTimeLike_ [ , _options_ ] )",
"Temporal.PlainMonthDay.from ( _item_ [ , _options_ ] )",
"Temporal.PlainMonthDay ( _isoMonth_, _isoDay_ [ , _calendarLike_ [ , _referenceISOYear_ ] ] )",
"Temporal.PlainMonthDay.prototype.equals ( _other_ )",
"Temporal.PlainMonthDay.prototype.getISOFields ( )",
"Temporal.PlainMonthDay.prototype.toJSON ( )",
"Temporal.PlainMonthDay.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainMonthDay.prototype.toPlainDate ( _item_ )",
"Temporal.PlainMonthDay.prototype.toString ( [ _options_ ] )",
"Temporal.PlainMonthDay.prototype.valueOf ( )",
"Temporal.PlainMonthDay.prototype.with ( _temporalMonthDayLike_ [ , _options_ ] )",
"Temporal.PlainTime.compare ( _one_, _two_ )",
"Temporal.PlainTime.from ( _item_ [ , _options_ ] )",
"Temporal.PlainTime ( [ _hour_ [ , _minute_ [ , _second_ [ , _millisecond_ [ , _microsecond_ [ , _nanosecond_ ] ] ] ] ] ] )",
"Temporal.PlainTime.prototype.add ( _temporalDurationLike_ )",
"Temporal.PlainTime.prototype.equals ( _other_ )",
"Temporal.PlainTime.prototype.getISOFields ( )",
"Temporal.PlainTime.prototype.round ( _options_ )",
"Temporal.PlainTime.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainTime.prototype.subtract ( _temporalDurationLike_ )",
"Temporal.PlainTime.prototype.toJSON ( )",
"Temporal.PlainTime.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainTime.prototype.toPlainDateTime ( _temporalDate_ )",
"Temporal.PlainTime.prototype.toString ( [ _options_ ] )",
"Temporal.PlainTime.prototype.toZonedDateTime ( _item_ )",
"Temporal.PlainTime.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainTime.prototype.valueOf ( )",
"Temporal.PlainTime.prototype.with ( _temporalTimeLike_ [ , _options_ ] )",
"Temporal.PlainYearMonth.compare ( _one_, _two_ )",
"Temporal.PlainYearMonth.from ( _item_ [ , _options_ ] )",
"Temporal.PlainYearMonth ( _isoYear_, _isoMonth_ [ , _calendarLike_ [ , _referenceISODay_ ] ] )",
"Temporal.PlainYearMonth.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.equals ( _other_ )",
"Temporal.PlainYearMonth.prototype.getISOFields ( )",
"Temporal.PlainYearMonth.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.toJSON ( )",
"Temporal.PlainYearMonth.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.PlainYearMonth.prototype.toPlainDate ( _item_ )",
"Temporal.PlainYearMonth.prototype.toString ( [ _options_ ] )",
"Temporal.PlainYearMonth.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.PlainYearMonth.prototype.valueOf ( )",
"Temporal.PlainYearMonth.prototype.with ( _temporalYearMonthLike_ [ , _options_ ] )",
"Temporal.TimeZone.from ( _item_ )",
"Temporal.TimeZone ( _identifier_ )",
"Temporal.TimeZone.prototype.getInstantFor ( _dateTime_ [ , _options_ ] )",
"Temporal.TimeZone.prototype.getNextTransition ( _startingPoint_ )",
"Temporal.TimeZone.prototype.getOffsetNanosecondsFor ( _instant_ )",
"Temporal.TimeZone.prototype.getOffsetStringFor ( _instant_ )",
"Temporal.TimeZone.prototype.getPlainDateTimeFor ( _instant_ [ , _calendarLike_ ] )",
"Temporal.TimeZone.prototype.getPossibleInstantsFor ( _dateTime_ )",
"Temporal.TimeZone.prototype.getPreviousTransition ( _startingPoint_ )",
"Temporal.TimeZone.prototype.toJSON ( )",
"Temporal.TimeZone.prototype.toString ( )",
"Temporal.ZonedDateTime.compare ( _one_, _two_ )",
"Temporal.ZonedDateTime ( _epochNanoseconds_, _timeZoneLike_ [ , _calendarLike_ ] )",
"Temporal.ZonedDateTime.from ( _item_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.add ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.equals ( _other_ )",
"Temporal.ZonedDateTime.prototype.getISOFields ( )",
"Temporal.ZonedDateTime.prototype.round ( _options_ )",
"Temporal.ZonedDateTime.prototype.since ( _other_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.startOfDay ( )",
"Temporal.ZonedDateTime.prototype.subtract ( _temporalDurationLike_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.toInstant ( )",
"Temporal.ZonedDateTime.prototype.toJSON ( )",
"Temporal.ZonedDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )",
"Temporal.ZonedDateTime.prototype.toPlainDate ( )",
"Temporal.ZonedDateTime.prototype.toPlainDateTime ( )",
"Temporal.ZonedDateTime.prototype.toPlainMonthDay ( )",
"Temporal.ZonedDateTime.prototype.toPlainTime ( )",
"Temporal.ZonedDateTime.prototype.toPlainYearMonth ( )",
"Temporal.ZonedDateTime.prototype.toString ( [ _options_ ] )",
"Temporal.ZonedDateTime.prototype.until ( _other_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.valueOf ( )",
"Temporal.ZonedDateTime.prototype.withCalendar ( _calendarLike_ )",
"Temporal.ZonedDateTime.prototype.withPlainDate ( _plainDateLike_ )",
"Temporal.ZonedDateTime.prototype.withPlainTime ( [ _plainTimeLike_ ] )",
"Temporal.ZonedDateTime.prototype.with ( _temporalZonedDateTimeLike_ [ , _options_ ] )",
"Temporal.ZonedDateTime.prototype.withTimeZone ( _timeZoneLike_ )",
];
// Find out the minimum number of arguments of that function
function numberOfArgs(tokens) {
let argc = 0;
for (i = 2; i < tokens.length; i++) {
if (tokens[i] == "[" || tokens[i] == ")") {
return argc;
}
if (tokens[i] != ",") {
argc++;
}
}
}
funcs.forEach(function(line) {
let tokens = line.split(" ");
if (tokens[0] == "get") {
let lastDot = tokens[1].lastIndexOf(".");
let prototype = eval(tokens[1].substring(0, lastDot));
let property = tokens[1].substring(lastDot + 1);
let desc = Object.getOwnPropertyDescriptor(prototype, property);
assertNotEquals(desc, undefined, "Getter should be defined:" + line);
assertEquals(desc.set, undefined, "Setter should NOT be defined:" + line);
} else {
let obj = eval(tokens[0]);
// Verify the method is defined
assertNotEquals(obj, undefined,
"Method should be defined:" + line);
// Verify the number of minimum arguments.
assertEquals(obj.length, numberOfArgs(tokens),
"Method should be defined with " + numberOfArgs(tokens) +
" arguments but got " + obj.length + " arguments:\n" +line);
}
});

View File

@ -0,0 +1,48 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let i1 = new Temporal.Instant(50000n);
assertEquals(3052001n,
i1.add(new Temporal.Duration(0,0,0,0,0,0,0,3,2,1)).epochNanoseconds);
assertEquals(BigInt(4 * 1e9) + 3052001n,
i1.add(new Temporal.Duration(0,0,0,0,0,0,4,3,2,1)).epochNanoseconds);
assertEquals(BigInt(5 * 60 + 4) * 1000000000n + 3052001n,
i1.add(new Temporal.Duration(0,0,0,0,0,5,4,3,2,1)).epochNanoseconds);
assertEquals(BigInt(6 * 3600 + 5 * 60 + 4) * 1000000000n + 3052001n,
i1.add(new Temporal.Duration(0,0,0,0,6,5,4,3,2,1)).epochNanoseconds);
assertEquals(-2952001n,
i1.add(new Temporal.Duration(0,0,0,0,0,0,0,-3,-2,-1)).epochNanoseconds);
assertEquals(BigInt(-4 * 1e9) - 2952001n,
i1.add(new Temporal.Duration(0,0,0,0,0,0,-4,-3,-2,-1)).epochNanoseconds);
assertEquals(BigInt(5 * 60 + 4) * -1000000000n - 2952001n,
i1.add(new Temporal.Duration(0,0,0,0,0,-5,-4,-3,-2,-1)).epochNanoseconds);
assertEquals(BigInt(6 * 3600 + 5 * 60 + 4) * -1000000000n - 2952001n,
i1.add(new Temporal.Duration(0,0,0,0,-6,-5,-4,-3,-2,-1)).epochNanoseconds);
// Test RequireInternalSlot Throw TypeError
let badInstant = { add: i1.add };
assertThrows(() => badInstant.add(new Temporal.Duration(0, 0, 0, 0, 5)), TypeError);
// Test ToLimitedTemporalDuration Throw RangeError
assertThrows(() => i1.add(new Temporal.Duration(1)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(0, 2)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(0, 0, 3)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(0, 0, 0, 4)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(-1)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(0, -2)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(0, 0, -3)), RangeError);
assertThrows(() => i1.add(new Temporal.Duration(0, 0, 0, -4)), RangeError);
// Test AddInstant Throw RangeError
let i2 = new Temporal.Instant(86400n * 99999999999999999n);
assertThrows(() => i2.add(new Temporal.Duration(0, 0, 0, 0, 999999999)), RangeError);

View File

@ -0,0 +1,21 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let inst1 = new Temporal.Instant(1234567890123456789n);
let inst2 = new Temporal.Instant(1234567890123456000n);
let inst3 = new Temporal.Instant(1234567890123456000n);
assertEquals(Temporal.Instant.compare(inst2, inst3), 0);
assertEquals(Temporal.Instant.compare(inst1, inst2), 1);
assertEquals(Temporal.Instant.compare(inst3, inst1), -1);
assertThrows(() => Temporal.Instant.compare(inst1, "invalid iso8601 string"),
RangeError);
assertThrows(() => Temporal.Instant.compare("invalid iso8601 string", inst1),
RangeError);
// TODO Test Temporal.compare with Temporal.ZonedDateTime object
// TODO Test Temporal.compare with TemporalInstantString

View File

@ -0,0 +1,43 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let inst1 = new Temporal.Instant(1234567890123456789n);
assertEquals(1234567890123456789n , inst1.epochNanoseconds);
assertEquals(1234567890123456n , inst1.epochMicroseconds);
assertEquals(1234567890123 , inst1.epochMilliseconds);
assertEquals(1234567890 , inst1.epochSeconds);
let inst2 = new Temporal.Instant(-1234567890123456789n);
assertEquals(-1234567890123456789n , inst2.epochNanoseconds);
assertEquals(-1234567890123456n , inst2.epochMicroseconds);
assertEquals(-1234567890123 , inst2.epochMilliseconds);
assertEquals(-1234567890 , inst2.epochSeconds);
// 1. If NewTarget is undefined, then
// a. Throw a TypeError exception.
assertThrows(() => Temporal.Instant(1234567890123456789n), TypeError);
// 2. Let epochNanoseconds be ? ToBigInt(epochNanoseconds).
assertThrows(() => {let inst = new Temporal.Instant(undefined)},
TypeError);
assertThrows(() => {let inst = new Temporal.Instant(null)}, TypeError);
assertEquals(1n, (new Temporal.Instant(true)).epochNanoseconds);
assertEquals(0n, (new Temporal.Instant(false)).epochNanoseconds);
assertThrows(() => {let inst = Temporal.Instant(12345)}, TypeError);
assertEquals(1234567890123456789n,
(new Temporal.Instant("1234567890123456789")).epochNanoseconds);
assertThrows(() => {let inst = new Temporal.Instant(Symbol(12345n))},
TypeError);
// 3. If ! IsValidEpochNanoseconds(epochNanoseconds) is false,
// throw a RangeError exception.
assertThrows(() => {let inst = new Temporal.Instant(8640000000000000000001n)},
RangeError);
assertThrows(() => {let inst = new Temporal.Instant(-8640000000000000000001n)},
RangeError);
assertEquals(8640000000000000000000n,
(new Temporal.Instant(8640000000000000000000n)).epochNanoseconds);
assertEquals(-8640000000000000000000n,
(new Temporal.Instant(-8640000000000000000000n)).epochNanoseconds);

View File

@ -0,0 +1,17 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let inst1 = new Temporal.Instant(1234567890123456789n);
let inst2 = new Temporal.Instant(1234567890123456000n);
let inst3 = new Temporal.Instant(1234567890123456000n);
assertEquals(inst1.equals(inst2), false);
assertEquals(inst2.equals(inst3), true);
let badInst = {equals: inst1.equals};
assertThrows(() => badInst.equals(inst1), TypeError);
// TODO Test Temporal.compare with Temporal.ZonedDateTime object
// TODO Test Temporal.compare with TemporalInstantString

View File

@ -0,0 +1,28 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let bigint_nano = 1234567890123456789000n;
let bigint_micro = 1234567890123456789n;
let inst1 = new Temporal.Instant(bigint_nano);
let inst2 = Temporal.Instant.fromEpochMicroseconds(bigint_micro);
assertEquals(inst1, inst2);
let just_fit_neg_bigint = -8640000000000000000n;
let just_fit_pos_bigint = 8640000000000000000n;
let too_big_bigint = 8640000000000000001n;
let too_small_bigint = -8640000000000000001n;
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochMicroseconds(too_small_bigint)},
RangeError);
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochMicroseconds(too_big_bigint)},
RangeError);
assertEquals(just_fit_neg_bigint,
(Temporal.Instant.fromEpochMicroseconds(
just_fit_neg_bigint)).epochMicroseconds);
assertEquals(just_fit_pos_bigint,
(Temporal.Instant.fromEpochMicroseconds(
just_fit_pos_bigint)).epochMicroseconds);

View File

@ -0,0 +1,32 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let bigint_nano = 567890123456789000000n;
let milli = 567890123456789;
let bigint_milli = BigInt(milli);
let inst1 = new Temporal.Instant(bigint_nano);
assertThrows(() =>
Temporal.Instant.fromEpochMilliseconds(bigint_milli),
TypeError);
let inst2 = Temporal.Instant.fromEpochMilliseconds(milli);
assertEquals(inst1, inst2);
let just_fit_neg = -8640000000000000;
let just_fit_pos = 8640000000000000;
let too_big = 8640000000000001;
let too_small = -8640000000000001;
assertThrows(() =>
Temporal.Instant.fromEpochMilliseconds(too_small),
RangeError);
assertThrows(() =>
Temporal.Instant.fromEpochMilliseconds(too_big),
RangeError);
assertEquals(just_fit_neg,
(Temporal.Instant.fromEpochMilliseconds(
just_fit_neg)).epochMilliseconds);
assertEquals(just_fit_pos,
(Temporal.Instant.fromEpochMilliseconds(
just_fit_pos)).epochMilliseconds);

View File

@ -0,0 +1,27 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let bigint1 = 1234567890123456789n;
let inst1 = new Temporal.Instant(bigint1);
let inst2 = Temporal.Instant.fromEpochNanoseconds(bigint1);
assertEquals(inst1, inst2);
let just_fit_neg_bigint = -8640000000000000000000n;
let just_fit_pos_bigint = 8640000000000000000000n;
let too_big_bigint = 8640000000000000000001n;
let too_small_bigint = -8640000000000000000001n;
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochNanoseconds(too_small_bigint)},
RangeError);
assertThrows(() =>
{let inst = Temporal.Instant.fromEpochNanoseconds(too_big_bigint)},
RangeError);
assertEquals(just_fit_neg_bigint,
(Temporal.Instant.fromEpochNanoseconds(
just_fit_neg_bigint)).epochNanoseconds);
assertEquals(just_fit_pos_bigint,
(Temporal.Instant.fromEpochNanoseconds(
just_fit_pos_bigint)).epochNanoseconds);

View File

@ -0,0 +1,30 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let bigint_nano = 7890123456789000000000n;
let sec = 7890123456789;
let bigint_sec = BigInt(sec);
let inst1 = new Temporal.Instant(bigint_nano);
assertThrows(() =>
Temporal.Instant.fromEpochSeconds(bigint_sec),
TypeError)
let inst2 = Temporal.Instant.fromEpochSeconds(sec);
assertEquals(inst1, inst2);
let just_fit_neg = -8640000000000;
let just_fit_pos = 8640000000000;
let too_big = 8640000000001;
let too_small = -8640000000001;
assertThrows(() =>
Temporal.Instant.fromEpochSeconds(too_small),
RangeError)
assertThrows(() =>
Temporal.Instant.fromEpochSeconds(too_big),
RangeError)
assertEquals(just_fit_neg,
(Temporal.Instant.fromEpochSeconds(just_fit_neg)).epochSeconds);
assertEquals(just_fit_pos,
(Temporal.Instant.fromEpochSeconds(just_fit_pos)).epochSeconds);

View File

@ -0,0 +1,54 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let i1 = new Temporal.Instant(50000n);
assertEquals(3052001n,
i1.subtract(new Temporal.Duration(
0,0,0,0,0,0,0,-3,-2,-1)).epochNanoseconds);
assertEquals(BigInt(4 * 1e9) + 3052001n,
i1.subtract(new Temporal.Duration(
0,0,0,0,0,0,-4,-3,-2,-1)).epochNanoseconds);
assertEquals(BigInt(5 * 60 + 4) * 1000000000n + 3052001n,
i1.subtract(new Temporal.Duration(
0,0,0,0,0,-5,-4,-3,-2,-1)).epochNanoseconds);
assertEquals(BigInt(6 * 3600 + 5 * 60 + 4) * 1000000000n + 3052001n,
i1.subtract(new Temporal.Duration(
0,0,0,0,-6,-5,-4,-3,-2,-1)).epochNanoseconds);
assertEquals(-2952001n,
i1.subtract(new Temporal.Duration(0,0,0,0,0,0,0,3,2,1)).epochNanoseconds);
assertEquals(BigInt(-4 * 1e9) - 2952001n,
i1.subtract(new Temporal.Duration(0,0,0,0,0,0,4,3,2,1)).epochNanoseconds);
assertEquals(BigInt(5 * 60 + 4) * -1000000000n - 2952001n,
i1.subtract(new Temporal.Duration(0,0,0,0,0,5,4,3,2,1)).epochNanoseconds);
assertEquals(BigInt(6 * 3600 + 5 * 60 + 4) * -1000000000n - 2952001n,
i1.subtract(new Temporal.Duration(0,0,0,0,6,5,4,3,2,1)).epochNanoseconds);
// Test RequireInternalSlot Throw TypeError
let badInstant = { subtract: i1.subtract };
assertThrows(() => badInstant.subtract(
new Temporal.Duration(0, 0, 0, 0, 5)), TypeError);
// Test ToLimitedTemporalDuration Throw RangeError
assertThrows(() => i1.subtract(new Temporal.Duration(1)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(0, 2)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(0, 0, 3)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(0, 0, 0, 4)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(-1)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(0, -2)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(0, 0, -3)), RangeError);
assertThrows(() => i1.subtract(new Temporal.Duration(0, 0, 0, -4)), RangeError);
// Test AddInstant Throw RangeError
let i2 = new Temporal.Instant(-86400n * 99999999999999999n);
assertThrows(() => i2.subtract(new Temporal.Duration(0, 0, 0, 0, 999999999)),
RangeError);

View File

@ -0,0 +1,45 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
assertEquals("1970-01-01T00:00:00Z",
(Temporal.Instant.fromEpochSeconds(0)).toJSON());
let days_in_sec = 24 * 60 * 60;
assertEquals("1970-12-31T23:59:59Z",
Temporal.Instant.fromEpochSeconds((365 * days_in_sec) - 1).toJSON());
assertEquals("1971-01-01T00:00:00Z",
Temporal.Instant.fromEpochSeconds((365 * days_in_sec)).toJSON());
assertEquals("1971-12-31T23:59:59Z",
Temporal.Instant.fromEpochSeconds((2 *365 * days_in_sec - 1)).toJSON());
assertEquals("1972-01-01T00:00:00Z",
Temporal.Instant.fromEpochSeconds((2 *365 * days_in_sec)).toJSON());
// 1972 is a leap year
assertEquals("1972-02-28T00:00:00Z",
Temporal.Instant.fromEpochSeconds(((2 *365 + 58) * days_in_sec)).toJSON());
assertEquals("1972-02-29T00:00:00Z",
Temporal.Instant.fromEpochSeconds(((2 *365 + 59) * days_in_sec)).toJSON());
assertEquals("1985-01-01T00:00:00Z",
Temporal.Instant.fromEpochSeconds(((15 *365 + 4) * days_in_sec)).toJSON());
// Test with Date
const year_in_sec = 24*60*60*365;
const number_of_random_test = 500;
for (i = 0; i < number_of_random_test ; i++) {
// bertween -5000 years and +5000 years
let ms = Math.floor(Math.random() * year_in_sec * 1000 * 10000) - year_in_sec * 1000 * 5000;
// Temporal auto precision will remove trailing zeros in milliseconds so we only
// compare the first 19 char- to second.
let d = new Date(ms)
dateout = d.toJSON().substr(0,19);
temporalout = Temporal.Instant.fromEpochMilliseconds(ms).toJSON().substr(0, 19);
if (dateout[0] != '0') {
assertEquals(dateout, temporalout, ms);
}
}

View File

@ -0,0 +1,52 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d = new Temporal.Instant(0n);
assertEquals("1970-01-01T00:00:00Z", d.toJSON());
d = new Temporal.Instant(1n);
assertEquals("1970-01-01T00:00:00.000000001Z", d.toJSON());
d = new Temporal.Instant(12n);
assertEquals("1970-01-01T00:00:00.000000012Z", d.toJSON());
d = new Temporal.Instant(123n);
assertEquals("1970-01-01T00:00:00.000000123Z", d.toJSON());
d = new Temporal.Instant(1234n);
assertEquals("1970-01-01T00:00:00.000001234Z", d.toJSON());
d = new Temporal.Instant(12345n);
assertEquals("1970-01-01T00:00:00.000012345Z", d.toJSON());
d = new Temporal.Instant(123456n);
assertEquals("1970-01-01T00:00:00.000123456Z", d.toJSON());
d = new Temporal.Instant(1234567n);
assertEquals("1970-01-01T00:00:00.001234567Z", d.toJSON());
d = new Temporal.Instant(12345678n);
assertEquals("1970-01-01T00:00:00.012345678Z", d.toJSON());
d = new Temporal.Instant(123456789n);
assertEquals("1970-01-01T00:00:00.123456789Z", d.toJSON());
d = new Temporal.Instant(1234567891n);
assertEquals("1970-01-01T00:00:01.234567891Z", d.toJSON());
d = new Temporal.Instant(12345678912n);
assertEquals("1970-01-01T00:00:12.345678912Z", d.toJSON());
d = new Temporal.Instant(-1n);
assertEquals("1969-12-31T23:59:59.999999999Z", d.toJSON());
d = new Temporal.Instant(-12n);
assertEquals("1969-12-31T23:59:59.999999988Z", d.toJSON());
d = new Temporal.Instant(-123n);
assertEquals("1969-12-31T23:59:59.999999877Z", d.toJSON());
d = new Temporal.Instant(-1234n);
assertEquals("1969-12-31T23:59:59.999998766Z", d.toJSON());
d = new Temporal.Instant(-12345n);
assertEquals("1969-12-31T23:59:59.999987655Z", d.toJSON());
d = new Temporal.Instant(-123456n);
assertEquals("1969-12-31T23:59:59.999876544Z", d.toJSON());
d = new Temporal.Instant(-1234567n);
assertEquals("1969-12-31T23:59:59.998765433Z", d.toJSON());
d = new Temporal.Instant(-12345678n);
assertEquals("1969-12-31T23:59:59.987654322Z", d.toJSON());
d = new Temporal.Instant(-123456789n);
assertEquals("1969-12-31T23:59:59.876543211Z", d.toJSON());
d = new Temporal.Instant(-1234567891n);
assertEquals("1969-12-31T23:59:58.765432109Z", d.toJSON());
d = new Temporal.Instant(-12345678912n);
assertEquals("1969-12-31T23:59:47.654321088Z", d.toJSON());

View File

@ -0,0 +1,7 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = Temporal.Now.instant( );
assertThrows(() => d1.valueOf(), TypeError);

View File

@ -0,0 +1,25 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
// Simple add
let d = new Temporal.PlainDate(2021, 7, 20);
assertPlainDate(d.add("P1D"), 2021, 7, 21);
assertPlainDate(d.subtract("-P1D"), 2021, 7, 21);
assertPlainDate(d.add("-P1D"), 2021, 7, 19);
assertPlainDate(d.subtract("P1D"), 2021, 7, 19);
assertPlainDate(d.add("P11D"), 2021, 7, 31);
assertPlainDate(d.subtract("-P11D"), 2021, 7, 31);
assertPlainDate(d.add("P12D"), 2021, 8, 1);
assertPlainDate(d.subtract("-P12D"), 2021, 8, 1);
let goodDate = new Temporal.PlainDate(2021, 7, 20);
let badDate = {add: goodDate.add};
assertThrows(() => badDate.add("P1D"), TypeError);
// Throw in ToLimitedTemporalDuration
assertThrows(() => (new Temporal.PlainDate(2021, 7, 20)).add("bad duration"),
RangeError);

View File

@ -0,0 +1,30 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let t1 = new Temporal.PlainDate(2021, 3, 14);
let t2 = new Temporal.PlainDate(2021, 3, 14);
let t3 = t1;
let t4 = new Temporal.PlainDate(2021, 3, 15);
let t5 = new Temporal.PlainDate(2021, 4, 14);
let t6 = new Temporal.PlainDate(2022, 3, 14);
// years in 4 digits range
assertEquals(0, Temporal.PlainDate.compare(t1, t1));
assertEquals(0, Temporal.PlainDate.compare(t1, t2));
assertEquals(0, Temporal.PlainDate.compare(t1, t3));
assertEquals(0, Temporal.PlainDate.compare(t1, "2021-03-14"));
assertEquals(0, Temporal.PlainDate.compare(t1, "2021-03-14T23:59:59"));
assertEquals(1, Temporal.PlainDate.compare(t4, t1));
assertEquals(1, Temporal.PlainDate.compare(t5, t1));
assertEquals(1, Temporal.PlainDate.compare(t6, t1));
assertEquals(-1, Temporal.PlainDate.compare(t1, t4));
assertEquals(-1, Temporal.PlainDate.compare(t1, t5));
assertEquals(-1, Temporal.PlainDate.compare(t1, t6));
assertEquals(1, Temporal.PlainDate.compare("2021-07-21", t1));
// Test Throw
assertThrows(() => Temporal.PlainDate.compare(t1, "invalid iso8601 string"),
RangeError);
assertThrows(() => Temporal.PlainDate.compare("invalid iso8601 string", t1),
RangeError);

View File

@ -0,0 +1,82 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDate(1911, 10, 10);
assertPlainDate(d1, 1911, 10, 10);
let d2 = new Temporal.PlainDate(2020, 3, 12);
assertPlainDate(d2, 2020, 3, 12);
let d3 = new Temporal.PlainDate(1, 12, 25);
assertPlainDate(d3, 1, 12, 25);
let d4 = new Temporal.PlainDate(1970, 1, 1);
assertPlainDate(d4, 1970, 1, 1);
let d5 = new Temporal.PlainDate(-10, 12, 1);
assertPlainDate(d5, -10, 12, 1);
let d6 = new Temporal.PlainDate(-25406, 1, 1);
assertPlainDate(d6, -25406, 1, 1);
let d7 = new Temporal.PlainDate(26890, 12, 31);
assertPlainDate(d7, 26890, 12, 31);
assertThrows(() => Temporal.PlainDate(2021, 7, 1), TypeError);
assertThrows(() => new Temporal.PlainDate(), RangeError);
assertThrows(() => new Temporal.PlainDate(2021), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 0), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 7), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 13), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 7, 0), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 7, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, -7, 1), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, -7, -1), RangeError);
// Wrong month
assertThrows(() => new Temporal.PlainDate(2021, 0, 1), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 13, 1), RangeError);
// Right day for month
assertPlainDate((new Temporal.PlainDate(2021, 1, 31)), 2021, 1, 31);
assertPlainDate((new Temporal.PlainDate(2021, 2, 28)), 2021, 2, 28);
assertPlainDate((new Temporal.PlainDate(2021, 3, 31)), 2021, 3, 31);
assertPlainDate((new Temporal.PlainDate(2021, 4, 30)), 2021, 4, 30);
assertPlainDate((new Temporal.PlainDate(2021, 5, 31)), 2021, 5, 31);
assertPlainDate((new Temporal.PlainDate(2021, 6, 30)), 2021, 6, 30);
assertPlainDate((new Temporal.PlainDate(2021, 7, 31)), 2021, 7, 31);
assertPlainDate((new Temporal.PlainDate(2021, 8, 31)), 2021, 8, 31);
assertPlainDate((new Temporal.PlainDate(2021, 9, 30)), 2021, 9, 30);
assertPlainDate((new Temporal.PlainDate(2021, 10, 31)), 2021, 10, 31);
assertPlainDate((new Temporal.PlainDate(2021, 11, 30)), 2021, 11, 30);
assertPlainDate((new Temporal.PlainDate(2021, 12, 31)), 2021, 12, 31);
// Check Feb 29 for Leap year
assertThrows(() => new Temporal.PlainDate(1900, 2, 29), RangeError);
assertPlainDate((new Temporal.PlainDate(2000, 2, 29)), 2000, 2, 29);
assertThrows(() => new Temporal.PlainDate(2001, 2, 29), RangeError);
assertThrows(() => new Temporal.PlainDate(2002, 2, 29), RangeError);
assertThrows(() => new Temporal.PlainDate(2003, 2, 29), RangeError);
assertPlainDate((new Temporal.PlainDate(2004, 2, 29)), 2004, 2, 29);
assertThrows(() => new Temporal.PlainDate(2100, 2, 29), RangeError);
// Wrong day for month
assertThrows(() => new Temporal.PlainDate(2021, 1, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 2, 29), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 3, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 4, 31), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 5, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 6, 31), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 7, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 8, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 9, 31), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 10, 32), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 11, 31), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 12, 32), RangeError);
// Infinty
assertThrows(() => new Temporal.PlainDate(Infinity, 12, 1), RangeError);
assertThrows(() => new Temporal.PlainDate(-Infinity, 12, 1), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 12, Infinity), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, 12, -Infinity), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, -Infinity, 1), RangeError);
assertThrows(() => new Temporal.PlainDate(2021, Infinity, 1), RangeError);
// TODO Test calendar
//

View File

@ -0,0 +1,15 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 2, 28);
let d2 = Temporal.PlainDate.from("2021-02-28");
let d3 = Temporal.PlainDate.from("2021-01-28");
assertEquals(d1.equals(d2), true);
assertEquals(d1.equals(d3), false);
assertEquals(d2.equals(d3), false);
let badDate = {equals: d1.equals};
assertThrows(() => badDate.equals(d1), TypeError);

View File

@ -0,0 +1,51 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = Temporal.Now.plainDateISO();
// 1. Set options to ? GetOptionsObject(options).
[true, false, "string is invalid", Symbol(),
123, 456n, Infinity, NaN, null].forEach(function(invalidOptions) {
assertThrows(() => Temporal.PlainDate.from( d1, invalidOptions), TypeError);
});
// a. Perform ? ToTemporalOverflow(options).
assertThrows(() => Temporal.PlainDate.from(
d1, {overflow: "invalid overflow"}), RangeError);
[undefined, {}, {overflow: "constrain"}, {overflow: "reject"}].forEach(
function(validOptions) {
let d = new Temporal.PlainDate(1, 2, 3);
let d2 = Temporal.PlainDate.from(d, validOptions);
assertEquals(1, d2.year);
assertEquals(2, d2.month);
assertEquals(3, d2.day);
assertEquals("iso8601", d2.calendar.id);
});
[undefined, {}, {overflow: "constrain"}, {overflow: "reject"}].forEach(
function(validOptions) {
let d3 = Temporal.PlainDate.from( {year:9, month: 8, day:7}, validOptions);
assertEquals(9, d3.year);
assertEquals(8, d3.month);
assertEquals("M08", d3.monthCode);
assertEquals(7, d3.day);
assertEquals("iso8601", d3.calendar.id);
});
[undefined, {}, {overflow: "constrain"}].forEach(
function(validOptions) {
let d4 = Temporal.PlainDate.from( {year:9, month: 14, day:32}, validOptions);
assertEquals(9, d4.year);
assertEquals(12, d4.month);
assertEquals("M12", d4.monthCode);
assertEquals(31, d4.day);
assertEquals("iso8601", d4.calendar.id);
});
assertThrows(() => Temporal.PlainDate.from(
{year:9, month: 14, day:30}, {overflow: "reject"}), RangeError);
assertThrows(() => Temporal.PlainDate.from(
{year:9, month: 12, day:32}, {overflow: "reject"}), RangeError);

View File

@ -0,0 +1,8 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11, {get id() {return "custom";}});
assertEquals("custom", d1.calendar.id);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{day: function(like) {return 2;}});
assertEquals(2, d1.day);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{dayOfWeek: function(like) {return 2;}});
assertEquals(2, d1.dayOfWeek);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{dayOfYear: function(like) {return 2;}});
assertEquals(2, d1.dayOfYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{daysInMonth: function(like) {return 2;}});
assertEquals(2, d1.daysInMonth);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{daysInWeek: function(like) {return 2;}});
assertEquals(2, d1.daysInWeek);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{daysInYear: function(like) {return 350;}});
assertEquals(350, d1.daysInYear);

View File

@ -0,0 +1,10 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let ret = "foo bar";
let d1 = new Temporal.PlainDate(2021, 12, 11,
{era: function(like) {return ret;}});
assertEquals(ret, d1.era);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{eraYear: function(like) {return 3838;}});
assertEquals(3838, d1.eraYear);

View File

@ -0,0 +1,10 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let ret = "foo bar";
let d1 = new Temporal.PlainDate(2021, 12, 11,
{inLeapYear: function(like) {return ret;}});
assertEquals(ret, d1.inLeapYear);

View File

@ -0,0 +1,21 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDate(1911, 10, 10);
assertPlainDate(d1, 1911, 10, 10);
let d2 = new Temporal.PlainDate(2020, 3, 12);
assertPlainDate(d2, 2020, 3, 12);
let d3 = new Temporal.PlainDate(1, 12, 25);
assertPlainDate(d3, 1, 12, 25);
let d4 = new Temporal.PlainDate(1970, 1, 1);
assertPlainDate(d4, 1970, 1, 1);
let d5 = new Temporal.PlainDate(-10, 12, 1);
assertPlainDate(d5, -10, 12, 1);
let d6 = new Temporal.PlainDate(-25406, 1, 1);
assertPlainDate(d6, -25406, 1, 1);
let d7 = new Temporal.PlainDate(26890, 12, 31);
assertPlainDate(d7, 26890, 12, 31);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{month: function(like) {return 2;}});
assertEquals(2, d1.month);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{monthCode: function(like) {return "M02";}});
assertEquals("M02", d1.monthCode);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{monthsInYear: function(like) {return 14;}});
assertEquals(14, d1.monthsInYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{weekOfYear: function(like) {return 20;}});
assertEquals(20, d1.weekOfYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDate(2021, 12, 11,
{year: function(like) {return 2;}});
assertEquals(2, d1.year);

View File

@ -0,0 +1,68 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
// Simple add
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("PT9H8M7.080090010S"), 2021, 7, 20, 10, 10, 10, 84, 95, 16);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,1,996))
.add("PT0.0000071S"), 2021, 7, 20, 0, 0, 0, 0, 9, 96);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,1,996))
.add("PT0.0071S"), 2021, 7, 20, 0, 0, 0, 9, 96, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,1,996))
.add("PT7.1S"), 2021, 7, 20, 0, 0, 9, 96, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,1,59))
.add("PT5M7S"), 2021, 7, 20, 0, 7, 6, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,59))
.add("PT5H7M"), 2021, 7, 20, 7, 6, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 19))
.add("PT8H"), 2021, 7, 21, 3, 0, 0, 0, 0, 0);
assertPlainDateTime(
(new Temporal.PlainDateTime(2021, 7, 20, 21,52,53,994,995,996))
.add("PT5H13M11.404303202S"), 2021, 7, 21, 3, 6, 5, 399, 299, 198);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,0,995))
.add("PT0.000000006S"), 2021, 7, 20, 0, 0, 0, 0, 1, 1);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,0,995))
.add("PT0.00000006S"), 2021, 7, 20, 0, 0, 0, 0, 1, 55);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,0,995))
.add("PT0.0000006S"), 2021, 7, 20, 0, 0, 0, 0, 1, 595);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT0.000000007S"), 2021, 7, 20, 1, 2, 3, 4, 4, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT0.000005007S"), 2021, 7, 20, 1, 2, 3, 3, 999, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT0.004005007S"), 2021, 7, 20, 1, 2, 2, 999, 999, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT0.005006007S"), 2021, 7, 20, 1, 2, 2, 998, 998, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT4.005006007S"), 2021, 7, 20, 1, 1, 58, 998, 998, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT4S"), 2021, 7, 20, 1, 1, 59, 4, 5, 6);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT5M"), 2021, 7, 20, 0, 57, 3, 4, 5, 6);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT1H5M"), 2021, 7, 19, 23, 57, 3, 4, 5, 6);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.add("-PT1H5M4S"), 2021, 7, 19, 23, 56, 59, 4, 5, 6);
let goodDateTime = new Temporal.PlainDateTime(2021, 7, 20, 1,2,3);
let badDateTime = {add: goodDateTime.add};
assertThrows(() => badDateTime.add("PT30M"), TypeError);
// Throw in ToLimitedTemporalDuration
assertThrows(() => (new Temporal.PlainDateTime(2021, 7, 20, 1,2,3))
.add("bad duration"), RangeError);

View File

@ -0,0 +1,34 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let t1 = new Temporal.PlainDateTime(2021, 3, 14, 1, 2, 3, 4, 5, 6);
let t2 = new Temporal.PlainDateTime(2021, 3, 14, 1, 2, 3, 4, 5, 6);
let t3 = t1;
let t4 = new Temporal.PlainDateTime(2021, 3, 15, 1, 2, 3, 4, 5, 6);
let t5 = new Temporal.PlainDateTime(2021, 4, 14, 1, 2, 3, 4, 5, 6);
let t6 = new Temporal.PlainDateTime(2022, 3, 14, 1, 2, 3, 4, 5, 6);
let t7 = new Temporal.PlainDateTime(2021, 3, 14, 1, 2, 3, 4, 5, 7);
// years in 4 digits range
assertEquals(0, Temporal.PlainDateTime.compare(t1, t1));
assertEquals(0, Temporal.PlainDateTime.compare(t1, t2));
assertEquals(0, Temporal.PlainDateTime.compare(t1, t3));
assertEquals(1, Temporal.PlainDateTime.compare(t1, "2021-03-14T01:02:03"));
assertEquals(1, Temporal.PlainDateTime.compare(t4, t1));
assertEquals(1, Temporal.PlainDateTime.compare(t5, t1));
assertEquals(1, Temporal.PlainDateTime.compare(t6, t1));
assertEquals(1, Temporal.PlainDateTime.compare(t7, t1));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t4));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t5));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t6));
assertEquals(-1, Temporal.PlainDateTime.compare(t1, t7));
assertEquals(1, Temporal.PlainDateTime.compare("2021-07-21", t1));
assertEquals(0, Temporal.PlainDateTime.compare(
t1, "2021-03-14T01:02:03.004005006"));
// Test Throw
assertThrows(() => Temporal.PlainDateTime.compare(t1, "invalid iso8601 string"),
RangeError);
assertThrows(() => Temporal.PlainDateTime.compare("invalid iso8601 string", t1),
RangeError);

View File

@ -0,0 +1,154 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDateTime(1911, 10, 10);
assertPlainDateTime(d1, 1911, 10, 10, 0, 0, 0, 0, 0, 0);
let d2 = new Temporal.PlainDateTime(2020, 3, 12);
assertPlainDateTime(d2, 2020, 3, 12, 0, 0, 0, 0, 0, 0);
let d3 = new Temporal.PlainDateTime(1, 12, 25);
assertPlainDateTime(d3, 1, 12, 25, 0, 0, 0, 0, 0, 0);
let d4 = new Temporal.PlainDateTime(1970, 1, 1);
assertPlainDateTime(d4, 1970, 1, 1, 0, 0, 0, 0, 0, 0);
let d5 = new Temporal.PlainDateTime(-10, 12, 1);
assertPlainDateTime(d5, -10, 12, 1, 0, 0, 0, 0, 0, 0);
let d6 = new Temporal.PlainDateTime(-25406, 1, 1);
assertPlainDateTime(d6, -25406, 1, 1, 0, 0, 0, 0, 0, 0);
let d7 = new Temporal.PlainDateTime(26890, 12, 31);
assertPlainDateTime(d7, 26890, 12, 31, 0, 0, 0, 0, 0, 0);
assertThrows(() => Temporal.PlainDateTime(2021, 7, 1), TypeError);
assertThrows(() => new Temporal.PlainDateTime(), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 0), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 13), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 0), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, -7, 1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, -7, -1), RangeError);
// Wrong month
assertThrows(() => new Temporal.PlainDateTime(2021, 0, 1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 13, 1), RangeError);
// Right day for month
assertPlainDateTime((new Temporal.PlainDateTime(2021, 1, 31)),
2021, 1, 31, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 2, 28)),
2021, 2, 28, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 3, 31)),
2021, 3, 31, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 4, 30)),
2021, 4, 30, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 5, 31)),
2021, 5, 31, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 6, 30)),
2021, 6, 30, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 31)),
2021, 7, 31, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 8, 31)),
2021, 8, 31, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 9, 30)),
2021, 9, 30, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 10, 31)),
2021, 10, 31, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 11, 30)),
2021, 11, 30, 0, 0, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 12, 31)),
2021, 12, 31, 0, 0, 0, 0, 0, 0);
// Check Feb 29 for Leap year
assertThrows(() => new Temporal.PlainDateTime(1900, 2, 29), RangeError);
assertPlainDateTime((new Temporal.PlainDateTime(2000, 2, 29)),
2000, 2, 29, 0, 0, 0, 0, 0, 0);
assertThrows(() => new Temporal.PlainDateTime(2001, 2, 29), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2002, 2, 29), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2003, 2, 29), RangeError);
assertPlainDateTime((new Temporal.PlainDateTime(2004, 2, 29)),
2004, 2, 29, 0, 0, 0, 0, 0, 0);
assertThrows(() => new Temporal.PlainDateTime(2100, 2, 29), RangeError);
// Wrong day for month
assertThrows(() => new Temporal.PlainDateTime(2021, 1, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 2, 29), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 3, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 4, 31), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 5, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 6, 31), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 8, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 9, 31), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 10, 32), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 11, 31), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 12, 32), RangeError);
// Infinity
assertThrows(() => new Temporal.PlainDateTime(Infinity, 12, 1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(-Infinity, 12, 1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 12, Infinity), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 12, -Infinity), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, -Infinity, 1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, Infinity, 1), RangeError);
assertPlainDateTime(new Temporal.PlainDateTime(2021, 7, 9),
2021, 7, 9, 0, 0, 0, 0, 0, 0);
assertPlainDateTime(new Temporal.PlainDateTime(2021, 7, 9, 1, 2, 3, 4, 5, 6),
2021, 7, 9, 1, 2, 3, 4, 5, 6);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 1, 2, 3, 4, 5),
2021, 7, 9, 1, 2, 3, 4, 5, 0);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 1, 2, 3, 4),
2021, 7, 9, 1, 2, 3, 4, 0, 0);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 1, 2, 3),
2021, 7, 9, 1, 2, 3, 0, 0, 0);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 1, 2),
2021, 7, 9, 1, 2, 0, 0, 0, 0);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 1, 0),
2021, 7, 9, 1, 0, 0, 0, 0, 0);
// smallest values
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, 0, 0, 0),
2021, 7, 9, 0, 0, 0, 0, 0, 0);
// largest values
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 23, 59, 59, 999, 999, 999),
2021, 7, 9, 23, 59, 59, 999, 999, 999);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, true, false, NaN, undefined, true),
2021, 7, 9, 1, 0, 0, 0, 1, 0);
assertPlainDateTime(
new Temporal.PlainDateTime(2021, 7, 9, 11.9, 12.8, 13.7, 14.6, 15.5, 1.999999),
2021, 7, 9, 11, 12, 13, 14, 15, 1);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, -Infinity), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, Infinity), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, Symbol(2)), TypeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 3n), TypeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 24), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 60), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 60), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, 1000), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, 0, 1000), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, 0, 0, 1000), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, -1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, -1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, -1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, -1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, 0, -1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(2021, 7, 9, 0, 0, 0, 0, 0, -1), RangeError);

View File

@ -0,0 +1,18 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 2, 28, 11, 12, 13);
let d2 = Temporal.PlainDateTime.from(
{year: 2021, month: 2, day: 28, hour:11, minute:12, second:13});
let d3 = Temporal.PlainDateTime.from(
{year: 2021, month: 2, day: 28, hour:11, minute:12, second:13,
nanosecond:1});
assertEquals(d1.equals(d2), true);
assertEquals(d1.equals(d3), false);
assertEquals(d2.equals(d3), false);
let badDate = {equals: d1.equals};
assertThrows(() => badDate.equals(d1), TypeError);

View File

@ -0,0 +1,101 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = Temporal.Now.plainDateTimeISO();
// 1. Set options to ? GetOptionsObject(options).
[true, false, "string is invalid", Symbol(),
123, 456n, Infinity, NaN, null].forEach(function(invalidOptions) {
assertThrows(() => Temporal.PlainDateTime.from(
d1, invalidOptions), TypeError);
});
// a. Perform ? ToTemporalOverflow(options).
assertThrows(() => Temporal.PlainDateTime.from(
d1, {overflow: "invalid overflow"}), RangeError);
[undefined, {}, {overflow: "constrain"}, {overflow: "reject"}].forEach(
function(validOptions) {
let d = new Temporal.PlainDateTime(1, 2, 3, 4, 5, 6, 7, 8, 9);
let d2 = Temporal.PlainDateTime.from(d, validOptions);
assertEquals(1, d2.year);
assertEquals(2, d2.month);
assertEquals("M02", d2.monthCode);
assertEquals(3, d2.day);
assertEquals(4, d2.hour);
assertEquals(5, d2.minute);
assertEquals(6, d2.second);
assertEquals(7, d2.millisecond);
assertEquals(8, d2.microsecond);
assertEquals(9, d2.nanosecond);
assertEquals("iso8601", d2.calendar.id);
});
[undefined, {}, {overflow: "constrain"}, {overflow: "reject"}].forEach(
function(validOptions) {
let d3 = Temporal.PlainDateTime.from(
{year:9, month: 8, day:7, hour: 6, minute: 5, second: 4,
millisecond: 3, microsecond: 2, nanosecond: 1},
validOptions);
assertEquals(9, d3.year);
assertEquals(8, d3.month);
assertEquals("M08", d3.monthCode);
assertEquals(7, d3.day);
assertEquals(6, d3.hour);
assertEquals(5, d3.minute);
assertEquals(4, d3.second);
assertEquals(3, d3.millisecond);
assertEquals(2, d3.microsecond);
assertEquals(1, d3.nanosecond);
assertEquals("iso8601", d3.calendar.id);
});
[undefined, {}, {overflow: "constrain"}].forEach(
function(validOptions) {
let d4 = Temporal.PlainDateTime.from(
{year:9, month: 14, day:32, hour:24, minute:60, second:60,
millisecond: 1000, microsecond: 1000, nanosecond: 1000},
validOptions);
assertEquals(9, d4.year);
assertEquals(12, d4.month);
assertEquals("M12", d4.monthCode);
assertEquals(31, d4.day);
assertEquals(23, d4.hour);
assertEquals(59, d4.minute);
assertEquals(59, d4.second);
assertEquals(999, d4.millisecond);
assertEquals(999, d4.microsecond);
assertEquals(999, d4.nanosecond);
assertEquals("iso8601", d4.calendar.id);
});
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 14, day:30}, {overflow: "reject"}), RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:32}, {overflow: "reject"}), RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:31, hour: 24}, {overflow: "reject"}), RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:31, minute: 60}, {overflow: "reject"}),
RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:31, second: 60}, {overflow: "reject"}),
RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:31, millisecond: 1000}, {overflow: "reject"}),
RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:31, microsecond: 1000}, {overflow: "reject"}),
RangeError);
assertThrows(() => Temporal.PlainDateTime.from(
{year:9, month: 12, day:31, nanosecond: 1000}, {overflow: "reject"}),
RangeError);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{get id() {return "custom";}});
assertEquals("custom", d1.calendar.id);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{day: function(like) {return 2;}});
assertEquals(2, d1.day);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{dayOfWeek: function(like) {return 2;}});
assertEquals(2, d1.dayOfWeek);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{dayOfYear: function(like) {return 2;}});
assertEquals(2, d1.dayOfYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{daysInMonth: function(like) {return 2;}});
assertEquals(2, d1.daysInMonth);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{daysInWeek: function(like) {return 2;}});
assertEquals(2, d1.daysInWeek);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{daysInYear: function(like) {return 350;}});
assertEquals(350, d1.daysInYear);

View File

@ -0,0 +1,10 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let ret = "foo bar";
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{era: function(like) {return ret;}});
assertEquals(ret, d1.era);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{eraYear: function(like) {return 3838;}});
assertEquals(3838, d1.eraYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{hour: function(like) {return 100;}});
assertEquals(1, d1.hour);

View File

@ -0,0 +1,10 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let ret = "foo bar";
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{inLeapYear: function(like) {return ret;}});
assertEquals(ret, d1.inLeapYear);

View File

@ -0,0 +1,50 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3, 4, 5, 6, 7, 8, 9),
1, 2, 3, 4, 5, 6, 7, 8, 9);
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3, 4, 5, 6, 7, 8),
1, 2, 3, 4, 5, 6, 7, 8, 0);
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3, 4, 5, 6, 7),
1, 2, 3, 4, 5, 6, 7, 0, 0);
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3, 4, 5, 6),
1, 2, 3, 4, 5, 6, 0, 0, 0);
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3, 4, 5),
1, 2, 3, 4, 5, 0, 0, 0, 0);
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3, 4),
1, 2, 3, 4, 0, 0, 0, 0, 0);
assertPlainDateTime(new Temporal.PlainDateTime(1, 2, 3),
1, 2, 3, 0, 0, 0, 0, 0, 0);
assertThrows(() => new Temporal.PlainDateTime(1, 2), RangeError);
assertThrows(() => new Temporal.PlainDateTime(1), RangeError);
assertThrows(() => new Temporal.PlainDateTime(), RangeError);
// smallest values
assertPlainDateTime(new Temporal.PlainDateTime(-25406, 1, 1),
-25406, 1, 1, 0, 0, 0, 0, 0, 0);
// largest values
assertPlainDateTime(
new Temporal.PlainDateTime(29345, 12, 31, 23, 59, 59, 999, 999, 999),
29345, 12, 31, 23, 59, 59, 999, 999, 999);
assertPlainDateTime(
new Temporal.PlainDateTime(false, true, true, NaN, undefined, true),
0, 1, 1, 0, 0, 1, 0, 0, 0, 0);
assertPlainDateTime(
new Temporal.PlainDateTime(11.9, 12.8, 13.7, 14.6, 15.5, 16.6, 17.7, 18.8,
1.999999), 11, 12, 13, 14, 15, 16, 17, 18, 1);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{microsecond: function(like) {return 100;}});
assertEquals(5, d1.microsecond);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{millisecond: function(like) {return 100;}});
assertEquals(4, d1.millisecond);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{minute: function(like) {return 100;}});
assertEquals(2, d1.minute);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{month: function(like) {return 2;}});
assertEquals(2, d1.month);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{monthCode: function(like) {return "M02";}});
assertEquals("M02", d1.monthCode);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{monthsInYear: function(like) {return 14;}});
assertEquals(14, d1.monthsInYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{nanosecond: function(like) {return 100;}});
assertEquals(6, d1.nanosecond);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1, 2, 3, 4, 5, 6,
{second: function(like) {return 100;}});
assertEquals(3, d1.second);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{weekOfYear: function(like) {return 20;}});
assertEquals(20, d1.weekOfYear);

View File

@ -0,0 +1,9 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6,
{year: function(like) {return 2;}});
assertEquals(2, d1.year);

View File

@ -0,0 +1,68 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
// Simple subtract
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("-PT9H8M7.080090010S"), 2021, 7, 20, 10, 10, 10, 84, 95, 16);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,1,996))
.subtract("-PT0.0000071S"), 2021, 7, 20, 0, 0, 0, 0, 9, 96);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,1,996))
.subtract("-PT0.0071S"), 2021, 7, 20, 0, 0, 0, 9, 96, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,1,996))
.subtract("-PT7.1S"), 2021, 7, 20, 0, 0, 9, 96, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,1,59))
.subtract("-PT5M7S"), 2021, 7, 20, 0, 7, 6, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,59))
.subtract("-PT5H7M"), 2021, 7, 20, 7, 6, 0, 0, 0, 0);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 19))
.subtract("-PT8H"), 2021, 7, 21, 3, 0, 0, 0, 0, 0);
assertPlainDateTime(
(new Temporal.PlainDateTime(2021, 7, 20, 21,52,53,994,995,996))
.subtract("-PT5H13M11.404303202S"), 2021, 7, 21, 3, 6, 5, 399, 299, 198);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,0,995))
.subtract("-PT0.000000006S"), 2021, 7, 20, 0, 0, 0, 0, 1, 1);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,0,995))
.subtract("-PT0.00000006S"), 2021, 7, 20, 0, 0, 0, 0, 1, 55);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 0,0,0,0,0,995))
.subtract("-PT0.0000006S"), 2021, 7, 20, 0, 0, 0, 0, 1, 595);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT0.000000007S"), 2021, 7, 20, 1, 2, 3, 4, 4, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT0.000005007S"), 2021, 7, 20, 1, 2, 3, 3, 999, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT0.004005007S"), 2021, 7, 20, 1, 2, 2, 999, 999, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT0.005006007S"), 2021, 7, 20, 1, 2, 2, 998, 998, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT4.005006007S"), 2021, 7, 20, 1, 1, 58, 998, 998, 999);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT4S"), 2021, 7, 20, 1, 1, 59, 4, 5, 6);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT5M"), 2021, 7, 20, 0, 57, 3, 4, 5, 6);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT1H5M"), 2021, 7, 19, 23, 57, 3, 4, 5, 6);
assertPlainDateTime((new Temporal.PlainDateTime(2021, 7, 20, 1,2,3,4,5,6))
.subtract("PT1H5M4S"), 2021, 7, 19, 23, 56, 59, 4, 5, 6);
let goodDateTime = new Temporal.PlainDateTime(2021, 7, 20, 1,2,3);
let badDateTime = {subtract: goodDateTime.subtract};
assertThrows(() => badDateTime.subtract("PT30M"), TypeError);
// Throw in ToLimitedTemporalDuration
assertThrows(() => (new Temporal.PlainDateTime(2021, 7, 20, 1,2,3))
.subtract("bad duration"), RangeError);

View File

@ -0,0 +1,94 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
// years in 4 digits range
assertEquals("2021-07-01T00:00:00",
(new Temporal.PlainDateTime(2021, 7, 1)).toJSON());
assertEquals("9999-12-31T00:00:00",
(new Temporal.PlainDateTime(9999, 12, 31)).toJSON());
assertEquals("1000-01-01T00:00:00",
(new Temporal.PlainDateTime(1000, 1, 1)).toJSON());
// years out of 4 digits range
assertEquals("+010000-01-01T00:00:00",
(new Temporal.PlainDateTime(10000, 1, 1)).toJSON());
assertEquals("+025021-07-01T00:00:00",
(new Temporal.PlainDateTime(25021, 7, 1)).toJSON());
assertEquals("0999-12-31T00:00:00",
(new Temporal.PlainDateTime(999, 12, 31)).toJSON());
assertEquals("0099-08-01T00:00:00",
(new Temporal.PlainDateTime(99, 8, 1)).toJSON());
assertEquals("-000020-09-30T00:00:00",
(new Temporal.PlainDateTime(-20, 9, 30)).toJSON());
assertEquals("-002021-07-01T00:00:00",
(new Temporal.PlainDateTime(-2021, 7, 1)).toJSON());
assertEquals("-022021-07-01T00:00:00",
(new Temporal.PlainDateTime(-22021, 7, 1)).toJSON());
// with time
assertEquals("2021-07-01T02:03:04",
(new Temporal.PlainDateTime(2021, 7, 1, 2, 3, 4)).toJSON());
assertEquals("2021-07-01T00:03:04",
(new Temporal.PlainDateTime(2021, 7, 1, 0, 3, 4)).toJSON());
assertEquals("2021-07-01T00:00:04",
(new Temporal.PlainDateTime(2021, 7, 1, 0, 0, 4)).toJSON());
assertEquals("2021-07-01T00:00:00",
(new Temporal.PlainDateTime(2021, 7, 1, 0, 0, 0)).toJSON());
assertEquals("2021-07-01T02:00:00",
(new Temporal.PlainDateTime(2021, 7, 1, 2, 0, 0)).toJSON());
assertEquals("2021-07-01T02:03:00",
(new Temporal.PlainDateTime(2021, 7, 1, 2, 3, 0)).toJSON());
assertEquals("2021-07-01T23:59:59",
(new Temporal.PlainDateTime(2021, 7, 1, 23, 59, 59)).toJSON());
assertEquals("2021-07-01T00:59:59",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59)).toJSON());
assertEquals("2021-07-01T00:59:59.000000001",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 0, 1)).toJSON());
assertEquals("2021-07-01T00:59:59.000008009",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 8, 9)).toJSON());
assertEquals("2021-07-01T00:59:59.007008009",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 7, 8, 9)).toJSON());
assertEquals("2021-07-01T00:59:59.00000009",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 0, 90)).toJSON());
assertEquals("2021-07-01T00:59:59.0000009",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 0, 900)).toJSON());
assertEquals("2021-07-01T00:59:59.000008",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 8)).toJSON());
assertEquals("2021-07-01T00:59:59.000008",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 8, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.00008",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 80)).toJSON());
assertEquals("2021-07-01T00:59:59.00008",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 80, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.0008",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 800)).toJSON());
assertEquals("2021-07-01T00:59:59.0008",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 800, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.007",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 7, 0, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.007",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 7, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.007",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 7)).toJSON());
assertEquals("2021-07-01T00:59:59.07",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 70, 0, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.07",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 70, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.07",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 70)).toJSON());
assertEquals("2021-07-01T00:59:59.7",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 700, 0, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.7",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 700, 0)).toJSON());
assertEquals("2021-07-01T00:59:59.7",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 700)).toJSON());
assertEquals("2021-07-01T00:59:59.000876",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 876)).toJSON());
assertEquals("2021-07-01T00:59:59.876",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 876)).toJSON());
assertEquals("2021-07-01T00:59:59.000000876",
(new Temporal.PlainDateTime(2021, 7, 1, 00, 59, 59, 0, 0, 876)).toJSON());

View File

@ -0,0 +1,12 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6);
let badDateTime = { toPlainDate: d1.toPlainDate }
assertThrows(() => badDateTime.toPlainDate(), TypeError);
assertPlainDate(d1.toPlainDate(), 2021, 12, 11);

View File

@ -0,0 +1,12 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6);
let badDateTime = { toPlainMonthDay: d1.toPlainMonthDay }
assertThrows(() => badDateTime.toPlainMonthDay(), TypeError);
assertPlainMonthDay(d1.toPlainMonthDay(), "M12", 11);

View File

@ -0,0 +1,12 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6);
let badDateTime = { toPlainTime: d1.toPlainTime }
assertThrows(() => badDateTime.toPlainTime(), TypeError);
assertPlainTime(d1.toPlainTime(), 1, 2, 3, 4, 5, 6);

View File

@ -0,0 +1,12 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDateTime(2021, 12, 11, 1,2,3,4,5,6);
let badDateTime = { toPlainYearMonth: d1.toPlainYearMonth }
assertThrows(() => badDateTime.toPlainYearMonth(), TypeError);
assertPlainYearMonth(d1.toPlainYearMonth(), 2021, 12);

View File

@ -0,0 +1,7 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-temporal
let d1 = Temporal.Now.plainDateTimeISO();
assertThrows(() => d1.valueOf(), TypeError);

Some files were not shown because too many files have changed in this diff Show More