mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:07:44 +00:00
js: Implement print function for Date objects
This commit is contained in:
parent
839beb52f3
commit
632231cc0c
3 changed files with 23 additions and 12 deletions
|
@ -35,11 +35,16 @@ public:
|
|||
virtual ~Date() override;
|
||||
|
||||
Core::DateTime& datetime() { return m_datetime; }
|
||||
const Core::DateTime& datetime() const { return m_datetime; }
|
||||
u16 milliseconds() { return m_milliseconds; }
|
||||
|
||||
String date_string() { return m_datetime.to_string("%a %b %d %Y"); }
|
||||
String date_string() const { return m_datetime.to_string("%a %b %d %Y"); }
|
||||
// FIXME: Deal with timezones once SerenityOS has a working tzset(3)
|
||||
String time_string() { return m_datetime.to_string("%T GMT+0000 (UTC)"); }
|
||||
String time_string() const { return m_datetime.to_string("%T GMT+0000 (UTC)"); }
|
||||
String string() const
|
||||
{
|
||||
return String::format("%s %s", date_string().characters(), time_string().characters());
|
||||
}
|
||||
|
||||
virtual Value value_of() const override
|
||||
{
|
||||
|
|
|
@ -172,10 +172,7 @@ Value DatePrototype::to_string(Interpreter& interpreter)
|
|||
auto* this_object = this_date_from_interpreter(interpreter);
|
||||
if (!this_object)
|
||||
return {};
|
||||
auto string = String::format(
|
||||
"%s %s",
|
||||
this_object->date_string().characters(),
|
||||
this_object->time_string().characters());
|
||||
auto string = this_object->string();
|
||||
return js_string(interpreter.heap(), move(string));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue