mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibJS: Implement Date.prototype.toString()
This commit is contained in:
parent
b4fde72013
commit
dc9b1226ac
2 changed files with 12 additions and 0 deletions
|
@ -58,6 +58,7 @@ DatePrototype::DatePrototype()
|
|||
put_native_function("getMonth", get_month);
|
||||
put_native_function("getSeconds", get_seconds);
|
||||
put_native_function("getTime", get_time);
|
||||
put_native_function("toString", to_string);
|
||||
}
|
||||
|
||||
DatePrototype::~DatePrototype()
|
||||
|
@ -146,4 +147,14 @@ Value DatePrototype::get_time(Interpreter& interpreter)
|
|||
return Value(static_cast<double>(seconds * 1000 + milliseconds));
|
||||
}
|
||||
|
||||
Value DatePrototype::to_string(Interpreter& interpreter)
|
||||
{
|
||||
auto* this_object = this_date_from_interpreter(interpreter);
|
||||
if (!this_object)
|
||||
return {};
|
||||
// FIXME: Deal with timezones once SerenityOS has a working tzset(3)
|
||||
auto string = this_object->datetime().to_string("%a %b %d %Y %T GMT+0000 (UTC)");
|
||||
return js_string(interpreter.heap(), move(string));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ private:
|
|||
static Value get_month(Interpreter&);
|
||||
static Value get_seconds(Interpreter&);
|
||||
static Value get_time(Interpreter&);
|
||||
static Value to_string(Interpreter&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue