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

[Temporal] Add PlainDate.prototype.toZonedDateTime

Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tozoneddatetime

Bug: v8:11544
Change-Id: I758e46efdc33cfc3f336e5c595a402123ae6c485
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3535920Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80709}
parent 8516c9be
......@@ -50,8 +50,6 @@ TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeUntil)
TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeSince)
/* Temporal #sec-temporal.plaindate.prototype.equals */
TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeEquals)
/* Temporal #sec-temporal.plaindate.prototype.tozoneddatetime */
TO_BE_IMPLEMENTED(TemporalPlainDatePrototypeToZonedDateTime)
/* Temporal.PlaneTime */
/* Temporal #sec-temporal.plaintime.compare */
......@@ -415,6 +413,7 @@ TEMPORAL_PROTOTYPE_METHOD1(PlainDate, WithCalendar, withCalendar)
TEMPORAL_PROTOTYPE_METHOD2(PlainDate, With, with)
TEMPORAL_PROTOTYPE_METHOD0(PlainDate, GetISOFields, getISOFields)
TEMPORAL_PROTOTYPE_METHOD1(PlainDate, ToPlainDateTime, toPlainDateTime)
TEMPORAL_PROTOTYPE_METHOD1(PlainDate, ToZonedDateTime, toZonedDateTime)
TEMPORAL_VALUE_OF(PlainDate)
TEMPORAL_PROTOTYPE_METHOD0(PlainDate, ToJSON, toJSON)
TEMPORAL_PROTOTYPE_METHOD2(PlainDate, ToLocaleString, toLocaleString)
......
......@@ -7945,6 +7945,118 @@ MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::With(
"Temporal.PlainDate.prototype.with");
}
// #sec-temporal.plaindate.prototype.tozoneddatetime
MaybeHandle<JSTemporalZonedDateTime> JSTemporalPlainDate::ToZonedDateTime(
Isolate* isolate, Handle<JSTemporalPlainDate> temporal_date,
Handle<Object> item_obj) {
const char* method_name = "Temporal.PlainDate.prototype.toZonedDateTime";
Factory* factory = isolate->factory();
// 1. Let temporalDate be the this value.
// 2. Perform ? RequireInternalSlot(temporalDate,
// [[InitializedTemporalDate]]).
// 3. If Type(item) is Object, then
Handle<JSReceiver> time_zone;
Handle<Object> temporal_time_obj;
if (item_obj->IsJSReceiver()) {
Handle<JSReceiver> item = Handle<JSReceiver>::cast(item_obj);
// a. Let timeZoneLike be ? Get(item, "timeZone").
Handle<Object> time_zone_like;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, time_zone_like,
JSReceiver::GetProperty(isolate, item, factory->timeZone_string()),
JSTemporalZonedDateTime);
// b. If timeZoneLike is undefined, then
if (time_zone_like->IsUndefined()) {
// i. Let timeZone be ? ToTemporalTimeZone(item).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, time_zone,
temporal::ToTemporalTimeZone(isolate, item, method_name),
JSTemporalZonedDateTime);
// ii. Let temporalTime be undefined.
temporal_time_obj = factory->undefined_value();
// c. Else,
} else {
// i. Let timeZone be ? ToTemporalTimeZone(timeZoneLike).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, time_zone,
temporal::ToTemporalTimeZone(isolate, time_zone_like, method_name),
JSTemporalZonedDateTime);
// ii. Let temporalTime be ? Get(item, "plainTime").
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_time_obj,
JSReceiver::GetProperty(isolate, item, factory->plainTime_string()),
JSTemporalZonedDateTime);
}
// 4. Else,
} else {
// a. Let timeZone be ? ToTemporalTimeZone(item).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, time_zone,
temporal::ToTemporalTimeZone(isolate, item_obj, method_name),
JSTemporalZonedDateTime);
// b. Let temporalTime be undefined.
temporal_time_obj = factory->undefined_value();
}
// 5. If temporalTime is undefined, then
Handle<JSTemporalPlainDateTime> temporal_date_time;
Handle<JSReceiver> calendar(temporal_date->calendar(), isolate);
if (temporal_time_obj->IsUndefined()) {
// a. Let temporalDateTime be ?
// CreateTemporalDateTime(temporalDate.[[ISOYear]],
// temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], 0, 0, 0, 0, 0, 0,
// temporalDate.[[Calendar]]).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_time,
temporal::CreateTemporalDateTime(
isolate,
{{temporal_date->iso_year(), temporal_date->iso_month(),
temporal_date->iso_day()},
{0, 0, 0, 0, 0, 0}},
calendar),
JSTemporalZonedDateTime);
// 6. Else,
} else {
Handle<JSTemporalPlainTime> temporal_time;
// a. Set temporalTime to ? ToTemporalTime(temporalTime).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_time,
temporal::ToTemporalTime(isolate, temporal_time_obj,
ShowOverflow::kConstrain, method_name),
JSTemporalZonedDateTime);
// b. Let temporalDateTime be ?
// CreateTemporalDateTime(temporalDate.[[ISOYear]],
// temporalDate.[[ISOMonth]], temporalDate.[[ISODay]],
// temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]],
// temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]],
// temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]],
// temporalDate.[[Calendar]]).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_time,
temporal::CreateTemporalDateTime(
isolate,
{{temporal_date->iso_year(), temporal_date->iso_month(),
temporal_date->iso_day()},
{temporal_time->iso_hour(), temporal_time->iso_minute(),
temporal_time->iso_second(), temporal_time->iso_millisecond(),
temporal_time->iso_microsecond(),
temporal_time->iso_nanosecond()}},
calendar),
JSTemporalZonedDateTime);
}
// 7. Let instant be ? BuiltinTimeZoneGetInstantFor(timeZone,
// temporalDateTime, "compatible").
Handle<JSTemporalInstant> instant;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
BuiltinTimeZoneGetInstantFor(isolate, time_zone, temporal_date_time,
Disambiguation::kCompatible, method_name),
JSTemporalZonedDateTime);
// 8. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone,
// temporalDate.[[Calendar]]).
return CreateTemporalZonedDateTime(
isolate, handle(instant->nanoseconds(), isolate), time_zone, calendar);
}
// #sec-temporal.now.plaindate
MaybeHandle<JSTemporalPlainDate> JSTemporalPlainDate::Now(
Isolate* isolate, Handle<Object> calendar_like,
......
......@@ -287,6 +287,11 @@ class JSTemporalPlainDate
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainMonthDay>
ToPlainMonthDay(Isolate* isolate, Handle<JSTemporalPlainDate> plain_date);
// #sec-temporal.plaindate.prototype.tozoneddatetime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime>
ToZonedDateTime(Isolate* isolate, Handle<JSTemporalPlainDate> plain_date,
Handle<Object> item);
// #sec-temporal.now.plaindate
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDate> Now(
Isolate* isolate, Handle<Object> calendar_like,
......
......@@ -780,23 +780,9 @@
'built-ins/Temporal/PlainDate/prototype/subtract/subclassing-ignored': [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/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-zoneddatetime-negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/basic': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/branding': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar-temporal-object': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-argument-zoneddatetime-balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/plaintime-propertybag-no-time-units': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getpossibleinstantsfor-iterable': [SKIP],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string-datetime': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/argument-plaindatetime': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/argument-string-with-utc-designator': [FAIL],
......@@ -1819,7 +1805,6 @@
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-time-designator-required-for-disambiguation': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-with-time-designator': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/year-zero': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/largestunit-undefined': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/roundingincrement': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil': [FAIL],
......@@ -2298,9 +2283,6 @@
'built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/argument-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toPlainDateTime/limits': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/argument-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type': [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