summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-07-06 23:54:53 +0100
committerLinus Groh <mail@linusgroh.de>2021-07-07 00:42:01 +0100
commit6cd16eceb3adae39919f5d56b4226667423581d1 (patch)
tree0856cf3d0a754242664a8c5ff9292000a372683f /Userland
parent265e89367e66203702a04774feb01ed319820924 (diff)
downloadserenity-6cd16eceb3adae39919f5d56b4226667423581d1.zip
LibJS: Implement Temporal.now.timeZone()
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp23
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.h5
3 files changed, 29 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
index 35bdc71e9b..8f0a484f6a 100644
--- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
+++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
@@ -300,6 +300,7 @@ namespace JS {
P(tanh) \
P(test) \
P(then) \
+ P(timeZone) \
P(toDateString) \
P(toFixed) \
P(toGMTString) \
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
index b372cb236b..1d3be0ad61 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
@@ -6,6 +6,7 @@
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Temporal/Now.h>
+#include <LibJS/Runtime/Temporal/TimeZone.h>
namespace JS::Temporal {
@@ -18,6 +19,28 @@ Now::Now(GlobalObject& global_object)
void Now::initialize(GlobalObject& global_object)
{
Object::initialize(global_object);
+
+ auto& vm = this->vm();
+ u8 attr = Attribute::Writable | Attribute::Configurable;
+
+ define_native_function(vm.names.timeZone, time_zone, 0, attr);
+}
+
+// 2.1.1 Temporal.now.timeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.timezone
+JS_DEFINE_NATIVE_FUNCTION(Now::time_zone)
+{
+ // 1. Return ? SystemTimeZone().
+ return system_time_zone(global_object);
+}
+
+// 2.2.1 SystemTimeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone
+Object* system_time_zone(GlobalObject& global_object)
+{
+ // 1. Let identifier be ! DefaultTimeZone().
+ auto identifier = default_time_zone();
+
+ // 2. Return ? CreateTemporalTimeZone(identifier).
+ return create_temporal_time_zone(global_object, identifier);
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.h b/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
index 1f0ec308f3..c04a5013bb 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
@@ -17,6 +17,11 @@ public:
explicit Now(GlobalObject&);
virtual void initialize(GlobalObject&) override;
virtual ~Now() override = default;
+
+private:
+ JS_DECLARE_NATIVE_FUNCTION(time_zone);
};
+Object* system_time_zone(GlobalObject&);
+
}