LibJS: Implement Date.prototype.toString()

This commit is contained in:
Linus Groh 2020-03-30 18:32:00 +01:00 committed by Andreas Kling
parent b4fde72013
commit dc9b1226ac
Notes: sideshowbarker 2024-07-19 08:02:42 +09:00
2 changed files with 12 additions and 0 deletions

View file

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

View file

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