[FIX] web: tests: patchDate use the offset fixed in luxon
Before this commit, patchDate used the machine offset and not the offset
fixed in luxon.
For example:
Date to Patch = 01-01-2000 10:30:00
Machine offset = -120 (UTC-2)
Luxon offset = 360 (UTC+6)
Before:
Patched Date = 01-01-2000 10:30:00 UTC-2
After:
Patched Date = 01-01-2000 02:30:00 UTC-2
closes odoo/odoo#91591
Signed-off-by: Bruno Boi <boi@odoo.com>
This commit is contained in:
@@ -23,7 +23,18 @@ const { App, onMounted, onPatched, useComponent } = owl;
|
||||
export function patchDate(year, month, day, hours, minutes, seconds) {
|
||||
var RealDate = window.Date;
|
||||
var actualDate = new RealDate();
|
||||
|
||||
// By default, RealDate uses the browser offset, so we must replace it with the offset fixed in luxon.
|
||||
var fakeDate = new RealDate(year, month, day, hours, minutes, seconds);
|
||||
if (!(luxon.Settings.defaultZone instanceof luxon.FixedOffsetZone)) {
|
||||
throw new Error("luxon.Settings.defaultZone must be a FixedOffsetZone");
|
||||
}
|
||||
const browserOffset = -fakeDate.getTimezoneOffset();
|
||||
const patchedOffset = luxon.Settings.defaultZone.offset();
|
||||
const offsetDiff = patchedOffset - browserOffset;
|
||||
const correctedMinutes = fakeDate.getMinutes() - offsetDiff;
|
||||
fakeDate.setMinutes(correctedMinutes);
|
||||
|
||||
var timeInterval = actualDate.getTime() - fakeDate.getTime();
|
||||
|
||||
window.Date = (function (NativeDate) {
|
||||
|
||||
Reference in New Issue
Block a user