From 4c38507c03bc1b551d2fa2e1480bd0258cef9ece Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" Date: Mon, 6 Nov 2023 13:40:00 +0000 Subject: [PATCH] [FIX] mail: don't apply system timezone on tracked date value in chatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Add a date field in a model with `tracking=True` - Log with a user with timezone set to UTC+2 - Create a record and set the date field to any date. - Update the date value to another date (Should have logged a message in the chatter with changes) - Log with a user with timezone set to `America/Los Angeles` - Check the chatter of the record created above Issue: New date value displayed in the chatter is wrong (set to one day before). Cause: The value displayed in the chatter is the date value converted first as datetime (with Luxon library), then the system timezone is set on it and therefore might change the day. Solution: Use `deserializeDate` instead, who has the same computation as `deserializeDatetime` (with the sole difference of date vs datetime) and therefore will not apply a timezone on the date. opw-3427502 closes odoo/odoo#142034 X-original-commit: ca3254f8c7700fe78053072710f0c57fee60af5b Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Nasreddin Boulif (bon) --- .../mail/static/src/core/web/message_patch.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/mail/static/src/core/web/message_patch.js b/addons/mail/static/src/core/web/message_patch.js index 9ed40b2c99b..6a6be443c44 100644 --- a/addons/mail/static/src/core/web/message_patch.js +++ b/addons/mail/static/src/core/web/message_patch.js @@ -3,7 +3,12 @@ import { Message } from "@mail/core/common/message"; import { markEventHandled } from "@web/core/utils/misc"; -import { deserializeDateTime, formatDate, formatDateTime } from "@web/core/l10n/dates"; +import { + deserializeDate, + deserializeDateTime, + formatDate, + formatDateTime, +} from "@web/core/l10n/dates"; import { _t } from "@web/core/l10n/translation"; import { formatChar, @@ -69,13 +74,12 @@ patch(Message.prototype, { case "many2one": case "selection": return formatChar(trackingValue.value); - case "date": - if (trackingValue.value) { - return luxon.DateTime.fromISO(trackingValue.value, { zone: "utc" }) - .setZone("system") - .toLocaleString({ locale: this.userService.lang.replace("_", "-") }); - } - return formatDate(trackingValue.value); + case "date": { + const value = trackingValue.value + ? deserializeDate(trackingValue.value) + : trackingValue.value; + return formatDate(value); + } case "datetime": { const value = trackingValue.value ? deserializeDateTime(trackingValue.value)