[Temporal] Add Calendar.prototype.dayOfWeek
Also add AO: ToISODayOfWeek Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.dayofweek https://tc39.es/proposal-temporal/#sec-temporal-toisodayofweek Note- this is only the non-intl version. intl version in https://tc39.es/proposal-temporal/#sup-temporal.calendar.prototype.dayofweek will be implemented in later cl. Bug: v8:11544 Change-Id: I0b3448209741e4aa56cd8170a331d837853bff17 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3531564 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#79698}
This commit is contained in:
parent
db44515379
commit
3f3a427f48
@ -322,8 +322,6 @@ TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonth)
|
||||
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeMonthCode)
|
||||
/* Temporal #sec-temporal.calendar.prototype.day */
|
||||
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDay)
|
||||
/* Temporal #sec-temporal.calendar.prototype.dayofweek */
|
||||
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeDayOfWeek)
|
||||
/* Temporal #sec-temporal.calendar.prototype.weekofyear */
|
||||
TO_BE_IMPLEMENTED(TemporalCalendarPrototypeWeekOfYear)
|
||||
/* Temporal #sec-temporal.calendar.prototype.daysinweek */
|
||||
@ -798,6 +796,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, DayOfWeek, dayOfWeek)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(Calendar, DayOfYear, dayOfYear)
|
||||
TEMPORAL_PROTOTYPE_METHOD1(Calendar, MonthsInYear, monthsInYear)
|
||||
TEMPORAL_TO_STRING(Calendar)
|
||||
|
@ -4801,6 +4801,8 @@ int32_t ToISODayOfYear(Isolate* isolate, int32_t year, int32_t month,
|
||||
// 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.
|
||||
// Note: In ISO 8601, Jan: month=1, Dec: month=12,
|
||||
// In DateCache API, Jan: month=0, Dec: month=11 so we need to - 1 for month.
|
||||
return day + isolate->date_cache()->DaysFromYearMonth(year, month - 1) -
|
||||
isolate->date_cache()->DaysFromYearMonth(year, 0);
|
||||
}
|
||||
@ -4811,6 +4813,30 @@ bool IsPlainDatePlainDateTimeOrPlainYearMonth(
|
||||
temporal_date_like->IsJSTemporalPlainDateTime() ||
|
||||
temporal_date_like->IsJSTemporalPlainYearMonth();
|
||||
}
|
||||
|
||||
// #sec-temporal-toisodayofweek
|
||||
int32_t ToISODayOfWeek(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 day of the week according to ISO-8601.
|
||||
// Note: In ISO 8601, Jan: month=1, Dec: month=12.
|
||||
// In DateCache API, Jan: month=0, Dec: month=11 so we need to - 1 for month.
|
||||
// Weekday() expect "the number of days since the epoch" as input and the
|
||||
// value of day is 1-based so we need to minus 1 to calculate "the number of
|
||||
// days" because the number of days on the epoch (1970/1/1) should be 0,
|
||||
// not 1.
|
||||
int32_t weekday = isolate->date_cache()->Weekday(
|
||||
isolate->date_cache()->DaysFromYearMonth(year, month - 1) + day - 1);
|
||||
// Note: In ISO 8601, Sun: weekday=7 Mon: weekday=1
|
||||
// In DateCache API, Sun: weekday=0 Mon: weekday=1
|
||||
return weekday == 0 ? 7 : weekday;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// #sec-temporal.calendar.prototype.daysinyear
|
||||
@ -4914,6 +4940,30 @@ MaybeHandle<Smi> JSTemporalCalendar::DayOfYear(
|
||||
return handle(Smi::FromInt(value), isolate);
|
||||
}
|
||||
|
||||
// #sec-temporal.calendar.prototype.dayofweek
|
||||
MaybeHandle<Smi> JSTemporalCalendar::DayOfWeek(
|
||||
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.dayOfWeek"),
|
||||
Smi);
|
||||
// a. Let value be ! ToISODayOfWeek(temporalDate.[[ISOYear]],
|
||||
// temporalDate.[[ISOMonth]], temporalDate.[[ISODay]]).
|
||||
int32_t value =
|
||||
ToISODayOfWeek(isolate, temporal_date->iso_year(),
|
||||
temporal_date->iso_month(), temporal_date->iso_day());
|
||||
return handle(Smi::FromInt(value), isolate);
|
||||
}
|
||||
|
||||
// #sec-temporal.calendar.prototype.monthsinyear
|
||||
MaybeHandle<Smi> JSTemporalCalendar::MonthsInYear(
|
||||
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
|
||||
|
@ -62,6 +62,11 @@ class JSTemporalCalendar
|
||||
Isolate* isolate, Handle<JSTemporalCalendar> calendar,
|
||||
Handle<Object> temporal_date_like);
|
||||
|
||||
// #sec-temporal.calendar.prototype.dayofweek
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> DayOfWeek(
|
||||
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,
|
||||
|
@ -48,7 +48,6 @@
|
||||
'temporal/calendar-date-from-fields': [FAIL],
|
||||
'temporal/calendar-date-until': [FAIL],
|
||||
'temporal/calendar-day': [FAIL],
|
||||
'temporal/calendar-day-of-week': [FAIL],
|
||||
'temporal/calendar-days-in-month': [FAIL],
|
||||
'temporal/calendar-days-in-week': [FAIL],
|
||||
'temporal/calendar-fields': [FAIL],
|
||||
|
@ -488,20 +488,10 @@
|
||||
'built-ins/Temporal/Calendar/prototype/day/date-time': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/day/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/day/month-day': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-with-utc-designator': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/basic': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/branding': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/calendar-fields-iterable': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/calendar-temporal-object': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfWeek/plain-date': [FAIL],
|
||||
'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/basic': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfYear/calendar-fields-iterable': [FAIL],
|
||||
'built-ins/Temporal/Calendar/prototype/dayOfYear/calendar-temporal-object': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user