[FIX] web: use correct date in py_date.js

__Current behavior before commit:__
When `context_today()` is in a domain, UTC is used. However this is not
consistent with [the legacy method](https://github.com/odoo/odoo/blob/81183495a07eb5928b29ae56f3f86671234d602c/addons/web/static/src/legacy/js/core/py_utils.js#L232) used before OWL migration.

This has the consequence that filters with this method in their domain
will not behave correctly and use UTC date instead of the actual date
of the user.

__Description of the fix:__
Switch the UTC methods calls to regular ones.

__To reproduce:__
(Reproducible only in Odoo 16, since the old method is still used in 15)
1. Change computer date and timezone so that UTC date is not the same as
your date (e.g. if timezone is CEST, set the hour to 1am)
1. On any record, schedule an activity with the due date to today.
1. In the Activities notifications panel, click on **1 Today**
1. The page display nothing because it will filter by the previous day.

opw-3423316

closes odoo/odoo#137798

X-original-commit: e41dcde8d66c74c8ad114c76ea6ed9c607e04455
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Julien (jula)
2023-10-06 07:12:21 +00:00
committed by Aaron Bohy
parent a9a8dd6795
commit 41d135d860
2 changed files with 23 additions and 23 deletions
+11 -11
View File
@@ -233,9 +233,9 @@ export class PyDate {
* @returns {PyDate}
*/
static convertDate(date) {
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const day = date.getUTCDate();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return new PyDate(year, month, day);
}
@@ -340,12 +340,12 @@ export class PyDateTime {
* @returns {PyDateTime}
*/
static convertDate(date) {
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const day = date.getUTCDate();
const hour = date.getUTCHours();
const minute = date.getUTCMinutes();
const second = date.getUTCSeconds();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
return new PyDateTime(year, month, day, hour, minute, second, 0);
}
@@ -511,8 +511,8 @@ export class PyTime extends PyDate {
constructor(hour, minute, second) {
const now = new Date();
const year = now.getFullYear();
const month = now.getUTCMonth();
const day = now.getUTCDate();
const month = now.getMonth();
const day = now.getDate();
super(year, month, day);
this.hour = hour;
this.minute = minute;
@@ -16,15 +16,15 @@ QUnit.module("py", {}, () => {
}
const format = (n) => String(n).padStart(2, "0");
const formatDate = (d) => {
const year = d.getUTCFullYear();
const month = format(d.getUTCMonth() + 1);
const day = format(d.getUTCDate());
const year = d.getFullYear();
const month = format(d.getMonth() + 1);
const day = format(d.getDate());
return `${year}-${month}-${day}`;
};
const formatDateTime = (d) => {
const h = format(d.getUTCHours());
const m = format(d.getUTCMinutes());
const s = format(d.getUTCSeconds());
const h = format(d.getHours());
const m = format(d.getMinutes());
const s = format(d.getSeconds());
return `${formatDate(d)} ${h}:${m}:${s}`;
};
@@ -39,12 +39,12 @@ QUnit.module("py", {}, () => {
QUnit.module("datetime.datetime");
QUnit.test("datetime.datetime.now", (assert) => {
assert.ok(check("datetime.datetime.now().year", (d) => d.getUTCFullYear()));
assert.ok(check("datetime.datetime.now().month", (d) => d.getUTCMonth() + 1));
assert.ok(check("datetime.datetime.now().day", (d) => d.getUTCDate()));
assert.ok(check("datetime.datetime.now().hour", (d) => d.getUTCHours()));
assert.ok(check("datetime.datetime.now().minute", (d) => d.getUTCMinutes()));
assert.ok(check("datetime.datetime.now().second", (d) => d.getUTCSeconds()));
assert.ok(check("datetime.datetime.now().year", (d) => d.getFullYear()));
assert.ok(check("datetime.datetime.now().month", (d) => d.getMonth() + 1));
assert.ok(check("datetime.datetime.now().day", (d) => d.getDate()));
assert.ok(check("datetime.datetime.now().hour", (d) => d.getHours()));
assert.ok(check("datetime.datetime.now().minute", (d) => d.getMinutes()));
assert.ok(check("datetime.datetime.now().second", (d) => d.getSeconds()));
});
QUnit.test("various operations", (assert) => {