mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibJS: Implement Temporal.TimeZone.prototype.getInstantFor()
This commit is contained in:
parent
55e1edd51b
commit
97f6c6029f
15 changed files with 341 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||
#include <LibJS/Runtime/Temporal/CalendarConstructor.h>
|
||||
#include <LibJS/Runtime/Temporal/Duration.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainMonthDay.h>
|
||||
|
@ -135,6 +136,29 @@ ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject& global_object, Ob
|
|||
return &result.as_object();
|
||||
}
|
||||
|
||||
// 12.1.7 CalendarDateAdd ( calendar, date, duration, options [ , dateAdd ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateadd
|
||||
ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject& global_object, Object& calendar, PlainDate& date, Duration& duration, Object* options, FunctionObject* date_add)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: Type(calendar) is Object.
|
||||
|
||||
// 2. If dateAdd is not present, set dateAdd to ? GetMethod(calendar, "dateAdd").
|
||||
if (!date_add)
|
||||
date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd));
|
||||
|
||||
// 3. Let addedDate be ? Call(dateAdd, calendar, « date, duration, options »).
|
||||
auto added_date = TRY(call(global_object, date_add ?: js_undefined(), &calendar, &date, &duration, options ?: js_undefined()));
|
||||
|
||||
// 4. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]).
|
||||
auto* added_date_object = TRY(added_date.to_object(global_object));
|
||||
if (!is<PlainDate>(added_date_object))
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Temporal.PlainDate");
|
||||
|
||||
// 5. Return addedDate.
|
||||
return static_cast<PlainDate*>(added_date_object);
|
||||
}
|
||||
|
||||
// 12.1.9 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
|
||||
ThrowCompletionOr<double> calendar_year(GlobalObject& global_object, Object& calendar, Object& date_like)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue