1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

LibJS: Implement Temporal.PlainDate.prototype.era

This commit is contained in:
Linus Groh 2021-08-27 20:03:41 +01:00
parent c3e0d78ba6
commit 6f7d6d917e
5 changed files with 67 additions and 0 deletions

View file

@ -288,6 +288,30 @@ Value calendar_in_leap_year(GlobalObject& global_object, Object& calendar, Objec
return Value(&calendar).invoke(global_object, vm.names.inLeapYear, &date_like);
}
// 15.6.1.2 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
Value calendar_era(GlobalObject& global_object, Object& calendar, Object& date_like)
{
auto& vm = global_object.vm();
// 1. Assert: Type(calendar) is Object.
// 2. Let result be ? Invoke(calendar, "era", « dateLike »).
auto result = Value(&calendar).invoke(global_object, vm.names.era, &date_like);
if (vm.exception())
return {};
// 3. If result is not undefined, set result to ? ToString(result).
if (!result.is_undefined()) {
auto result_string = result.to_string(global_object);
if (vm.exception())
return {};
result = js_string(vm, move(result_string));
}
// 4. Return result.
return result;
}
// 12.1.21 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
Object* to_temporal_calendar(GlobalObject& global_object, Value temporal_calendar_like)
{