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
commit 2191ec591f
Notes: sideshowbarker 2024-07-19 03:13:23 +09:00
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;