1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +00:00

LibJS: Add Date.prototype.toGMTString()

This commit is contained in:
Andreas Kling 2021-03-14 16:40:41 +01:00
parent 36ea9fbd9e
commit 093331df06
5 changed files with 20 additions and 0 deletions

View file

@ -220,6 +220,7 @@ namespace JS {
P(tanh) \
P(test) \
P(toDateString) \
P(toGMTString) \
P(toISOString) \
P(toJSON) \
P(toLocaleDateString) \

View file

@ -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();

View file

@ -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.

View file

@ -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);

View file

@ -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);