mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +00:00
LibJS: Implement Temporal.Now.plainDate()
...and ten required AOs we didn't have yet: - BalanceISODate - BalanceISODateTime - BalanceISOYearMonth - BalanceTime - BuiltinTimeZoneGetPlainDateTimeFor - GetISOPartsFromEpoch - GetOffsetNanosecondsFor - ParseTemporalTimeZone - SystemDateTime - ToTemporalTimeZone
This commit is contained in:
parent
5512ff79f0
commit
c303bbde54
18 changed files with 507 additions and 1 deletions
|
@ -6,8 +6,11 @@
|
|||
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||
#include <LibJS/Runtime/Temporal/Instant.h>
|
||||
#include <LibJS/Runtime/Temporal/Now.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
||||
#include <LibJS/Runtime/Temporal/TimeZone.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -31,6 +34,7 @@ void Now::initialize(GlobalObject& global_object)
|
|||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
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);
|
||||
}
|
||||
|
||||
// 2.1.1 Temporal.Now.timeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.timezone
|
||||
|
@ -47,6 +51,21 @@ JS_DEFINE_NATIVE_FUNCTION(Now::instant)
|
|||
return system_instant(global_object);
|
||||
}
|
||||
|
||||
// 2.1.7 Temporal.Now.plainDate ( calendar [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindate
|
||||
JS_DEFINE_NATIVE_FUNCTION(Now::plain_date)
|
||||
{
|
||||
auto calendar = vm.argument(0);
|
||||
auto temporal_time_zone_like = vm.argument(1);
|
||||
|
||||
// 1. Let dateTime be ? SystemDateTime(temporalTimeZoneLike, calendar).
|
||||
auto* date_time = system_date_time(global_object, temporal_time_zone_like, calendar);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 2. 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)
|
||||
{
|
||||
|
@ -90,4 +109,33 @@ Instant* system_instant(GlobalObject& global_object)
|
|||
return create_temporal_instant(global_object, *ns);
|
||||
}
|
||||
|
||||
// 2.2.4 SystemDateTime ( temporalTimeZoneLike, calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-systemdatetime
|
||||
PlainDateTime* system_date_time(GlobalObject& global_object, Value temporal_time_zone_like, Value calendar_like)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
Object* time_zone;
|
||||
|
||||
// 1. If temporalTimeZoneLike is undefined, then
|
||||
if (temporal_time_zone_like.is_undefined()) {
|
||||
// a. Let timeZone be ! SystemTimeZone().
|
||||
time_zone = system_time_zone(global_object);
|
||||
} else {
|
||||
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
|
||||
time_zone = to_temporal_time_zone(global_object, temporal_time_zone_like);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
|
||||
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
|
||||
auto* calendar = to_temporal_calendar(global_object, calendar_like);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 4. Let instant be ! SystemInstant().
|
||||
auto* instant = system_instant(global_object);
|
||||
|
||||
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
|
||||
return builtin_time_zone_get_plain_date_time_for(global_object, *time_zone, *instant, *calendar);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue