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

[Temporal] Add some tests for PlainDateTime

Land some of the tests for Temporal.PlainDateTime
All marked as FAIL at this stage.

Bug: v8:11544
Change-Id: I09bf681e61f19d96607c848ddcb6bee06580aff1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3085625
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77332}
parent 85e287c9
// 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);
// 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);
// 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);
// 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);
// 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
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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);
// 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("+000999-12-31T00:00:00",
(new Temporal.PlainDateTime(999, 12, 31)).toJSON());
assertEquals("+000099-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());
// 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);
// 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);
// 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);
// 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);
// 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);
// 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, 4, 5, 6, 7, 8, 9);
let badDateTime = { withCalendar: d1.withCalendar }
assertThrows(() => badDateTime.withCalendar("iso8601"), TypeError);
// A simplified version of Republic of China calendar
let rocCal = {
iso8601: new Temporal.Calendar("iso8601"),
get id() {return "roc";},
dateFromFields: function(fields, options) {
fields.year -= 1911;
return this.iso8601.dateFromFields(fields, options);
},
year: function(date) { return this.iso8601.year(date) - 1911; },
month: function(date) { return this.iso8601.month(date); },
monthCode: function(date) { return this.iso8601.monthCode(date); },
day: function(date) { return this.iso8601.day(date); },
};
let d2 = d1.withCalendar(rocCal);
assertEquals(d2.calendar.id, "roc");
assertPlainDateTime(d2, 0, 10, 10, 4, 5, 6, 7, 8, 9);
let d3 = d2.withCalendar("iso8601");
assertEquals(d3.calendar.id, "iso8601");
assertPlainDateTime(d3, 1911, 10, 10, 4, 5, 6, 7, 8, 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
d8.file.execute('test/mjsunit/temporal/temporal-helpers.js');
let d1 = new Temporal.PlainDateTime(1911, 10, 10, 4, 5, 6, 7, 8, 9);
let badDate = { withPlainDate: d1.withPlainDate }
assertThrows(() => badDate.withPlainDate("2021-03-11"), TypeError);
assertPlainDateTime(d1.withPlainDate("2021-07-12"),
2021, 7, 12, 4, 5, 6, 7, 8, 9);
// A simplified version of Republic of China calendar
let rocCal = {
iso8601: new Temporal.Calendar("iso8601"),
get id() {return "roc";},
dateFromFields: function(fields, options) {
fields.year -= 1911;
return this.iso8601.dateFromFields(fields, options);
},
year: function(date) { return this.iso8601.year(date) - 1911; },
month: function(date) { return this.iso8601.month(date); },
monthCode: function(date) { return this.iso8601.monthCode(date); },
day: function(date) { return this.iso8601.day(date); },
};
let d3 = new Temporal.PlainDateTime(2020, 3, 15, 4, 5, 6, 7, 8, 9, rocCal);
assertPlainDateTime(d3.withPlainDate("2021-07-12"), 110, 7, 12, 4, 5, 6, 7, 8, 9);
assertThrows(() => d1.withPlainDate(undefined), RangeError);
assertThrows(() => d1.withPlainDate(null), RangeError);
assertThrows(() => d1.withPlainDate(true), RangeError);
assertThrows(() => d1.withPlainDate(false), RangeError);
assertThrows(() => d1.withPlainDate(Infinity), RangeError);
assertThrows(() => d1.withPlainDate(123), RangeError);
assertThrows(() => d1.withPlainDate(456n), RangeError);
assertThrows(() => d1.withPlainDate("invalid iso8601 string"), RangeError);
// 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, 4, 5, 6, 7, 8, 9);
let badDate = { withPlainTime: d1.withPlainTime }
assertThrows(() => badDate.withPlainTime(), TypeError);
let timeRecord = {
hour: 9, minute: 8, second: 7,
millisecond: 6, microsecond: 5, nanosecond: 4
};
assertPlainDateTime(d1.withPlainTime(timeRecord), 1911, 10, 10, 9, 8, 7, 6, 5, 4);
// A simplified version of Republic of China calendar
let rocCal = {
iso8601: new Temporal.Calendar("iso8601"),
get id() {return "roc";},
dateFromFields: function(fields, options) {
fields.year -= 1911;
return this.iso8601.dateFromFields(fields, options);
},
year: function(date) { return this.iso8601.year(date) - 1911; },
month: function(date) { return this.iso8601.month(date); },
monthCode: function(date) { return this.iso8601.monthCode(date); },
day: function(date) { return this.iso8601.day(date); },
};
let d3 = new Temporal.PlainDateTime(2020, 3, 15, 4, 5, 6, 7, 8, 9, rocCal);
assertPlainDateTime(d3.withPlainTime(timeRecord), 109, 3, 15, 9, 8, 7, 6, 5, 4);
assertThrows(() => d1.withPlainTime(null), RangeError);
assertThrows(() => d1.withPlainTime(true), RangeError);
assertThrows(() => d1.withPlainTime(false), RangeError);
assertThrows(() => d1.withPlainTime(Infinity), RangeError);
assertThrows(() => d1.withPlainTime("invalid iso8601 string"), RangeError);
assertThrows(() => d1.withPlainTime(123), RangeError);
assertThrows(() => d1.withPlainTime(456n), RangeError);
// 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, 11, 10, 4, 5, 6, 7, 8, 9);
let badDate = { with: d1.with }
assertThrows(() => badDate.with(), TypeError);
assertThrows(() => d1.with(null), TypeError);
assertThrows(() => d1.with(undefined), TypeError);
assertThrows(() => d1.with("string is invalid"), TypeError);
assertThrows(() => d1.with(true), TypeError);
assertThrows(() => d1.with(false), TypeError);
assertThrows(() => d1.with(NaN), TypeError);
assertThrows(() => d1.with(Infinity), TypeError);
assertThrows(() => d1.with(123), TypeError);
assertThrows(() => d1.with(456n), TypeError);
assertThrows(() => d1.with(Symbol()), TypeError);
let date = Temporal.Now.plainDateISO();
assertThrows(() => d1.with(date), TypeError);
let dateTime = Temporal.Now.plainDateTimeISO();
assertThrows(() => d1.with(dateTime), TypeError);
let time = Temporal.Now.plainTimeISO();
assertThrows(() => d1.with(time), TypeError);
let ym = new Temporal.PlainYearMonth(2021, 7);
assertThrows(() => d1.with(ym), TypeError);
let md = new Temporal.PlainMonthDay(12, 25);
assertThrows(() => d1.with(md), TypeError);
assertThrows(() => d1.with({calendar: "iso8601"}), TypeError);
assertThrows(() => d1.with({timeZone: "UTC"}), TypeError);
// options is not undefined or object
assertThrows(() => d1.with({day: 3}, null), TypeError);
assertThrows(() => d1.with({day: 3}, "string is invalid"), TypeError);
assertThrows(() => d1.with({day: 3}, true), TypeError);
assertThrows(() => d1.with({day: 3}, false), TypeError);
assertThrows(() => d1.with({day: 3}, 123), TypeError);
assertThrows(() => d1.with({day: 3}, 456n), TypeError);
assertThrows(() => d1.with({day: 3}, Symbol()), TypeError);
assertThrows(() => d1.with({day: 3}, NaN), TypeError);
assertThrows(() => d1.with({day: 3}, Infinity), TypeError);
assertPlainDateTime(d1.with({year: 2021}), 2021, 11, 10, 4, 5, 6, 7, 8, 9);
assertPlainDateTime(d1.with({month: 3}), 1911, 3, 10, 4, 5, 6, 7, 8, 9);
assertPlainDateTime(d1.with({monthCode: "M05"}), 1911, 5, 10, 4, 5, 6, 7, 8, 9);
assertPlainDateTime(d1.with({day: 1}), 1911, 11, 1, 4, 5, 6, 7, 8, 9);
assertPlainDateTime(d1.with({hour: 2}), 1911, 11, 10, 2, 5, 6, 7, 8, 9);
assertPlainDateTime(d1.with({minute: 3}), 1911, 11, 10, 4, 3, 6, 7, 8, 9);
assertPlainDateTime(d1.with({second: 4}), 1911, 11, 10, 4, 5, 4, 7, 8, 9);
assertPlainDateTime(d1.with({millisecond: 5}), 1911, 11, 10, 4, 5, 6, 5, 8, 9);
assertPlainDateTime(d1.with({microsecond: 6}), 1911, 11, 10, 4, 5, 6, 7, 6, 9);
assertPlainDateTime(d1.with({nanosecond: 7}), 1911, 11, 10, 4, 5, 6, 7, 8, 7);
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