Commit dfa3dfa3 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add some tests for Temporal.Calendar

All marked as FAIL at this stage.

Bug: v8:11544
Change-Id: I6e4346a57aa3df054d2ef5bd353544fba7fd855b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3044350
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76211}
parent 7817cf1f
......@@ -40,6 +40,11 @@
# All tests in the bug directory are expected to fail.
'bugs/*': [FAIL],
##############################################################################
# Temporal tests to be implemented
# https://crbug.com/v8/11544
'temporal/*': [FAIL],
##############################################################################
# Open bugs.
......
// 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,
"Constructor Temporal.Calendar requires 'new'");
assertThrows(() => new Temporal.Calendar(), RangeError,
"Invalid calendar specified: undefined");
// Wrong case
assertThrows(() => new Temporal.Calendar("ISO8601"), RangeError,
"Invalid calendar specified: ISO8601");
assertEquals("iso8601", (new Temporal.Calendar("iso8601")).id)
// 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());
This diff is collapsed.
This diff is collapsed.
// 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}));
// 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}));
// 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}));
// 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}));
// 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}));
// 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}));
// 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)
const fields = {
*[Symbol.iterator]() {
let i = 0;
while (i++ < 1000) {
yield "year";
}
}
}
let expected = Array.from(fields);
// For now, we only input it as array
let inpiut = expected;
assertArrayEquals(expected, cal.fields(expected));
// 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.
//assertThrows(() => Temporal.Calendar.from("invalid"), TypeError,
// "Constructor Temporal.Calendar requires 'new'");
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);
// 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}));
// 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,
"Cannot convert undefined or null to object");
assertThrows(() => cal.mergeFields(undefined, {}), TypeError,
"Cannot convert undefined or null to object");
assertThrows(() => cal.mergeFields(null, {}), TypeError,
"Cannot convert undefined or null to object");
assertThrows(() => cal.mergeFields({}, undefined), TypeError,
"Cannot convert undefined or null to object");
assertThrows(() => cal.mergeFields({}, null), TypeError,
"Cannot convert undefined or null to object");
// 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}));
// 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}));
This diff is collapsed.
// 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,
"invalid_argument");
// 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}));
// 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}));
// 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}));
// 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")
let nonObjMsg =
"Temporal.Calendar.prototype.yearMonthFromFields called on non-object");
// Check throw for first arg
assertThrows(() => cal.yearMonthFromFields(),
TypeError, nonObjMsg);
[undefined, true, false, 123, 456n, Symbol(), "string"].forEach(
function(fields) {
assertThrows(() => cal.yearMonthFromFields(fields), TypeError, nonObjMsg);
assertThrows(() => cal.yearMonthFromFields(fields, undefined),
TypeError, nonObjMsg);
assertThrows(() => cal.yearMonthFromFields(fields,
{overflow: "constrain"}), TypeError, nonObjMsg);
assertThrows(() => cal.yearMonthFromFields(fields,
{overflow: "reject"}), TypeError, nonObjMsg);
});
assertThrows(() => cal.yearMonthFromFields({month: 1}),
TypeError, "invalid_argument");
assertThrows(() => cal.yearMonthFromFields({year: 2021}),
TypeError, "invalid_argument");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "m1"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M1"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "m01"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: 12,
monthCode: "M11"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M00"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M19"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M99"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, monthCode: "M13"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: -1}),
RangeError, "Invalid time value");
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: -Infinity}),
RangeError, "Invalid time value");
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: 0, day: 5},
{overflow: "reject"}), RangeError, "Invalid time value");
assertThrows(() => cal.yearMonthFromFields({year: 2021, month: 13, day: 5},
{overflow: "reject"}), RangeError, "Invalid time value");
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, monthCode: "M00"}, {overflow: "reject"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, monthCode: "M13"}, {overflow: "reject"}),
RangeError, "monthCode value is out of range.");
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 0}), RangeError, "Invalid time value");
// Check throw for the second arg
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 7}, {overflow: "invalid"}),
RangeError,
"Value invalid out of range for " +
"Temporal.Calendar.prototype.yearMonthFromFields options property " +
"overflow");
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,
"Invalid time value");
assertThrows(() => cal.yearMonthFromFields(
{year: 2021, month: 9995}, {overflow: "reject"}), RangeError,
"Invalid time value");
// 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}));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment