[FIX] web: strftimeToLuxonFormat escape character
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) <lul@odoo.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user