diff options
author | Linus Groh <mail@linusgroh.de> | 2021-08-01 17:59:20 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-01 20:31:31 +0100 |
commit | 4640643019f861e9c46c98cf04e69c11975d03d8 (patch) | |
tree | 5b24a18a97c150ca195aed1f351d39188a594708 /Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp | |
parent | 6f75dcc7b8e77c988164718a2b95caa4b3fc1715 (diff) | |
download | serenity-4640643019f861e9c46c98cf04e69c11975d03d8.zip |
LibJS: Handle ZonedDateTime in ToTemporalDate
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index 9259d168d5..d5113409ff 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -8,10 +8,13 @@ #include <LibJS/Runtime/AbstractOperations.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Temporal/Calendar.h> +#include <LibJS/Runtime/Temporal/Instant.h> #include <LibJS/Runtime/Temporal/PlainDate.h> #include <LibJS/Runtime/Temporal/PlainDateConstructor.h> #include <LibJS/Runtime/Temporal/PlainDateTime.h> #include <LibJS/Runtime/Temporal/PlainYearMonth.h> +#include <LibJS/Runtime/Temporal/TimeZone.h> +#include <LibJS/Runtime/Temporal/ZonedDateTime.h> namespace JS::Temporal { @@ -89,10 +92,20 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt } // b. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then - // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). - // ii. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]). - // iii. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainDateTime.[[Calendar]]). - // TODO + if (is<ZonedDateTime>(item_object)) { + auto& zoned_date_time = static_cast<ZonedDateTime&>(item_object); + + // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). + auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()); + + // ii. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]). + auto* plain_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()); + if (vm.exception()) + return {}; + + // iii. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainDateTime.[[Calendar]]). + return create_temporal_date(global_object, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_date_time->calendar()); + } // c. If item has an [[InitializedTemporalDateTime]] internal slot, then if (is<PlainDateTime>(item_object)) { |