v8/test/mjsunit/temporal/plain-date-to-json.js
Frank Tang a5697616eb [Temporal] Add PlainDate.prototype.toJSON
Also add AOs: PadISOYear, FormatCalendarAnnotation, TemporalDateToString
Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tojson
https://tc39.es/proposal-temporal/#sec-temporal-padisoyear
https://tc39.es/proposal-temporal/#sec-temporal-formatcalendarannotation
https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetostring

Change the ISODateTimeWithinLimits from
-8.64 × 10^21 - 8.64 × 10^16, 8.64 × 10^21 + 8.64 × 10^16
to
-8.64 × 10^21 - 8.64 × 10^13, 8.64 × 10^21 + 8.64 × 10^13
per https://github.com/tc39/proposal-temporal/pull/1723

Change to use AppendCStringLiteral instead of AppendCharacter when
appropriate.

Bug: v8:11544
Change-Id: I01f22657b2c3e5aacbea790593d7e9f60076ec74
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3438379
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80622}
2022-05-19 01:22:23 +00:00

19 lines
1.0 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
// years in 4 digits range
assertEquals("2021-07-01", (new Temporal.PlainDate(2021, 7, 1)).toJSON());
assertEquals("9999-12-31", (new Temporal.PlainDate(9999, 12, 31)).toJSON());
assertEquals("1000-01-01", (new Temporal.PlainDate(1000, 1, 1)).toJSON());
assertEquals("0099-08-01", (new Temporal.PlainDate(99, 8, 1)).toJSON());
assertEquals("0999-12-31", (new Temporal.PlainDate(999, 12, 31)).toJSON());
// years out of 4 digits range
assertEquals("+010000-01-01", (new Temporal.PlainDate(10000, 1, 1)).toJSON());
assertEquals("+025021-07-01", (new Temporal.PlainDate(25021, 7, 1)).toJSON());
assertEquals("-000020-09-30", (new Temporal.PlainDate(-20, 9, 30)).toJSON());
assertEquals("-002021-07-01", (new Temporal.PlainDate(-2021, 7, 1)).toJSON());
assertEquals("-022021-07-01", (new Temporal.PlainDate(-22021, 7, 1)).toJSON());