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

[Temporal] Add ZonedDateTime.prototype.startOfDay

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

Bug: v8:11544
Change-Id: I475e03fa9ba43290896a906524414cfbddd1f7bb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3385610
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80754}
parent 9a570284
......@@ -124,8 +124,6 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeEquals)
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToString)
/* Temporal #sec-temporal.zonedddatetimeprototype.tojson */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToJSON)
/* Temporal #sec-temporal.zoneddatetime.prototype.startofday */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeStartOfDay)
/* Temporal #sec-temporal.zoneddatetime.prototype.toinstant */
TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToInstant)
/* Temporal #sec-temporal.zoneddatetime.prototype.toplaindate */
......@@ -629,6 +627,7 @@ TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, GetISOFields, getISOFields)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, OffsetNanoseconds, offsetNanoseconds)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, Offset, offset)
TEMPORAL_VALUE_OF(ZonedDateTime)
TEMPORAL_PROTOTYPE_METHOD0(ZonedDateTime, StartOfDay, startOfDay)
// Duration
BUILTIN(TemporalDurationConstructor) {
......
......@@ -10080,6 +10080,60 @@ MaybeHandle<String> JSTemporalZonedDateTime::Offset(
"Temporal.ZonedDateTime.prototype.offset");
}
// #sec-temporal.zoneddatetime.prototype.startofday
MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::StartOfDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
TEMPORAL_ENTER_FUNC();
const char* method_name = "Temporal.ZonedDateTime.prototype.startOfDay";
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime,
// [[InitializedTemporalZonedDateTime]]).
// 3. Let timeZone be zonedDateTime.[[TimeZone]].
Handle<JSReceiver> time_zone(zoned_date_time->time_zone(), isolate);
// 4. Let calendar be zonedDateTime.[[Calendar]].
Handle<JSReceiver> calendar(zoned_date_time->calendar(), isolate);
// 5. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
Handle<JSTemporalInstant> instant =
temporal::CreateTemporalInstant(
isolate, handle(zoned_date_time->nanoseconds(), isolate))
.ToHandleChecked();
// 6. Let temporalDateTime be ?
// BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
Handle<JSTemporalPlainDateTime> temporal_date_time;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date_time,
temporal::BuiltinTimeZoneGetPlainDateTimeFor(isolate, time_zone, instant,
calendar, method_name),
JSTemporalZonedDateTime);
// 7. Let startDateTime be ?
// CreateTemporalDateTime(temporalDateTime.[[ISOYear]],
// temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], 0, 0, 0, 0, 0,
// 0, calendar).
Handle<JSTemporalPlainDateTime> start_date_time;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, start_date_time,
temporal::CreateTemporalDateTime(
isolate,
{{temporal_date_time->iso_year(), temporal_date_time->iso_month(),
temporal_date_time->iso_day()},
{0, 0, 0, 0, 0, 0}},
calendar),
JSTemporalZonedDateTime);
// 8. Let startInstant be ? BuiltinTimeZoneGetInstantFor(timeZone,
// startDateTime, "compatible").
Handle<JSTemporalInstant> start_instant;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, start_instant,
BuiltinTimeZoneGetInstantFor(isolate, time_zone, start_date_time,
Disambiguation::kCompatible, method_name),
JSTemporalZonedDateTime);
// 9. Return ? CreateTemporalZonedDateTime(startInstant.[[Nanoseconds]],
// timeZone, calendar).
return CreateTemporalZonedDateTime(
isolate, handle(start_instant->nanoseconds(), isolate), time_zone,
calendar);
}
// #sec-temporal.instant
MaybeHandle<JSTemporalInstant> JSTemporalInstant::Constructor(
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
......
......@@ -678,6 +678,10 @@ class JSTemporalZonedDateTime
V8_WARN_UNUSED_RESULT static MaybeHandle<String> Offset(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.startofday
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalZonedDateTime> StartOfDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
DECL_PRINTER(JSTemporalZonedDateTime)
TQ_OBJECT_CONSTRUCTORS(JSTemporalZonedDateTime)
......
......@@ -1461,12 +1461,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/startOfDay/branding': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/startOfDay/subclassing-ignored': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/startOfDay/timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/startOfDay/timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/startOfDay/timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/ZonedDateTime/prototype/startOfDay/timezone-getoffsetnanosecondsfor-wrong-type': [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],
......
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