From 321d687a2f7b2c52affed5c9a1edb2205b29a503 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Thu, 19 May 2022 13:22:17 +0000 Subject: [PATCH] [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 --- addons/web/static/tests/helpers/utils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/web/static/tests/helpers/utils.js b/addons/web/static/tests/helpers/utils.js index 23c4e39ac6f..e0bd951fb83 100644 --- a/addons/web/static/tests/helpers/utils.js +++ b/addons/web/static/tests/helpers/utils.js @@ -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) {