mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:17:35 +00:00
LibJS: Implement Temporal.PlainDateTime.prototype.toPlainDate()
This commit is contained in:
parent
61b2780853
commit
18fd0d4011
4 changed files with 28 additions and 0 deletions
|
@ -348,6 +348,7 @@ namespace JS {
|
||||||
P(toLocaleString) \
|
P(toLocaleString) \
|
||||||
P(toLocaleTimeString) \
|
P(toLocaleTimeString) \
|
||||||
P(toLowerCase) \
|
P(toLowerCase) \
|
||||||
|
P(toPlainDate) \
|
||||||
P(toString) \
|
P(toString) \
|
||||||
P(toTemporalInstant) \
|
P(toTemporalInstant) \
|
||||||
P(toTimeString) \
|
P(toTimeString) \
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
|
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||||
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
||||||
#include <LibJS/Runtime/Temporal/PlainDateTimePrototype.h>
|
#include <LibJS/Runtime/Temporal/PlainDateTimePrototype.h>
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||||
|
define_native_function(vm.names.toPlainDate, to_plain_date, 0, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlainDateTime* typed_this(GlobalObject& global_object)
|
static PlainDateTime* typed_this(GlobalObject& global_object)
|
||||||
|
@ -65,4 +67,17 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5.3.37 Temporal.PlainDateTime.prototype.toPlainDate ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.toplaindate
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_date)
|
||||||
|
{
|
||||||
|
// 1. Let dateTime be the this value.
|
||||||
|
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||||
|
auto* date_time = typed_this(global_object);
|
||||||
|
if (vm.exception())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Return ? CreateTemporalDate(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[Calendar]]).
|
||||||
|
return create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(to_plain_date);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
describe("normal behavior", () => {
|
||||||
|
test("length is 0", () => {
|
||||||
|
expect(Temporal.PlainDateTime.prototype.toPlainDate).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("basic functionality", () => {
|
||||||
|
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 23, 0, 32, 18, 123, 456, 789);
|
||||||
|
const plainDate = plainDateTime.toPlainDate();
|
||||||
|
expect(plainDate.equals(new Temporal.PlainDate(2021, 7, 23))).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue