LibJS: Store Date milliseconds as signed to support negative offsets

We need to support the range of -999 to 999.
This commit is contained in:
Idan Horowitz 2021-06-06 16:27:38 +03:00 committed by Linus Groh
commit 46214f0657
Notes: sideshowbarker 2024-07-18 12:44:34 +09:00
3 changed files with 10 additions and 10 deletions

View file

@ -152,7 +152,7 @@ Value DateConstructor::construct(Function&)
auto create_invalid_date = [this]() {
auto datetime = Core::DateTime::create(1970, 1, 1, 0, 0, 0);
auto milliseconds = static_cast<u16>(0);
auto milliseconds = static_cast<i16>(0);
return Date::create(global_object(), datetime, milliseconds, true);
};
@ -173,7 +173,7 @@ Value DateConstructor::construct(Function&)
// A timestamp since the epoch, in UTC.
double value_as_double = value.as_double();
auto datetime = Core::DateTime::from_timestamp(static_cast<time_t>(value_as_double / 1000));
auto milliseconds = static_cast<u16>(fmod(value_as_double, 1000));
auto milliseconds = static_cast<i16>(fmod(value_as_double, 1000));
return Date::create(global_object(), datetime, milliseconds);
}