diff options
author | Linus Groh <mail@linusgroh.de> | 2021-07-27 00:30:10 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-27 19:51:44 +0100 |
commit | f2a2e8e13cd7f88f66df4d4c420fc449911b027d (patch) | |
tree | ac3029f86cc1fc2a72d9d6536a8196a1be341717 /Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp | |
parent | c303bbde5430c8d889853ae112d50275b57f74c5 (diff) | |
download | serenity-f2a2e8e13cd7f88f66df4d4c420fc449911b027d.zip |
LibJS: Implement Temporal.Now.plainDateISO()
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp index f33e1c3529..5f702ad883 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp @@ -35,6 +35,7 @@ void Now::initialize(GlobalObject& global_object) define_native_function(vm.names.timeZone, time_zone, 0, attr); define_native_function(vm.names.instant, instant, 0, attr); define_native_function(vm.names.plainDate, plain_date, 1, attr); + define_native_function(vm.names.plainDateISO, plain_date_iso, 0, attr); } // 2.1.1 Temporal.Now.timeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.timezone @@ -66,6 +67,25 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_date) return create_temporal_date(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->calendar()); } +// 2.1.8 Temporal.Now.plainDateISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindateiso +JS_DEFINE_NATIVE_FUNCTION(Now::plain_date_iso) +{ + auto temporal_time_zone_like = vm.argument(0); + + // 1. Let calendar be ? GetISO8601Calendar(). + auto* calendar = get_iso8601_calendar(global_object); + if (vm.exception()) + return {}; + + // 2. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar). + auto* date_time = system_date_time(global_object, temporal_time_zone_like, calendar); + 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()); +} + // 2.2.1 SystemTimeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone TimeZone* system_time_zone(GlobalObject& global_object) { |