[Temporal] Add toJSON, toString and non-intl version of toLocaleString to ZonedDateTime
Also add AOs: FormatISOTimeZoneOffsetString, TemporalZonedDateTimeToString, ToShowTimeZoneNameOption, ToShowOffsetOption, Update FormatTimeZoneOffsetString to use ToZeroPaddedDecimalString Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.tojson https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.tolocalestring https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.tostring https://tc39.es/proposal-temporal/#sec-temporal-formatisotimezoneoffsetstring https://tc39.es/proposal-temporal/#sec-temporal-temporalzoneddatetimetostring https://tc39.es/proposal-temporal/#sec-temporal-toshowtimezonenameoption https://tc39.es/proposal-temporal/#sec-temporal-toshowoffsetoption The intl version of toLocaleString is not implemented in this CL yet Bug: v8:11544 Change-Id: Id7e4f72b63864857b0b3fa8dc8dfcba0b5949faa Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3688848 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#81507}
This commit is contained in:
parent
adb111b776
commit
7a4a6cc6a8
@ -64,10 +64,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeUntil)
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeSince)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.round */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeRound)
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.tostring */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToString)
|
||||
/* Temporal #sec-temporal.zonedddatetimeprototype.tojson */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToJSON)
|
||||
|
||||
/* Temporal.Duration */
|
||||
/* Temporal #sec-temporal.duration.compare */
|
||||
@ -91,10 +87,6 @@ TO_BE_IMPLEMENTED(TemporalPlainYearMonthPrototypeSince)
|
||||
/* Temporal #sec-temporal.calendar.prototype.weekofyear */
|
||||
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
|
||||
|
||||
/* Temporal.ZonedDateTime */
|
||||
/* Temporal #sec-temporal.zoneddatetime.prototype.tolocalestring */
|
||||
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToLocaleString)
|
||||
|
||||
#define TEMPORAL_CONSTRUCTOR1(T) \
|
||||
BUILTIN(Temporal##T##Constructor) { \
|
||||
HandleScope scope(isolate); \
|
||||
@ -562,9 +554,12 @@ TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, OffsetNanoseconds, offsetNanoseconds)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, Offset, offset)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, StartOfDay, startOfDay)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToInstant, toInstant)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToJSON, toJSON)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainDate, toPlainDate)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainTime, toPlainTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainDateTime, toPlainDateTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(ZonedDateTime, ToLocaleString, toLocaleString)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, ToString, toString)
|
||||
TEMPORAL_VALUE_OF(ZonedDateTime)
|
||||
|
||||
// Duration
|
||||
|
@ -176,6 +176,30 @@ enum class ShowOverflow { kConstrain, kReject };
|
||||
// #sec-temporal-toshowcalendaroption
|
||||
enum class ShowCalendar { kAuto, kAlways, kNever };
|
||||
|
||||
// #sec-temporal-toshowtimezonenameoption
|
||||
enum class ShowTimeZone { kAuto, kNever };
|
||||
Maybe<ShowTimeZone> ToShowTimeZoneNameOption(Isolate* isolate,
|
||||
Handle<JSReceiver> options,
|
||||
const char* method_name) {
|
||||
// 1. Return ? GetOption(normalizedOptions, "timeZoneName", "string", «
|
||||
// "auto", "never" », "auto").
|
||||
return GetStringOption<ShowTimeZone>(
|
||||
isolate, options, "timeZoneName", method_name, {"auto", "never"},
|
||||
{ShowTimeZone::kAuto, ShowTimeZone::kNever}, ShowTimeZone::kAuto);
|
||||
}
|
||||
|
||||
// #sec-temporal-toshowoffsetoption
|
||||
enum class ShowOffset { kAuto, kNever };
|
||||
Maybe<ShowOffset> ToShowOffsetOption(Isolate* isolate,
|
||||
Handle<JSReceiver> options,
|
||||
const char* method_name) {
|
||||
// 1. Return ? GetOption(normalizedOptions, "offset", "string", « "auto",
|
||||
// "never" », "auto").
|
||||
return GetStringOption<ShowOffset>(
|
||||
isolate, options, "offset", method_name, {"auto", "never"},
|
||||
{ShowOffset::kAuto, ShowOffset::kNever}, ShowOffset::kAuto);
|
||||
}
|
||||
|
||||
enum class Precision { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9, kAuto, kMinute };
|
||||
|
||||
// Enum for add/subtract
|
||||
@ -2994,64 +3018,81 @@ Handle<String> FormatTimeZoneOffsetString(Isolate* isolate,
|
||||
builder.AppendCharacter((offset_nanoseconds >= 0) ? '+' : '-');
|
||||
// 3. Let offsetNanoseconds be abs(offsetNanoseconds).
|
||||
offset_nanoseconds = std::abs(offset_nanoseconds);
|
||||
// 3. Let nanoseconds be offsetNanoseconds modulo 10^9.
|
||||
// 4. Let nanoseconds be offsetNanoseconds modulo 10^9.
|
||||
int64_t nanoseconds = offset_nanoseconds % 1000000000;
|
||||
// 4. Let seconds be floor(offsetNanoseconds / 10^9) modulo 60.
|
||||
int64_t seconds = (offset_nanoseconds / 1000000000) % 60;
|
||||
// 5. Let minutes be floor(offsetNanoseconds / (6 × 10^10)) modulo 60.
|
||||
int64_t minutes = (offset_nanoseconds / 60000000000) % 60;
|
||||
// 6. Let hours be floor(offsetNanoseconds / (3.6 × 10^12)).
|
||||
int64_t hours = offset_nanoseconds / 3600000000000;
|
||||
// 7. Let h be hours, formatted as a two-digit decimal number, padded to the
|
||||
// left with a zero if necessary.
|
||||
if (hours < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(static_cast<int32_t>(hours));
|
||||
// 8. Let m be minutes, formatted as a two-digit decimal number, padded to the
|
||||
// left with a zero if necessary.
|
||||
// 5. Let seconds be floor(offsetNanoseconds / 10^9) modulo 60.
|
||||
int32_t seconds = (offset_nanoseconds / 1000000000) % 60;
|
||||
// 6. Let minutes be floor(offsetNanoseconds / (6 × 10^10)) modulo 60.
|
||||
int32_t minutes = (offset_nanoseconds / 60000000000) % 60;
|
||||
// 7. Let hours be floor(offsetNanoseconds / (3.6 × 10^12)).
|
||||
int32_t hours = offset_nanoseconds / 3600000000000;
|
||||
// 8. Let h be ToZeroPaddedDecimalString(hours, 2).
|
||||
ToZeroPaddedDecimalString(&builder, hours, 2);
|
||||
|
||||
// 9. Let m be ToZeroPaddedDecimalString(minutes, 2).
|
||||
builder.AppendCharacter(':');
|
||||
if (minutes < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(static_cast<int>(minutes));
|
||||
// 9. Let s be seconds, formatted as a two-digit decimal number, padded to the
|
||||
// left with a zero if necessary.
|
||||
// 10. If nanoseconds ≠ 0, then
|
||||
ToZeroPaddedDecimalString(&builder, minutes, 2);
|
||||
|
||||
// 10. Let s be ToZeroPaddedDecimalString(seconds, 2).
|
||||
// 11. If nanoseconds ≠ 0, then
|
||||
if (nanoseconds != 0) {
|
||||
builder.AppendCharacter(':');
|
||||
if (seconds < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(static_cast<int>(seconds));
|
||||
builder.AppendCharacter('.');
|
||||
// a. Let fraction be nanoseconds, formatted as a nine-digit decimal number,
|
||||
// padded to the left with zeroes if necessary.
|
||||
// a. Let fraction be ToZeroPaddedDecimalString(nanoseconds, 9).
|
||||
// b. Set fraction to the longest possible substring of fraction starting at
|
||||
// position 0 and not ending with the code unit 0x0030 (DIGIT ZERO).
|
||||
// position 0 and not ending with the code unit 0x0030 (DIGIT ZERO). c. Let
|
||||
// post be the string-concatenation of the code unit 0x003A (COLON), s, the
|
||||
// code unit 0x002E (FULL STOP), and fraction.
|
||||
builder.AppendCharacter(':');
|
||||
ToZeroPaddedDecimalString(&builder, seconds, 2);
|
||||
builder.AppendCharacter('.');
|
||||
int64_t divisor = 100000000;
|
||||
do {
|
||||
builder.AppendInt(static_cast<int>(nanoseconds / divisor));
|
||||
nanoseconds %= divisor;
|
||||
divisor /= 10;
|
||||
} while (nanoseconds > 0);
|
||||
// c. Let post be the string-concatenation of the code unit 0x003A (COLON),
|
||||
// s, the code unit 0x002E (FULL STOP), and fraction.
|
||||
// 11. Else if seconds ≠ 0, then
|
||||
} else if (seconds != 0) {
|
||||
// a. Let post be the string-concatenation of the code unit 0x003A (COLON)
|
||||
// and s.
|
||||
builder.AppendCharacter(':');
|
||||
if (seconds < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(static_cast<int>(seconds));
|
||||
ToZeroPaddedDecimalString(&builder, seconds, 2);
|
||||
}
|
||||
// 12. Return the string-concatenation of sign, h, the code unit 0x003A
|
||||
// (COLON), m, and post.
|
||||
return builder.Finish().ToHandleChecked();
|
||||
}
|
||||
|
||||
double RoundNumberToIncrement(Isolate* isolate, double x, double increment,
|
||||
RoundingMode rounding_mode);
|
||||
|
||||
// #sec-temporal-formatisotimezoneoffsetstring
|
||||
Handle<String> FormatISOTimeZoneOffsetString(Isolate* isolate,
|
||||
int64_t offset_nanoseconds) {
|
||||
IncrementalStringBuilder builder(isolate);
|
||||
// 1. Assert: offsetNanoseconds is an integer.
|
||||
// 2. Set offsetNanoseconds to ! RoundNumberToIncrement(offsetNanoseconds, 60
|
||||
// × 10^9, "halfExpand").
|
||||
offset_nanoseconds = RoundNumberToIncrement(
|
||||
isolate, offset_nanoseconds, 60000000000, RoundingMode::kHalfExpand);
|
||||
// 3. If offsetNanoseconds ≥ 0, let sign be "+"; otherwise, let sign be "-".
|
||||
builder.AppendCharacter((offset_nanoseconds >= 0) ? '+' : '-');
|
||||
// 4. Set offsetNanoseconds to abs(offsetNanoseconds).
|
||||
offset_nanoseconds = std::abs(offset_nanoseconds);
|
||||
// 5. Let minutes be offsetNanoseconds / (60 × 10^9) modulo 60.
|
||||
int32_t minutes = (offset_nanoseconds / 60000000000) % 60;
|
||||
// 6. Let hours be floor(offsetNanoseconds / (3600 × 10^9)).
|
||||
int32_t hours = offset_nanoseconds / 3600000000000;
|
||||
// 7. Let h be ToZeroPaddedDecimalString(hours, 2).
|
||||
ToZeroPaddedDecimalString(&builder, hours, 2);
|
||||
|
||||
// 8. Let m be ToZeroPaddedDecimalString(minutes, 2).
|
||||
builder.AppendCharacter(':');
|
||||
ToZeroPaddedDecimalString(&builder, minutes, 2);
|
||||
// 9. Return the string-concatenation of sign, h, the code unit 0x003A
|
||||
// (COLON), and m.
|
||||
return builder.Finish().ToHandleChecked();
|
||||
}
|
||||
|
||||
int32_t DecimalLength(int32_t n) {
|
||||
int32_t i = 1;
|
||||
while (n >= 10) {
|
||||
@ -13717,6 +13758,215 @@ MaybeHandle<JSTemporalPlainMonthDay> JSTemporalZonedDateTime::ToPlainMonthDay(
|
||||
"Temporal.ZonedDateTime.prototype.toPlainMonthDay");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Handle<BigInt> RoundTemporalInstant(Isolate* isolate, Handle<BigInt> ns,
|
||||
int64_t increment, Unit unit,
|
||||
RoundingMode rounding_mode);
|
||||
|
||||
// #sec-temporal-temporalzoneddatetimetostring
|
||||
MaybeHandle<String> TemporalZonedDateTimeToString(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Precision precision, ShowCalendar show_calendar,
|
||||
ShowTimeZone show_time_zone, ShowOffset show_offset, int64_t increment,
|
||||
Unit unit, RoundingMode rounding_mode, const char* method_name) {
|
||||
// 5. Let ns be ! RoundTemporalInstant(zonedDateTime.[[Nanoseconds]],
|
||||
// increment, unit, roundingMode).
|
||||
Handle<BigInt> ns = RoundTemporalInstant(
|
||||
isolate, handle(zoned_date_time->nanoseconds(), isolate), increment, unit,
|
||||
rounding_mode);
|
||||
|
||||
// 6. Let timeZone be zonedDateTime.[[TimeZone]].
|
||||
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
|
||||
// 7. Let instant be ! CreateTemporalInstant(ns).
|
||||
Handle<JSTemporalInstant> instant =
|
||||
temporal::CreateTemporalInstant(isolate, ns).ToHandleChecked();
|
||||
|
||||
// 8. Let isoCalendar be ! GetISO8601Calendar().
|
||||
Handle<JSTemporalCalendar> iso_calendar =
|
||||
temporal::GetISO8601Calendar(isolate);
|
||||
|
||||
// 9. Let temporalDateTime be ?
|
||||
// temporal::BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant,
|
||||
// isoCalendar).
|
||||
Handle<JSTemporalPlainDateTime> temporal_date_time;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, temporal_date_time,
|
||||
temporal::BuiltinTimeZoneGetPlainDateTimeFor(isolate, time_zone, instant,
|
||||
iso_calendar, method_name),
|
||||
String);
|
||||
// 10. Let dateTimeString be ?
|
||||
// TemporalDateTimeToString(temporalDateTime.[[ISOYear]],
|
||||
// temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]],
|
||||
// temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]],
|
||||
// temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]],
|
||||
// temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]],
|
||||
// isoCalendar, precision, "never").
|
||||
Handle<String> date_time_string;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, date_time_string,
|
||||
TemporalDateTimeToString(
|
||||
isolate,
|
||||
{{temporal_date_time->iso_year(), temporal_date_time->iso_month(),
|
||||
temporal_date_time->iso_day()},
|
||||
{temporal_date_time->iso_hour(), temporal_date_time->iso_minute(),
|
||||
temporal_date_time->iso_second(),
|
||||
temporal_date_time->iso_millisecond(),
|
||||
temporal_date_time->iso_microsecond(),
|
||||
temporal_date_time->iso_nanosecond()}},
|
||||
iso_calendar, precision, ShowCalendar::kNever),
|
||||
String);
|
||||
|
||||
IncrementalStringBuilder builder(isolate);
|
||||
builder.AppendString(date_time_string);
|
||||
|
||||
// 11. If showOffset is "never", then
|
||||
if (show_offset == ShowOffset::kNever) {
|
||||
// a. Let offsetString be the empty String.
|
||||
// 12. Else,
|
||||
} else {
|
||||
// a. Let offsetNs be ? GetOffsetNanosecondsFor(timeZone, instant).
|
||||
int64_t offset_ns;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, offset_ns,
|
||||
GetOffsetNanosecondsFor(isolate, time_zone, instant, method_name),
|
||||
Handle<String>());
|
||||
// b. Let offsetString be ! FormatISOTimeZoneOffsetString(offsetNs).
|
||||
builder.AppendString(FormatISOTimeZoneOffsetString(isolate, offset_ns));
|
||||
}
|
||||
|
||||
// 13. If showTimeZone is "never", then
|
||||
if (show_time_zone == ShowTimeZone::kNever) {
|
||||
// a. Let timeZoneString be the empty String.
|
||||
// 14. Else,
|
||||
} else {
|
||||
// a. Let timeZoneID be ? ToString(timeZone).
|
||||
Handle<String> time_zone_id;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(isolate, time_zone_id,
|
||||
Object::ToString(isolate, time_zone), String);
|
||||
// b. Let timeZoneString be the string-concatenation of the code unit 0x005B
|
||||
// (LEFT SQUARE BRACKET), timeZoneID, and the code unit 0x005D (RIGHT SQUARE
|
||||
// BRACKET).
|
||||
builder.AppendCStringLiteral("[");
|
||||
builder.AppendString(time_zone_id);
|
||||
builder.AppendCStringLiteral("]");
|
||||
}
|
||||
// 15. Let calendarID be ? ToString(zonedDateTime.[[Calendar]]).
|
||||
Handle<String> calendar_id;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, calendar_id,
|
||||
Object::ToString(isolate, handle(zoned_date_time->calendar(), isolate)),
|
||||
String);
|
||||
|
||||
// 16. Let calendarString be ! FormatCalendarAnnotation(calendarID,
|
||||
// showCalendar).
|
||||
builder.AppendString(
|
||||
FormatCalendarAnnotation(isolate, calendar_id, show_calendar));
|
||||
// 17. Return the string-concatenation of dateTimeString, offsetString,
|
||||
// timeZoneString, and calendarString.
|
||||
return builder.Finish();
|
||||
}
|
||||
|
||||
// #sec-temporal-temporalzoneddatetimetostring
|
||||
MaybeHandle<String> TemporalZonedDateTimeToString(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Precision precision, ShowCalendar show_calendar,
|
||||
ShowTimeZone show_time_zone, ShowOffset show_offset,
|
||||
const char* method_name) {
|
||||
// 1. Assert: Type(zonedDateTime) is Object and zonedDateTime has an
|
||||
// [[InitializedTemporalZonedDateTime]] internal slot.
|
||||
// 2. If increment is not present, set it to 1.
|
||||
// 3. If unit is not present, set it to "nanosecond".
|
||||
// 4. If roundingMode is not present, set it to "trunc".
|
||||
return TemporalZonedDateTimeToString(
|
||||
isolate, zoned_date_time, precision, show_calendar, show_time_zone,
|
||||
show_offset, 1, Unit::kNanosecond, RoundingMode::kTrunc, method_name);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
// #sec-temporal.zoneddatetime.prototype.tojson
|
||||
MaybeHandle<String> JSTemporalZonedDateTime::ToJSON(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
|
||||
TEMPORAL_ENTER_FUNC();
|
||||
// 1. Let zonedDateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(zonedDateTime,
|
||||
// [[InitializedTemporalZonedDateTime]]).
|
||||
// 3. Return ? TemporalZonedDateTimeToString(zonedDateTime, "auto", "auto",
|
||||
// "auto", "auto").
|
||||
return TemporalZonedDateTimeToString(
|
||||
isolate, zoned_date_time, Precision::kAuto, ShowCalendar::kAuto,
|
||||
ShowTimeZone::kAuto, ShowOffset::kAuto,
|
||||
"Temporal.ZonedDateTime.prototype.toJSON");
|
||||
}
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.tolocalestring
|
||||
MaybeHandle<String> JSTemporalZonedDateTime::ToLocaleString(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Handle<Object> locales, Handle<Object> options) {
|
||||
// TODO(ftang) Implement #sup-temporal.plaindatetime.prototype.tolocalestring
|
||||
return TemporalZonedDateTimeToString(
|
||||
isolate, zoned_date_time, Precision::kAuto, ShowCalendar::kAuto,
|
||||
ShowTimeZone::kAuto, ShowOffset::kAuto,
|
||||
"Temporal.ZonedDateTime.prototype.toLocaleString");
|
||||
}
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.tostring
|
||||
MaybeHandle<String> JSTemporalZonedDateTime::ToString(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Handle<Object> options_obj) {
|
||||
const char* method_name = "Temporal.ZonedDateTime.prototype.toString";
|
||||
// 1. Let zonedDateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(zonedDateTime,
|
||||
// [[InitializedTemporalZonedDateTime]]).
|
||||
// 3. Set options to ? GetOptionsObject(options).
|
||||
Handle<JSReceiver> options;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, options, GetOptionsObject(isolate, options_obj, method_name),
|
||||
String);
|
||||
|
||||
// 4. Let precision be ? ToSecondsStringPrecision(options).
|
||||
StringPrecision precision;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, precision,
|
||||
ToSecondsStringPrecision(isolate, options, method_name),
|
||||
Handle<String>());
|
||||
|
||||
// 5. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc").
|
||||
RoundingMode rounding_mode;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, rounding_mode,
|
||||
ToTemporalRoundingMode(isolate, options, RoundingMode::kTrunc,
|
||||
method_name),
|
||||
Handle<String>());
|
||||
|
||||
// 6. Let showCalendar be ? ToShowCalendarOption(options).
|
||||
ShowCalendar show_calendar;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, show_calendar,
|
||||
ToShowCalendarOption(isolate, options, method_name), Handle<String>());
|
||||
|
||||
// 7. Let showTimeZone be ? ToShowTimeZoneNameOption(options).
|
||||
ShowTimeZone show_time_zone;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, show_time_zone,
|
||||
ToShowTimeZoneNameOption(isolate, options, method_name),
|
||||
Handle<String>());
|
||||
|
||||
// 8. Let showOffset be ? ToShowOffsetOption(options).
|
||||
ShowOffset show_offset;
|
||||
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
|
||||
isolate, show_offset, ToShowOffsetOption(isolate, options, method_name),
|
||||
Handle<String>());
|
||||
|
||||
// 9. Return ? TemporalZonedDateTimeToString(zonedDateTime,
|
||||
// precision.[[Precision]], showCalendar, showTimeZone, showOffset,
|
||||
// precision.[[Increment]], precision.[[Unit]], roundingMode).
|
||||
return TemporalZonedDateTimeToString(
|
||||
isolate, zoned_date_time, precision.precision, show_calendar,
|
||||
show_time_zone, show_offset, precision.increment, precision.unit,
|
||||
rounding_mode, method_name);
|
||||
}
|
||||
|
||||
// #sec-temporal.now.zoneddatetime
|
||||
MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::Now(
|
||||
Isolate* isolate, Handle<Object> calendar_like,
|
||||
@ -14616,32 +14866,6 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalInstant::ToZonedDateTime(
|
||||
|
||||
namespace {
|
||||
|
||||
// #sec-temporal-formatisotimezoneoffsetstring
|
||||
V8_WARN_UNUSED_RESULT Handle<String> FormatISOTimeZoneOffsetString(
|
||||
Isolate* isolate, int64_t offset_nanoseconds) {
|
||||
IncrementalStringBuilder builder(isolate);
|
||||
// 1. Assert: offsetNanoseconds is an integer.
|
||||
// 2. Set offsetNanoseconds to ! RoundNumberToIncrement(offsetNanoseconds, 60
|
||||
// × 10^9, "halfExpand").
|
||||
offset_nanoseconds = RoundNumberToIncrement(isolate, offset_nanoseconds, 6e10,
|
||||
RoundingMode::kHalfExpand);
|
||||
// 3. If offsetNanoseconds ≥ 0, let sign be "+"; otherwise, let sign be "-".
|
||||
builder.AppendCharacter((offset_nanoseconds >= 0) ? '+' : '-');
|
||||
// 4. Set offsetNanoseconds to abs(offsetNanoseconds).
|
||||
offset_nanoseconds = abs(offset_nanoseconds);
|
||||
// 5. Let minutes be offsetNanoseconds / (60 × 10^9) modulo 60.
|
||||
int32_t minutes = (offset_nanoseconds / 60000000000) % 60;
|
||||
// 6. Let hours be floor(offsetNanoseconds / (3600 × 10^9)).
|
||||
int32_t hours = offset_nanoseconds / 3600000000000;
|
||||
// 7. Let h be ToZeroPaddedDecimalString(hours, 2).
|
||||
ToZeroPaddedDecimalString(&builder, hours, 2);
|
||||
// 8. Let m be ToZeroPaddedDecimalString(minutes, 2).
|
||||
ToZeroPaddedDecimalString(&builder, minutes, 2);
|
||||
// 9. Return the string-concatenation of sign, h, the code unit 0x003A
|
||||
// (COLON), and m.
|
||||
return builder.Finish().ToHandleChecked();
|
||||
}
|
||||
|
||||
// #sec-temporal-temporalinstanttostring
|
||||
MaybeHandle<String> TemporalInstantToString(Isolate* isolate,
|
||||
Handle<JSTemporalInstant> instant,
|
||||
|
@ -938,6 +938,20 @@ class JSTemporalZonedDateTime
|
||||
ToPlainDateTime(Isolate* isolate,
|
||||
Handle<JSTemporalZonedDateTime> zoned_date_time);
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.tojson
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToJSON(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.tolocalestring
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToLocaleString(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Handle<Object> locales, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.zoneddatetime.prototype.tostring
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToString(
|
||||
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
|
||||
Handle<Object> options);
|
||||
|
||||
DECL_PRINTER(JSTemporalZonedDateTime)
|
||||
|
||||
TQ_OBJECT_CONSTRUCTORS(JSTemporalZonedDateTime)
|
||||
|
@ -524,8 +524,6 @@
|
||||
'built-ins/Temporal/Instant/prototype/since/largestunit': [FAIL],
|
||||
'built-ins/Temporal/Instant/prototype/toString/timezone': [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/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],
|
||||
@ -569,7 +567,6 @@
|
||||
'built-ins/Temporal/PlainDate/prototype/subtract/limits': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/toPlainDateTime/basic': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/basic': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-argument-zoneddatetime-balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getpossibleinstantsfor-iterable': [SKIP],
|
||||
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
|
||||
@ -961,52 +958,13 @@
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/zoneddatetime-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/zoneddatetime-string-multiple-offsets': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/branding': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/negative-epochnanoseconds': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/offset': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/year-format': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/branding': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/return-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toPlainDateTime/plain-custom-timezone': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toPlainTime/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/branding': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/calendarname-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-nan': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-non-integer': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/negative-epochnanoseconds': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/offset': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/offset-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/offset-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/offset-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/options-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/smallestunit-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/smallestunit-plurals-accepted': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/smallestunit-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/smallestunit-valid-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/smallestunit-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-undefined': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/year-format': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/balance-negative-time-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/branding': [FAIL],
|
||||
@ -1349,16 +1307,10 @@
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/round/rounding-direction': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/round/roundto-invalid-string': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-auto': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-number': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/options-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/rounding-cross-midnight': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/rounding-direction': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-ceil': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-floor': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfExpand': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-trunc': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toString/smallestunit-fractionalseconddigits': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/options-wrong-type': [FAIL],
|
||||
'intl402/Temporal/Instant/prototype/toString/timezone-offset': [FAIL],
|
||||
'intl402/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-calendar': [FAIL],
|
||||
@ -1536,7 +1488,6 @@
|
||||
'built-ins/Temporal/Instant/from/argument-string': [FAIL],
|
||||
'built-ins/Temporal/Instant/prototype/add/argument-string-negative-fractional-units': [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/PlainDate/prototype/since/argument-leap-second': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-leap-second': [FAIL],
|
||||
'built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-year-zero': [FAIL],
|
||||
@ -1591,7 +1542,6 @@
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-string-negative-fractional-units': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/toJSON/basic': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-leap-second': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-year-zero': [FAIL],
|
||||
'built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-time-separators': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user