summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-14 16:40:41 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-15 21:20:33 +0100
commit093331df06b15a5635ec9e0a76840a8e99787449 (patch)
tree6bed3e7d2b3c2a5cb0a5758a8964a8c51775d090
parent36ea9fbd9eedfa76cb0e068e0b48d09918109f3c (diff)
downloadserenity-093331df06b15a5635ec9e0a76840a8e99787449.zip
LibJS: Add Date.prototype.toGMTString()
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.h1
5 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
index 07e577d1f4..f77911048e 100644
--- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
+++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
@@ -220,6 +220,7 @@ namespace JS {
P(tanh) \
P(test) \
P(toDateString) \
+ P(toGMTString) \
P(toISOString) \
P(toJSON) \
P(toLocaleDateString) \
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index ced1a58009..8644de4ad0 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -91,6 +91,13 @@ int Date::utc_seconds() const
return to_utc_tm().tm_sec;
}
+String Date::gmt_date_string() const
+{
+ // Mon, 18 Dec 1995 17:28:35 GMT
+ // FIXME: Note that we're totally cheating with the timezone part here..
+ return datetime().to_string("%a, %e %b %Y %T GMT");
+}
+
String Date::iso_date_string() const
{
auto tm = to_utc_tm();
diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h
index 368cc91bc2..550e3acf26 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.h
+++ b/Userland/Libraries/LibJS/Runtime/Date.h
@@ -71,6 +71,7 @@ public:
return String::formatted("{} {}", date_string(), time_string());
}
+ String gmt_date_string() const;
String iso_date_string() const;
// FIXME: One day, implement real locale support. Until then, everyone gets what the Clock MenuApplet displays.
diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
index a1002ce90e..ff262fcf44 100644
--- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
@@ -76,6 +76,7 @@ void DatePrototype::initialize(GlobalObject& global_object)
define_native_function(vm.names.getUTCMonth, get_utc_month, 0, attr);
define_native_function(vm.names.getUTCSeconds, get_utc_seconds, 0, attr);
define_native_function(vm.names.toDateString, to_date_string, 0, attr);
+ define_native_function(vm.names.toGMTString, to_gmt_string, 0, attr);
define_native_function(vm.names.toISOString, to_iso_string, 0, attr);
define_native_function(vm.names.toLocaleDateString, to_locale_date_string, 0, attr);
define_native_function(vm.names.toLocaleString, to_locale_string, 0, attr);
@@ -256,6 +257,15 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
return js_string(vm, move(string));
}
+JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string)
+{
+ auto* this_object = typed_this(vm, global_object);
+ if (!this_object)
+ return {};
+ auto string = this_object->gmt_date_string();
+ return js_string(vm, move(string));
+}
+
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
{
auto* this_object = typed_this(vm, global_object);
diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.h b/Userland/Libraries/LibJS/Runtime/DatePrototype.h
index b0891367f1..4bdfcf4350 100644
--- a/Userland/Libraries/LibJS/Runtime/DatePrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.h
@@ -58,6 +58,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(get_utc_month);
JS_DECLARE_NATIVE_FUNCTION(get_utc_seconds);
JS_DECLARE_NATIVE_FUNCTION(to_date_string);
+ JS_DECLARE_NATIVE_FUNCTION(to_gmt_string);
JS_DECLARE_NATIVE_FUNCTION(to_iso_string);
JS_DECLARE_NATIVE_FUNCTION(to_locale_date_string);
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);