mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibJS: Add Date.prototype.toGMTString()
This commit is contained in:
parent
36ea9fbd9e
commit
093331df06
5 changed files with 20 additions and 0 deletions
|
@ -220,6 +220,7 @@ namespace JS {
|
||||||
P(tanh) \
|
P(tanh) \
|
||||||
P(test) \
|
P(test) \
|
||||||
P(toDateString) \
|
P(toDateString) \
|
||||||
|
P(toGMTString) \
|
||||||
P(toISOString) \
|
P(toISOString) \
|
||||||
P(toJSON) \
|
P(toJSON) \
|
||||||
P(toLocaleDateString) \
|
P(toLocaleDateString) \
|
||||||
|
|
|
@ -91,6 +91,13 @@ int Date::utc_seconds() const
|
||||||
return to_utc_tm().tm_sec;
|
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
|
String Date::iso_date_string() const
|
||||||
{
|
{
|
||||||
auto tm = to_utc_tm();
|
auto tm = to_utc_tm();
|
||||||
|
|
|
@ -71,6 +71,7 @@ public:
|
||||||
return String::formatted("{} {}", date_string(), time_string());
|
return String::formatted("{} {}", date_string(), time_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String gmt_date_string() const;
|
||||||
String iso_date_string() const;
|
String iso_date_string() const;
|
||||||
|
|
||||||
// FIXME: One day, implement real locale support. Until then, everyone gets what the Clock MenuApplet displays.
|
// FIXME: One day, implement real locale support. Until then, everyone gets what the Clock MenuApplet displays.
|
||||||
|
|
|
@ -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.getUTCMonth, get_utc_month, 0, attr);
|
||||||
define_native_function(vm.names.getUTCSeconds, get_utc_seconds, 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.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.toISOString, to_iso_string, 0, attr);
|
||||||
define_native_function(vm.names.toLocaleDateString, to_locale_date_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);
|
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));
|
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)
|
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
|
||||||
{
|
{
|
||||||
auto* this_object = typed_this(vm, global_object);
|
auto* this_object = typed_this(vm, global_object);
|
||||||
|
|
|
@ -58,6 +58,7 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_month);
|
JS_DECLARE_NATIVE_FUNCTION(get_utc_month);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_seconds);
|
JS_DECLARE_NATIVE_FUNCTION(get_utc_seconds);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_date_string);
|
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_iso_string);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_date_string);
|
JS_DECLARE_NATIVE_FUNCTION(to_locale_date_string);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue