diff --git a/addons/web/static/src/core/py_js/py_date.js b/addons/web/static/src/core/py_js/py_date.js index 0d3ac955c4e..767c6144229 100644 --- a/addons/web/static/src/core/py_js/py_date.js +++ b/addons/web/static/src/core/py_js/py_date.js @@ -489,7 +489,7 @@ export class PyDateTime { * @returns {PyDateTime} */ to_utc() { - const d = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second); + const d = new Date(this.year, this.month -1, this.day, this.hour, this.minute, this.second); const timedelta = PyTimeDelta.create({ minutes: d.getTimezoneOffset() }); return this.add(timedelta); } diff --git a/addons/web/static/tests/core/py_js/py_date_tests.js b/addons/web/static/tests/core/py_js/py_date_tests.js index 4058d2938f4..78c4e287620 100644 --- a/addons/web/static/tests/core/py_js/py_date_tests.js +++ b/addons/web/static/tests/core/py_js/py_date_tests.js @@ -71,6 +71,24 @@ QUnit.module("py", {}, () => { assert.strictEqual(JSON.stringify(evaluateExpr(expr)), `"2021-09-16 18:00:00"`); }); + QUnit.test("to_utc in october with winter/summer change", (assert) => { + patchDate(2021, 9, 17, 10, 0, 0); + patchWithCleanup(Date.prototype, { + getTimezoneOffset() { + const month = this.getMonth() // starts at 0; + if (10 <= month || month <= 2) { + //rough approximation + return -60; + } else { + return -120; + } + }, + }); + const expr = + "datetime.datetime(2022, 10, 17).to_utc()"; + assert.strictEqual(JSON.stringify(evaluateExpr(expr)), `"2022-10-16 22:00:00"`); + }); + QUnit.test("datetime.datetime.combine", (assert) => { const expr = "datetime.datetime.combine(context_today(), datetime.time(23,59,59)).strftime('%Y-%m-%d %H:%M:%S')";