Skip to content

Commit 6cd16ec

Browse files
committed
LibJS: Implement Temporal.now.timeZone()
1 parent 265e893 commit 6cd16ec

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ namespace JS {
300300
P(tanh) \
301301
P(test) \
302302
P(then) \
303+
P(timeZone) \
303304
P(toDateString) \
304305
P(toFixed) \
305306
P(toGMTString) \

Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <LibJS/Runtime/GlobalObject.h>
88
#include <LibJS/Runtime/Temporal/Now.h>
9+
#include <LibJS/Runtime/Temporal/TimeZone.h>
910

1011
namespace JS::Temporal {
1112

@@ -18,6 +19,28 @@ Now::Now(GlobalObject& global_object)
1819
void Now::initialize(GlobalObject& global_object)
1920
{
2021
Object::initialize(global_object);
22+
23+
auto& vm = this->vm();
24+
u8 attr = Attribute::Writable | Attribute::Configurable;
25+
26+
define_native_function(vm.names.timeZone, time_zone, 0, attr);
27+
}
28+
29+
// 2.1.1 Temporal.now.timeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal.now.timezone
30+
JS_DEFINE_NATIVE_FUNCTION(Now::time_zone)
31+
{
32+
// 1. Return ? SystemTimeZone().
33+
return system_time_zone(global_object);
34+
}
35+
36+
// 2.2.1 SystemTimeZone ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone
37+
Object* system_time_zone(GlobalObject& global_object)
38+
{
39+
// 1. Let identifier be ! DefaultTimeZone().
40+
auto identifier = default_time_zone();
41+
42+
// 2. Return ? CreateTemporalTimeZone(identifier).
43+
return create_temporal_time_zone(global_object, identifier);
2144
}
2245

2346
}

Userland/Libraries/LibJS/Runtime/Temporal/Now.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Now final : public Object {
1717
explicit Now(GlobalObject&);
1818
virtual void initialize(GlobalObject&) override;
1919
virtual ~Now() override = default;
20+
21+
private:
22+
JS_DECLARE_NATIVE_FUNCTION(time_zone);
2023
};
2124

25+
Object* system_time_zone(GlobalObject&);
26+
2227
}

0 commit comments

Comments
 (0)