[Temporal] Add Calendar.prototype.dayOfYear

Also add AO: ToISODayOfYear
Spec Text:
https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dayofyear
https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear

Note- this is only the non-intl version. intl version in
https://tc39.es/proposal-temporal/#sup-temporal.calendar.prototype.dayofyear
will be implemented in later cl.



Bug: v8:11544
Change-Id: I5e5f9ea93cc0577df8d9b228efe5c3a97d118b88
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531566
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79681}
This commit is contained in:
Frank Tang 2022-03-26 23:19:28 -07:00 committed by V8 LUCI CQ
parent ac4c2afc7f
commit eb9a19a0a1
5 changed files with 48 additions and 13 deletions

View File

@ -324,8 +324,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthCode)
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDay)
/* Temporal #sec-temporal.calendar.prototype.dayofweek */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDayOfWeek)
/* Temporal #sec-temporal.calendar.prototype.dayofyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDayOfYear)
/* Temporal #sec-temporal.calendar.prototype.weekofyear */
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
/* Temporal #sec-temporal.calendar.prototype.daysinweek */
@ -802,6 +800,7 @@ TEMPORAL_CONSTRUCTOR1(Calendar)
TEMPORAL_ID_BY_TO_STRING(Calendar)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, Year, year)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DaysInYear, daysInYear)
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfYear, dayOfYear)
TEMPORAL_TO_STRING(Calendar)
// #sec-temporal.calendar.from
BUILTIN(TemporalCalendarFrom) {

View File

@ -4789,6 +4789,24 @@ MaybeHandle<JSTemporalCalendar> JSTemporalCalendar::Constructor(
return CreateTemporalCalendar(isolate, target, new_target, identifier);
}
namespace {
// #sec-temporal-toisodayofyear
int32_t ToISODayOfYear(Isolate* isolate, int32_t year, int32_t month,
int32_t day) {
TEMPORAL_ENTER_FUNC();
// 1. Assert: year is an integer.
// 2. Assert: month is an integer.
// 3. Assert: day is an integer.
// 4. Let date be the date given by year, month, and day.
// 5. Return date's ordinal date in the year according to ISO-8601.
return day + isolate->date_cache()->DaysFromYearMonth(year, month - 1) -
isolate->date_cache()->DaysFromYearMonth(year, 0);
}
} // namespace
// #sec-temporal.calendar.prototype.daysinyear
MaybeHandle<Smi> JSTemporalCalendar::DaysInYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
@ -4870,6 +4888,30 @@ MaybeHandle<Smi> JSTemporalCalendar::Year(Isolate* isolate,
return handle(Smi::FromInt(year), isolate);
}
// #sec-temporal.calendar.prototype.dayofyear
MaybeHandle<Smi> JSTemporalCalendar::DayOfYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like) {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar,
// [[InitializedTemporalCalendar]]).
// 3. Assert: calendar.[[Identifier]] is "iso8601".
// 4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
Handle<JSTemporalPlainDate> temporal_date;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, temporal_date,
ToTemporalDate(isolate, temporal_date_like,
isolate->factory()->NewJSObjectWithNullProto(),
"Temporal.Calendar.prototype.dayOfYear"),
Smi);
// a. Let value be ! ToISODayOfYear(temporalDate.[[ISOYear]],
// temporalDate.[[ISOMonth]], temporalDate.[[ISODay]]).
int32_t value =
ToISODayOfYear(isolate, temporal_date->iso_year(),
temporal_date->iso_month(), temporal_date->iso_day());
return handle(Smi::FromInt(value), isolate);
}
// #sec-temporal.calendar.prototype.tostring
MaybeHandle<String> JSTemporalCalendar::ToString(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,

View File

@ -62,6 +62,11 @@ class JSTemporalCalendar
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.dayofyear
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DayOfYear(
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
Handle<Object> temporal_date_like);
// #sec-temporal.calendar.prototype.tostring
static MaybeHandle<String> ToString(Isolate* isolate,
Handle<JSTemporalCalendar> calendar,

View File

@ -49,7 +49,6 @@
'temporal/calendar-date-until': [FAIL],
'temporal/calendar-day': [FAIL],
'temporal/calendar-day-of-week': [FAIL],
'temporal/calendar-day-of-year': [FAIL],
'temporal/calendar-days-in-month': [FAIL],
'temporal/calendar-days-in-week': [FAIL],
'temporal/calendar-fields': [FAIL],

View File

@ -502,20 +502,10 @@
'built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfWeek/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfWeek/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/basic': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/branding': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/calendar-temporal-object': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/plain-date-time': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/string': [FAIL],
'built-ins/Temporal/Calendar/prototype/dayOfYear/throw-range-error-ToTemporalDate': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/Calendar/prototype/daysInMonth/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],