summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp13
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.h1
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.zonedDateTimeISO.js19
4 files changed, 35 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
index b9d2ae05dd..8ead23741b 100644
--- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
+++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
@@ -414,7 +414,8 @@ namespace JS {
P(writable) \
P(year) \
P(years) \
- P(zonedDateTime)
+ P(zonedDateTime) \
+ P(zonedDateTimeISO)
struct CommonPropertyNames {
PropertyName and_ { "and", PropertyName::StringMayBeNumber::No };
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
index 2a087cd179..b2797cf6b1 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
@@ -39,6 +39,7 @@ void Now::initialize(GlobalObject& global_object)
define_native_function(vm.names.plainDateTime, plain_date_time, 1, attr);
define_native_function(vm.names.plainDateTimeISO, plain_date_time_iso, 0, attr);
define_native_function(vm.names.zonedDateTime, zoned_date_time, 1, attr);
+ define_native_function(vm.names.zonedDateTimeISO, zoned_date_time_iso, 0, attr);
define_native_function(vm.names.plainDate, plain_date, 1, attr);
define_native_function(vm.names.plainDateISO, plain_date_iso, 0, attr);
define_native_function(vm.names.plainTimeISO, plain_time_iso, 0, attr);
@@ -90,6 +91,18 @@ JS_DEFINE_NATIVE_FUNCTION(Now::zoned_date_time)
return system_zoned_date_time(global_object, temporal_time_zone_like, calendar);
}
+// 2.2.6 Temporal.Now.zonedDateTimeISO ( [ temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.zoneddatetimeiso
+JS_DEFINE_NATIVE_FUNCTION(Now::zoned_date_time_iso)
+{
+ auto temporal_time_zone_like = vm.argument(0);
+
+ // 1, Let calendar be ! GetISO8601Calendar().
+ auto* calendar = get_iso8601_calendar(global_object);
+
+ // 2. Return ? SystemZonedDateTime(temporalTimeZoneLike, calendar).
+ return system_zoned_date_time(global_object, temporal_time_zone_like, calendar);
+}
+
// 2.2.7 Temporal.Now.plainDate ( calendar [ , temporalTimeZoneLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.now.plaindate
JS_DEFINE_NATIVE_FUNCTION(Now::plain_date)
{
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.h b/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
index a2f3e4b055..989a0d69ad 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
@@ -24,6 +24,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(plain_date_time);
JS_DECLARE_NATIVE_FUNCTION(plain_date_time_iso);
JS_DECLARE_NATIVE_FUNCTION(zoned_date_time);
+ JS_DECLARE_NATIVE_FUNCTION(zoned_date_time_iso);
JS_DECLARE_NATIVE_FUNCTION(plain_date);
JS_DECLARE_NATIVE_FUNCTION(plain_date_iso);
JS_DECLARE_NATIVE_FUNCTION(plain_time_iso);
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.zonedDateTimeISO.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.zonedDateTimeISO.js
new file mode 100644
index 0000000000..c5b26d19bc
--- /dev/null
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.zonedDateTimeISO.js
@@ -0,0 +1,19 @@
+describe("correct behavior", () => {
+ test("length is 0", () => {
+ expect(Temporal.Now.zonedDateTimeISO).toHaveLength(0);
+ });
+
+ test("basic functionality", () => {
+ const zonedDateTime = Temporal.Now.zonedDateTimeISO();
+ expect(zonedDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
+ expect(zonedDateTime.calendar.id).toBe("iso8601");
+ });
+
+ test("with time zone", () => {
+ const timeZone = new Temporal.TimeZone("UTC");
+ const zonedDateTime = Temporal.Now.zonedDateTimeISO(timeZone);
+ expect(zonedDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
+ expect(zonedDateTime.calendar.id).toBe("iso8601");
+ expect(zonedDateTime.timeZone).toBe(timeZone);
+ });
+});