From cde7d9edb0183f6a8ae6ff1ea6f9b71205e20134 Mon Sep 17 00:00:00 2001 From: "Adrien Minne (adrm)" Date: Tue, 16 May 2023 08:24:00 +0000 Subject: [PATCH] [FIX] web: strftimeToLuxonFormat escape character MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function `strftimeToLuxonFormat` used brackets as escape character, which was the escape character of moment. This commit changes the escape character to be quotes, which is the correct escape character for luxon. https://moment.github.io/luxon/#/formatting?id=escaping closes odoo/odoo#123192 X-original-commit: d69201a6fe78dc22baed1cede04092aa2ed0bf0b Signed-off-by: Lucas Lefèvre (lul) --- addons/web/static/src/core/l10n/dates.js | 2 +- .../web/static/tests/core/l10n/dates_tests.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/core/l10n/dates.js b/addons/web/static/src/core/l10n/dates.js index 0ef4789aee4..bd63447c38c 100644 --- a/addons/web/static/src/core/l10n/dates.js +++ b/addons/web/static/src/core/l10n/dates.js @@ -246,7 +246,7 @@ export const strftimeToLuxonFormat = memoize(function strftimeToLuxonFormat(form if (inToken && normalizeFormatTable[character] !== undefined) { character = normalizeFormatTable[character]; } else { - character = "[" + character + "]"; // moment.js escape + character = "'" + character + "'"; // luxon escape } } output.push(character); diff --git a/addons/web/static/tests/core/l10n/dates_tests.js b/addons/web/static/tests/core/l10n/dates_tests.js index f6d462dc6be..c754befd4ce 100644 --- a/addons/web/static/tests/core/l10n/dates_tests.js +++ b/addons/web/static/tests/core/l10n/dates_tests.js @@ -322,6 +322,24 @@ QUnit.module( unpatch(localization, "patch loc"); }); + QUnit.test("parseDateTime with escaped characters (eg. Basque locale)", async (assert) => { + const dateFormat = strftimeToLuxonFormat("%a, %Y.eko %bren %da"); + const timeFormat = strftimeToLuxonFormat("%H:%M:%S"); + patch(localization, "patch loc", { + dateFormat, + timeFormat, + dateTimeFormat: `${dateFormat} ${timeFormat}`, + }); + + const dateTimeFormat = `${dateFormat} ${timeFormat}`; + assert.equal(dateTimeFormat, "ccc, yyyy.'e''k''o' MMM'r''e''n' dd'a' HH:mm:ss"); + assert.equal( + parseDateTime("1985-01-31 08:30:00").toFormat(dateTimeFormat), + "Thu, 1985.eko Janren 31a 08:30:00" + ); + unpatch(localization, "patch loc"); + }); + QUnit.test("parse smart date input", async (assert) => { patchDate(2020, 0, 1, 0, 0, 0); // 2020-01-01 00:00:00