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

[Temporal] Add ZonedDateTime.prototype.(add|subtract)

Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.add
https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.subtract

Bug: v8:11544
Change-Id: If4e1f71a05a0d1e88829bf219d4f90bd7a343877
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3617392Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80960}
parent 6d33cb89
......@@ -70,10 +70,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimeCompare)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeWith)
/* Temporal #sec-temporal.zoneddatetime.prototype.withplaindate */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeWithPlainDate)
/* Temporal #sec-temporal.zoneddatetime.prototype.add */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeAdd)
/* Temporal #sec-temporal.zoneddatetime.prototype.subtract */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeSubtract)
/* Temporal #sec-temporal.zoneddatetime.prototype.until */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeUntil)
/* Temporal #sec-temporal.zoneddatetime.prototype.since */
......@@ -597,6 +593,8 @@ TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, WithPlainTime, withPlainTime)
TEMPORAL_PROTOTYPE_METHOD1(ZonedDateTime, WithTimeZone, withTimeZone)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainYearMonth, toPlainYearMonth)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, ToPlainMonthDay, toPlainMonthDay)
TEMPORAL_PROTOTYPE_METHOD2(ZonedDateTime, Add, add)
TEMPORAL_PROTOTYPE_METHOD2(ZonedDateTime, Subtract, subtract)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, OffsetNanoseconds, offsetNanoseconds)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, Offset, offset)
......
......@@ -11501,6 +11501,90 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::NowISO(
method_name);
}
namespace {
// #sec-temporal-adddurationtoOrsubtractdurationfromzoneddatetime
MaybeHandle<JSTemporalZonedDateTime>
AddDurationToOrSubtractDurationFromZonedDateTime(
Isolate* isolate, Arithmetic operation,
Handle<JSTemporalZonedDateTime> zoned_date_time,
Handle<Object> temporal_duration_like, Handle<Object> options_obj,
const char* method_name) {
TEMPORAL_ENTER_FUNC();
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
double sign = operation == Arithmetic::kSubtract ? -1.0 : 1.0;
// 2. Let duration be ? ToTemporalDurationRecord(temporalDurationLike).
DurationRecord duration;
MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, duration,
temporal::ToTemporalDurationRecord(isolate, temporal_duration_like,
method_name),
Handle<JSTemporalZonedDateTime>());
TimeDurationRecord& time_duration = duration.time_duration;
// 3. Set options to ? GetOptionsObject(options).
Handle<JSReceiver> options;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, options, GetOptionsObject(isolate, options_obj, method_name),
JSTemporalZonedDateTime);
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
// 5. Let calendar be zonedDateTime.[[Calendar]].
Handle<JSReceiver> calendar(zoned_date_time->calendar(), isolate);
// 6. Let epochNanoseconds be ?
// AddZonedDateTime(zonedDateTime.[[Nanoseconds]], timeZone, calendar,
// sign x duration.[[Years]], sign x duration.[[Months]], sign x
// duration.[[Weeks]], sign x duration.[[Days]], sign x duration.[[Hours]],
// sign x duration.[[Minutes]], sign x duration.[[Seconds]], sign x
// duration.[[Milliseconds]], sign x duration.[[Microseconds]], sign x
// duration.[[Nanoseconds]], options).
Handle<BigInt> nanoseconds(zoned_date_time->nanoseconds(), isolate);
duration.years *= sign;
duration.months *= sign;
duration.weeks *= sign;
time_duration.days *= sign;
time_duration.hours *= sign;
time_duration.minutes *= sign;
time_duration.seconds *= sign;
time_duration.milliseconds *= sign;
time_duration.microseconds *= sign;
time_duration.nanoseconds *= sign;
Handle<BigInt> epoch_nanoseconds;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, epoch_nanoseconds,
AddZonedDateTime(isolate, nanoseconds, time_zone, calendar, duration,
options, method_name),
JSTemporalZonedDateTime);
// 7. Return ? CreateTemporalZonedDateTime(epochNanoseconds, timeZone,
// calendar).
return CreateTemporalZonedDateTime(isolate, epoch_nanoseconds, time_zone,
calendar);
}
} // namespace
// #sec-temporal.zoneddatetime.prototype.add
MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::Add(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
Handle<Object> temporal_duration_like, Handle<Object> options) {
TEMPORAL_ENTER_FUNC();
return AddDurationToOrSubtractDurationFromZonedDateTime(
isolate, Arithmetic::kAdd, zoned_date_time, temporal_duration_like,
options, "Temporal.ZonedDateTime.prototype.add");
}
// #sec-temporal.zoneddatetime.prototype.subtract
MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::Subtract(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
Handle<Object> temporal_duration_like, Handle<Object> options) {
TEMPORAL_ENTER_FUNC();
return AddDurationToOrSubtractDurationFromZonedDateTime(
isolate, Arithmetic::kSubtract, zoned_date_time, temporal_duration_like,
options, "Temporal.ZonedDateTime.prototype.subtract");
}
// #sec-temporal.zoneddatetime.prototype.getisofields
MaybeHandle<JSReceiver> JSTemporalZonedDateTime::GetISOFields(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
......
......@@ -765,6 +765,15 @@ class JSTemporalZonedDateTime
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> HoursInDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.add
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> Add(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
Handle<Object> temporal_duration_like, Handle<Object> options);
// #sec-temporal.zoneddatetime.prototype.subtract
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> Subtract(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time,
Handle<Object> temporal_duration_like, Handle<Object> options);
// #sec-temporal.zoneddatetime.prototype.getisofields
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> GetISOFields(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
......
......@@ -1138,19 +1138,6 @@
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-string-multiple-offsets': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/zoneddatetime-sub-minute-offset': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/non-integer-throws-rangeerror': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/options-undefined': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/overflow-invalid-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/overflow-undefined': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/overflow-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/subclassing-ignored': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/day/balance-negative-time-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
......@@ -1235,19 +1222,6 @@
'built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string-multiple-offsets': [FAIL],
'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/subtract/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/negative-epochnanoseconds': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/non-integer-throws-rangeerror': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/options-undefined': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-invalid-string': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-undefined': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/subclassing-ignored': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/timezone-getoffsetnanosecondsfor-wrong-type': [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],
......@@ -1644,13 +1618,11 @@
'built-ins/Temporal/ZonedDateTime/compare/year-zero': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/year-zero': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/equals/year-zero': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/largestunit-smallestunit-mismatch': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/since/year-zero': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-offset-not-agreeing-with-timezone': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/largestunit-smallestunit-mismatch': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/until/year-zero': [FAIL],
......@@ -1788,12 +1760,10 @@
'built-ins/Temporal/PlainYearMonth/prototype/subtract/options-wrong-type': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/until/options-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/from/options-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/add/options-wrong-type': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/round/options-wrong-type': [FAIL],
'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/subtract/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],
......
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