LibJS: Implement Date.prototype.toString()
This commit is contained in:
parent
b4fde72013
commit
dc9b1226ac
Notes:
sideshowbarker
2024-07-19 08:02:42 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/dc9b1226ac8 Pull-request: https://github.com/SerenityOS/serenity/pull/1540 Reviewed-by: https://github.com/awesomekling
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
Reference in a new issue