mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +00:00
LibJS: Handle ZonedDateTime in ToTemporalInstant
This commit is contained in:
parent
1f5098f61e
commit
6f75dcc7b8
2 changed files with 14 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <LibJS/Runtime/Temporal/InstantConstructor.h>
|
#include <LibJS/Runtime/Temporal/InstantConstructor.h>
|
||||||
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
||||||
#include <LibJS/Runtime/Temporal/TimeZone.h>
|
#include <LibJS/Runtime/Temporal/TimeZone.h>
|
||||||
|
#include <LibJS/Runtime/Temporal/ZonedDateTime.h>
|
||||||
|
|
||||||
namespace JS::Temporal {
|
namespace JS::Temporal {
|
||||||
|
|
||||||
|
@ -81,9 +82,14 @@ Instant* to_temporal_instant(GlobalObject& global_object, Value item)
|
||||||
// i. Return item.
|
// i. Return item.
|
||||||
return &static_cast<Instant&>(item.as_object());
|
return &static_cast<Instant&>(item.as_object());
|
||||||
}
|
}
|
||||||
// TODO:
|
|
||||||
// b. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then
|
// b. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then
|
||||||
|
if (is<ZonedDateTime>(item.as_object())) {
|
||||||
|
auto& zoned_date_time = static_cast<ZonedDateTime&>(item.as_object());
|
||||||
|
|
||||||
// i. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
|
// i. Return ! CreateTemporalInstant(item.[[Nanoseconds]]).
|
||||||
|
return create_temporal_instant(global_object, zoned_date_time.nanoseconds());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Let string be ? ToString(item).
|
// 2. Let string be ? ToString(item).
|
||||||
|
|
|
@ -8,6 +8,12 @@ describe("correct behavior", () => {
|
||||||
expect(Temporal.Instant.from(instant).epochNanoseconds).toBe(123n);
|
expect(Temporal.Instant.from(instant).epochNanoseconds).toBe(123n);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("ZonedDateTime instance argument", () => {
|
||||||
|
const timeZone = new Temporal.TimeZone("UTC");
|
||||||
|
const zonedDateTime = new Temporal.ZonedDateTime(123n, timeZone);
|
||||||
|
expect(Temporal.Instant.from(zonedDateTime).epochNanoseconds).toBe(123n);
|
||||||
|
});
|
||||||
|
|
||||||
// Un-skip once ParseISODateTime & ParseTemporalTimeZoneString are implemented
|
// Un-skip once ParseISODateTime & ParseTemporalTimeZoneString are implemented
|
||||||
test.skip("Instant string argument", () => {
|
test.skip("Instant string argument", () => {
|
||||||
expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z").epochNanoseconds).toBe(
|
expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z").epochNanoseconds).toBe(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue