|
@@ -7,9 +7,11 @@
|
|
|
|
|
|
#include <AK/TypeCasts.h>
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
+#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
|
|
#include <LibJS/Runtime/Temporal/Calendar.h>
|
|
|
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
|
|
#include <LibJS/Runtime/Temporal/PlainDatePrototype.h>
|
|
|
+#include <LibJS/Runtime/Temporal/PlainYearMonth.h>
|
|
|
|
|
|
namespace JS::Temporal {
|
|
|
|
|
@@ -43,6 +45,7 @@ void PlainDatePrototype::initialize(GlobalObject& global_object)
|
|
|
define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable);
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
|
+ define_native_function(vm.names.toPlainYearMonth, to_plain_year_month, 0, attr);
|
|
|
define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr);
|
|
|
define_native_function(vm.names.withCalendar, with_calendar, 1, attr);
|
|
|
define_native_function(vm.names.equals, equals, 1, attr);
|
|
@@ -267,6 +270,32 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::in_leap_year_getter)
|
|
|
return Value(calendar_in_leap_year(global_object, calendar, *temporal_date));
|
|
|
}
|
|
|
|
|
|
+// 3.3.16 Temporal.PlainDate.prototype.toPlainYearMonth ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.toplainyearmonth
|
|
|
+JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_year_month)
|
|
|
+{
|
|
|
+ // 1. Let temporalDate be the this value.
|
|
|
+ // 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]).
|
|
|
+ auto* temporal_date = typed_this(global_object);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 3. Let calendar be temporalDate.[[Calendar]].
|
|
|
+ auto& calendar = temporal_date->calendar();
|
|
|
+
|
|
|
+ // 4. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
|
|
|
+ auto field_names = calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv });
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 5. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
|
|
|
+ auto* fields = prepare_temporal_fields(global_object, *temporal_date, field_names, {});
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 6. Return ? YearMonthFromFields(calendar, fields).
|
|
|
+ return year_month_from_fields(global_object, calendar, *fields);
|
|
|
+}
|
|
|
+
|
|
|
// 3.3.18 Temporal.PlainDate.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.getisofields
|
|
|
JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields)
|
|
|
{
|