diff --git a/src/helpers/datetime.js b/src/helpers/datetime.js index 31ef1df4c..1c93e2b18 100644 --- a/src/helpers/datetime.js +++ b/src/helpers/datetime.js @@ -461,10 +461,16 @@ export function convertPHPToMomentFormat(format) { r: '', // no equivalent U: 'X', }; - return String(format) .split('') - .map((chr) => (chr in replacements ? replacements[chr] : chr)) + .map((chr, index, elements) => { + // Allow the format string to contain escaped chars, like ES or DE needs + const last = elements[index - 1]; + if (chr in replacements && last !== '\\') { + return replacements[chr]; + } + return chr; + }) .join(''); } diff --git a/test/unit/js/src/helpers/datetime.test.js b/test/unit/js/src/helpers/datetime.test.js index 7ddd6df5b..1ba654723 100644 --- a/test/unit/js/src/helpers/datetime.test.js +++ b/test/unit/js/src/helpers/datetime.test.js @@ -284,3 +284,9 @@ test('convertPHPToMomentFormat returns correct time format', () => { expect(format).toBe('h:mm a'); }); + +test('convertPHPToMomentFormat returns correct format that contains escaped chars, like ES or DE needs', () => { + const format = convertPHPToMomentFormat('G:i \\U\\h\\r'); // "20 Uhr" is german for "8 o'clock" (in the evening). + + expect(format).toBe('H:mm \\U\\h\\r'); +});