v8/test/mjsunit/temporal/plain-date-to-plain-date-time.js
Frank Tang 6fd503608a [Temporal] Fix test to sync with latest spec after spec change.
1. fix year value between 100 and 9999 should use 4 digit padding without '+' prefix to sync with the latest spec in
mjsunit/temporal/plain-date-time-to-json

2. Change the the toPlainDateTime to accept object with partial time fields to sync with current spect in
test/mjsunit/temporal/plain-date-to-plain-date-time.js

3. Change the test to accept input parameter type to Number instead of BigInt for Instant fromEpochSeconds and from EpochMilliseconds in
test/mjsunit/temporal/instant-from-epoch-milliseconds.js and
test/mjsunit/temporal/instant-from-epoch-seconds.js
Throw TypeError if the type is BigInt.

4. Change the return type of Instant epochSeconds and epochMilliseconds from BigInt to Number to sync with the spec in
test/mjsunit/temporal/instant-constructor.js

Spec text
https://tc39.es/proposal-temporal/#sec-temporal-padisoyear
https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimerecord
https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochmilliseconds
https://tc39.es/proposal-temporal/#sec-temporal.instant.fromepochseconds
https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochmilliseconds
https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochseconds

Bug: v8:11544
Change-Id: Icd290905b65fdabbedece27e59c785635c212ec2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3807122
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82185}
2022-08-03 23:53:24 +00:00

45 lines
1.8 KiB
JavaScript

// 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(2021, 12, 11);
let badDate = { toPlainDateTime: d1.toPlainDateTime }
assertThrows(() => badDate.toPlainDateTime(), TypeError);
assertThrows(() => d1.toPlainDateTime(null), RangeError);
assertThrows(() => d1.toPlainDateTime("string is invalid"), RangeError);
assertThrows(() => d1.toPlainDateTime(true), RangeError);
assertThrows(() => d1.toPlainDateTime(false), RangeError);
assertThrows(() => d1.toPlainDateTime(NaN), RangeError);
assertThrows(() => d1.toPlainDateTime(Infinity), RangeError);
assertThrows(() => d1.toPlainDateTime(123), RangeError);
assertThrows(() => d1.toPlainDateTime(456n), RangeError);
assertThrows(() => d1.toPlainDateTime(Symbol()), TypeError);
assertThrows(() => d1.toPlainDateTime({}), TypeError);
assertPlainDateTime(d1.toPlainDateTime(
{hour: 23}),
2021, 12, 11, 23, 0, 0, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{minute: 23}),
2021, 12, 11, 0, 23, 0, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{second: 23}),
2021, 12, 11, 0, 0, 23, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{millisecond: 23}),
2021, 12, 11, 0, 0, 0, 23, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{microsecond: 23}),
2021, 12, 11, 0, 0, 0, 0, 23, 0);
assertPlainDateTime(d1.toPlainDateTime(
{nanosecond: 23}),
2021, 12, 11, 0, 0, 0, 0, 0, 23);
assertPlainDateTime(d1.toPlainDateTime(),
2021, 12, 11, 0, 0, 0, 0, 0, 0);
assertPlainDateTime(d1.toPlainDateTime(
{hour: 9, minute: 8, second: 7, millisecond: 6, microsecond: 5, nanosecond: 4}),
2021, 12, 11, 9, 8, 7, 6, 5, 4);