[FIX] web: core: offset in to_utc
Take a PyDateTime representing the moment "2022-10-17 00:00:00" in the timezone of Brussels. Trying to get the related utc moment through to_utc gives wrongly "2022-10-16 23:00:00". This happens because the months are not numbered in the same way in Date or PyDateTime, so that in October for example, the offset applied was that of November which is -60 instead of -120 (summer/winter change). We fix that problem. closes odoo/odoo#103561 X-original-commit: a11e1fb5f702400fe51938362fe3f24570977ba9 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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')";
|
||||
|
||||
Reference in New Issue
Block a user