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

[Temporal] Add toJSON, toString, and non-intl toLocaleString to Instant

Also add AOs: FormatISOTimeZoneOffsetString, TemporalInstantToString,
GetUnsignedRoundingMode, ApplyUnsignedRoundingMode, RoundTemporalInstant

Also update the RoundNumberToIncrement implementation and a BigInt version.

Fix the test setup in test/mjsunit/temporal/instant-to-json.js since fromEpochSeconds and fromEpochMilliseconds do not take BigInt

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tojson
https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tolocalestring
https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tostring
https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
https://tc39.es/proposal-temporal/#sec-temporal-formatisotimezoneoffsetstring
https://tc39.es/proposal-temporal/#sec-temporal-getunsignedroundingmode
https://tc39.es/proposal-temporal/#sec-temporal-applyunsignedroundingmode
https://tc39.es/proposal-temporal/#sec-temporal-roundtemporalinstant
https://tc39.es/proposal-temporal/#sec-temporal-roundnumbertoincrement

This does NOT implement the intl version of toLocaleString
specified in (notice the "sup" not "sec" after #) yet.
https://tc39.es/proposal-temporal/#sup-temporal.instant.prototype.tolocalestring

Bug: v8:11544
Change-Id: I807afd5bf550d2a65a4732a8e536056eea79cf8f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3696483
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81428}
parent 92627133
......@@ -88,12 +88,6 @@ TO_BE_IMPLEMENTED(TemporalDurationPrototypeToString)
TO_BE_IMPLEMENTED(TemporalInstantPrototypeUntil)
/* Temporal #sec-temporal.instant.prototype.since */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeSince)
/* Temporal #sec-temporal.instant.prototype.tolocalestring */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeToLocaleString)
/* Temporal #sec-temporal.instant.prototype.tostring */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeToString)
/* Temporal #sec-temporal.instant.tojson */
TO_BE_IMPLEMENTED(TemporalInstantPrototypeToJSON)
/* Temporal.PlainYearMonth */
/* Temporal #sec-temporal.plainyearmonth.prototype.until */
......@@ -638,6 +632,9 @@ TEMPORAL_GET_BIGINT_AFTER_DIVID(Instant, EpochMicroseconds, nanoseconds, 1000,
TEMPORAL_PROTOTYPE_METHOD1(Instant, Add, add)
TEMPORAL_PROTOTYPE_METHOD1(Instant, Round, round)
TEMPORAL_PROTOTYPE_METHOD1(Instant, Subtract, subtract)
TEMPORAL_PROTOTYPE_METHOD0(Instant, ToJSON, toJSON)
TEMPORAL_PROTOTYPE_METHOD2(Instant, ToLocaleString, toLocaleString)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToString, toString)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToZonedDateTime, toZonedDateTime)
TEMPORAL_PROTOTYPE_METHOD1(Instant, ToZonedDateTimeISO, toZonedDateTimeISO)
......
This diff is collapsed.
......@@ -279,6 +279,20 @@ class JSTemporalInstant
Isolate* isolate, Handle<JSTemporalInstant> instant,
Handle<Object> temporal_duration_like);
// #sec-temporal.instant.prototype.tojson
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToJSON(
Isolate* isolate, Handle<JSTemporalInstant> instant);
// #sec-temporal.instant.prototype.tolocalestring
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToLocaleString(
Isolate* isolate, Handle<JSTemporalInstant> instant,
Handle<Object> locales, Handle<Object> options);
// #sec-temporal.instant.prototype.tostring
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToString(
Isolate* isolate, Handle<JSTemporalInstant> instant,
Handle<Object> options);
DECL_PRINTER(JSTemporalInstant)
TQ_OBJECT_CONSTRUCTORS(JSTemporalInstant)
......
......@@ -51,8 +51,6 @@
'temporal/instant-constructor': [FAIL],
'temporal/instant-from-epoch-milliseconds': [FAIL],
'temporal/instant-from-epoch-seconds': [FAIL],
'temporal/instant-to-json': [FAIL],
'temporal/instant-toJSON': [FAIL],
'temporal/plain-date-time-add': [FAIL],
'temporal/plain-date-time-subtract': [FAIL],
'temporal/plain-date-time-to-json': [FAIL],
......
......@@ -5,27 +5,27 @@
assertEquals("1970-01-01T00:00:00Z",
(Temporal.Instant.fromEpochSeconds(0n)).toJSON());
(Temporal.Instant.fromEpochSeconds(0)).toJSON());
let days_in_sec = 24n * 60n * 60n;
let days_in_sec = 24 * 60 * 60;
assertEquals("1970-12-31T23:59:59Z",
Temporal.Instant.fromEpochSeconds((365n * days_in_sec) - 1n).toJSON());
Temporal.Instant.fromEpochSeconds((365 * days_in_sec) - 1).toJSON());
assertEquals("1971-01-01T00:00:00Z",
Temporal.Instant.fromEpochSeconds((365n * days_in_sec)).toJSON());
Temporal.Instant.fromEpochSeconds((365 * days_in_sec)).toJSON());
assertEquals("1971-12-31T23:59:59Z",
Temporal.Instant.fromEpochSeconds((2n *365n * days_in_sec - 1n)).toJSON());
Temporal.Instant.fromEpochSeconds((2 *365 * days_in_sec - 1)).toJSON());
assertEquals("1972-01-01T00:00:00Z",
Temporal.Instant.fromEpochSeconds((2n *365n * days_in_sec)).toJSON());
Temporal.Instant.fromEpochSeconds((2 *365 * days_in_sec)).toJSON());
// 1972 is a leap year
assertEquals("1972-02-28T00:00:00Z",
Temporal.Instant.fromEpochSeconds(((2n *365n + 58n) * days_in_sec)).toJSON());
Temporal.Instant.fromEpochSeconds(((2 *365 + 58) * days_in_sec)).toJSON());
assertEquals("1972-02-29T00:00:00Z",
Temporal.Instant.fromEpochSeconds(((2n *365n + 59n) * days_in_sec)).toJSON());
Temporal.Instant.fromEpochSeconds(((2 *365 + 59) * days_in_sec)).toJSON());
assertEquals("1985-01-01T00:00:00Z",
Temporal.Instant.fromEpochSeconds(((15n *365n + 4n) * days_in_sec)).toJSON());
Temporal.Instant.fromEpochSeconds(((15 *365 + 4) * days_in_sec)).toJSON());
// Test with Date
......@@ -37,9 +37,8 @@ for (i = 0; i < number_of_random_test ; i++) {
// Temporal auto precision will remove trailing zeros in milliseconds so we only
// compare the first 19 char- to second.
let d = new Date(ms)
let bigd = BigInt(d)
dateout = d.toJSON().substr(0,19);
temporalout = Temporal.Instant.fromEpochMilliseconds(bigd).toJSON().substr(0, 19);
temporalout = Temporal.Instant.fromEpochMilliseconds(ms).toJSON().substr(0, 19);
if (dateout[0] != '0') {
assertEquals(dateout, temporalout, ms);
}
......
......@@ -541,7 +541,6 @@
'built-ins/Temporal/Instant/compare/instant-string': [FAIL],
'built-ins/Temporal/Instant/from/instant-string': [FAIL],
'built-ins/Temporal/Instant/from/timezone-custom': [FAIL],
'built-ins/Temporal/Instant/prototype/equals/argument-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/equals/instant-string': [FAIL],
'built-ins/Temporal/Instant/prototype/round/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/prototype/since/argument-zoneddatetime': [FAIL],
......@@ -566,41 +565,11 @@
'built-ins/Temporal/Instant/prototype/since/smallestunit-plurals-accepted': [FAIL],
'built-ins/Temporal/Instant/prototype/since/smallestunit-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/since/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toJSON/basic': [FAIL],
'built-ins/Temporal/Instant/prototype/toJSON/branding': [FAIL],
'built-ins/Temporal/Instant/prototype/toJSON/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/Instant/prototype/toJSON/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Instant/prototype/toJSON/year-format': [FAIL],
'built-ins/Temporal/Instant/prototype/toLocaleString/branding': [FAIL],
'built-ins/Temporal/Instant/prototype/toLocaleString/return-string': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/basic': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/branding': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-invalid-string': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-nan': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-non-integer': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-out-of-range': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/options-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/precision': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-invalid-string': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-invalid-string': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-plurals-accepted': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-undefined': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-valid-units': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-offset': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-string-datetime': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/year-format': [FAIL],
'built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/Instant/prototype/until/argument-zoneddatetime': [FAIL],
......@@ -979,7 +948,6 @@
'built-ins/Temporal/TimeZone/prototype/getInstantFor/options-undefined': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/balance-negative-time-units': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/instant-string': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/pre-epoch': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-zoneddatetime-balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string-multiple-offsets': [FAIL],
......@@ -1417,16 +1385,9 @@
'built-ins/Temporal/Duration/prototype/toString/smallestunit-fractionalseconddigits': [FAIL],
'built-ins/Temporal/Instant/prototype/round/rounding-direction': [FAIL],
'built-ins/Temporal/Instant/prototype/since/options-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-auto': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-number': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/options-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/rounding-cross-midnight': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/rounding-direction': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-ceil': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-floor': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-halfExpand': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/roundingmode-trunc': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-fractionalseconddigits': [FAIL],
'built-ins/Temporal/Instant/prototype/until/options-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/options-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/options-wrong-type': [FAIL],
......@@ -1546,12 +1507,9 @@
'built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/Duration/prototype/total/relativeto-wrong-type': [FAIL],
'built-ins/Temporal/Duration/prototype/total/timezone-wrong-type': [FAIL],
'built-ins/Temporal/Instant/compare/argument-wrong-type': [FAIL],
'built-ins/Temporal/Instant/from/argument-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/since/argument-object-tostring': [FAIL],
'built-ins/Temporal/Instant/prototype/since/argument-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/since/instant-string-sub-minute-offset': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number': [FAIL],
'built-ins/Temporal/Instant/prototype/until/argument-object-tostring': [FAIL],
'built-ins/Temporal/Instant/prototype/until/argument-wrong-type': [FAIL],
......@@ -1618,7 +1576,6 @@
'built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/until/argument-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-wrong-type': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/limits': [FAIL],
'built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number': [FAIL],
......@@ -1694,7 +1651,6 @@
'built-ins/Temporal/Instant/prototype/since/leap-second': [FAIL],
'built-ins/Temporal/Instant/prototype/subtract/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-string-leap-second': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-string-year-zero': [FAIL],
'built-ins/Temporal/Instant/prototype/until/argument-string-invalid': [FAIL],
'built-ins/Temporal/Instant/prototype/until/argument-string-time-separators': [FAIL],
'built-ins/Temporal/Instant/prototype/until/leap-second': [FAIL],
......
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