1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibJS: Make Date's tuple constructor correctly handle out-of-range arguments

Milliseconds need extra handling, but everything else just works
now that mktime() handles this case.
This commit is contained in:
Nico Weber 2020-08-24 09:26:28 -04:00 committed by Andreas Kling
parent 5b9d43767c
commit 2191ec591f
2 changed files with 32 additions and 1 deletions

View file

@ -195,6 +195,13 @@ Value DateConstructor::construct(Interpreter& interpreter, Function&)
int seconds = arg_or(5, 0);
int milliseconds = arg_or(6, 0);
seconds += milliseconds / 1000;
milliseconds %= 1000;
if (milliseconds < 0) {
seconds -= 1;
milliseconds += 1000;
}
if (year >= 0 && year <= 99)
year += 1900;
int month = month_index + 1;