1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:57:35 +00:00

LibJS: Support month and day arguments of Date.setFullYear

This commit is contained in:
tuqqu 2021-03-19 13:10:55 +03:00 committed by Andreas Kling
parent d48666489c
commit ad40c5f9a9

View file

@ -128,10 +128,27 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year)
auto new_year = vm.argument(0).to_i32(global_object);
if (vm.exception())
return {};
// FIXME: Support specifying new month and new day as well.
auto& datetime = this_object->datetime();
auto new_month = datetime.month();
auto new_day = datetime.day();
i32 new_month;
if (vm.argument_count() >= 2) {
new_month = vm.argument(1).to_i32(global_object);
if (vm.exception())
return {};
} else {
new_month = datetime.month();
}
i32 new_day;
if (vm.argument_count() >= 3) {
new_day = vm.argument(2).to_i32(global_object);
if (vm.exception())
return {};
} else {
new_day = datetime.day();
}
datetime.set_time(new_year, new_month, new_day, datetime.hour(), datetime.minute(), datetime.second());
return Value { this_object->time() };
}