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

[Temporal] Add ZoneDateTime.prototype.offset*

Spec Text:
https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.offset
https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.offsetnanoseconds

Bug: v8:11544
Change-Id: Ia88d96b038117a8e528ff9d0cdb9a07fb7cbcda5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3385606Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80096}
parent dd835c01
......@@ -160,10 +160,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeDaysInYear)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeMonthsInYear)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.inleapyear */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeInLeapYear)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.offsetnanoseconds */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeOffsetNanoseconds)
/* Temporal #sec-get-temporal.zoneddatetime.prototype.offset */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeOffset)
/* Temporal #sec-temporal.zoneddatetime.prototype.with */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeWith)
/* Temporal #sec-temporal.zoneddatetime.prototype.withplaintime */
......@@ -739,6 +735,8 @@ TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, WithTimeZone, withTimeZone)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainYearMonth, toPlainYearMonth)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainMonthDay, toPlainMonthDay)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, OffsetNanoseconds, offsetNanoseconds)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, Offset, offset)
TEMPORAL_VALUE_OF(ZonedDateTime)
// Duration
......
......@@ -6426,6 +6426,51 @@ MaybeHandle<JSTemporalInstant> JSTemporalInstant::Now(Isolate* isolate) {
return SystemInstant(isolate);
}
// #sec-get-temporal.zoneddatetime.prototype.offsetnanoseconds
MaybeHandle<Object> JSTemporalZonedDateTime::OffsetNanoseconds(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
TEMPORAL_ENTER_FUNC();
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]).
// 3. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone = handle(zoned_date_time->time_zone(), isolate);
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate)),
Object);
// 5. Return 𝔽(? GetOffsetNanosecondsFor(timeZone, instant)).
Maybe<int64_t> maybe_result = GetOffsetNanosecondsFor(
isolate, time_zone, instant,
"Temporal.ZonedDateTime.prototype.offsetNanoseconds");
MAYBE_RETURN(maybe_result, Handle<Object>());
return isolate->factory()->NewNumberFromInt64(maybe_result.FromJust());
}
// #sec-get-temporal.zoneddatetime.prototype.offset
MaybeHandle<String> JSTemporalZonedDateTime::Offset(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
TEMPORAL_ENTER_FUNC();
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]).
// 3. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, instant,
temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate)),
String);
// 4. Return ? BuiltinTimeZoneGetOffsetStringFor(zonedDateTime.[[TimeZone]],
// instant).
return BuiltinTimeZoneGetOffsetStringFor(
isolate, handle(zoned_date_time->time_zone(), isolate), instant,
"Temporal.ZonedDateTime.prototype.offset");
}
// #sec-temporal.instant
MaybeHandle<JSTemporalInstant> JSTemporalInstant::Constructor(
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
......
......@@ -430,6 +430,14 @@ class JSTemporalZonedDateTime
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> NowISO(
Isolate* isolate, Handle<Object> temporal_time_zone_like);
// #sec-get-temporal.zoneddatetime.prototype.offsetnanoseconds
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> OffsetNanoseconds(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-get-temporal.zoneddatetime.prototype.offset
V8_WARN_UNUSED_RESULT static MaybeHandle<String> Offset(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
DECL_PRINTER(JSTemporalZonedDateTime)
TQ_OBJECT_CONSTRUCTORS(JSTemporalZonedDateTime)
......
......@@ -1956,16 +1956,6 @@
'built-ins/Temporal/ZonedDateTime/prototype/month/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/nanosecond/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/basic': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offsetNanoseconds/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offsetNanoseconds/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offsetNanoseconds/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offsetNanoseconds/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offsetNanoseconds/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/offset/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/dateadd-options': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/div-zero': [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