mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibJS: Implement Temporal.PlainDate.compare
This commit is contained in:
parent
2c6bd3a61b
commit
07485802c6
5 changed files with 67 additions and 0 deletions
|
@ -27,6 +27,9 @@ void PlainDateConstructor::initialize(GlobalObject& global_object)
|
|||
// 3.2.1 Temporal.PlainDate.prototype, https://tc39.es/proposal-temporal/#sec-temporal-plaindate-prototype
|
||||
define_direct_property(vm.names.prototype, global_object.temporal_plain_date_prototype(), 0);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.compare, compare, 2, attr);
|
||||
|
||||
define_direct_property(vm.names.length, Value(3), Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
@ -93,4 +96,19 @@ Value PlainDateConstructor::construct(FunctionObject& new_target)
|
|||
return create_temporal_date(global_object, y, m, d, *calendar, &new_target);
|
||||
}
|
||||
|
||||
// 3.2.3 Temporal.PlainDate.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindate-constructor
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::compare)
|
||||
{
|
||||
// 1. Set one to ? ToTemporalDate(one).
|
||||
auto* one = to_temporal_date(global_object, vm.argument(0));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
// 2. Set two to ? ToTemporalDate(two).
|
||||
auto* two = to_temporal_date(global_object, vm.argument(1));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
// 3. Return 𝔽(! CompareISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]])).
|
||||
return Value(compare_iso_date(one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue