From 2ac6492cc29b7300cf1ab1635222d3b96ea5507d Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Wed, 12 May 2021 14:07:05 +0000 Subject: [FIX] web: parseDateTime util optimizations - `parseDateTime` util: we now caches "without zero" date and time formats Taskid: 2412172 --- addons/web/static/src/js/core/time.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'addons/web/static/src/js/core/time.js') diff --git a/addons/web/static/src/js/core/time.js b/addons/web/static/src/js/core/time.js index 3e677c4201a..b9f41813030 100644 --- a/addons/web/static/src/js/core/time.js +++ b/addons/web/static/src/js/core/time.js @@ -300,7 +300,34 @@ function getLangDatetimeFormat() { return strftime_to_moment_format(_t.database.parameters.date_format + " " + _t.database.parameters.time_format); } +const dateFormatWoZeroCache = {}; +/** + * Get date format of the user's language - allows non padded + */ +function getLangDateFormatWoZero() { + const dateFormat = getLangDateFormat(); + if (!dateFormat in dateFormatWoZeroCache) { + dateFormatWoZeroCache[dateFormat] = dateFormat + .replace('MM', 'M') + .replace('DD', 'D'); + } + return dateFormatWoZeroCache[dateFormat]; +} +const timeFormatWoZeroCache = {}; +/** + * Get time format of the user's language - allows non padded + */ +function getLangTimeFormatWoZero() { + const timeFormat = getLangTimeFormat(); + if (!timeFormat in timeFormatWoZeroCache) { + timeFormatWoZeroCache[timeFormat] = timeFormat + .replace('HH', 'H') + .replace('mm', 'm') + .replace('ss', 's'); + } + return timeFormatWoZeroCache[timeFormat]; +} return { date_to_utc: date_to_utc, @@ -316,6 +343,8 @@ return { moment_to_strftime_format: moment_to_strftime_format, getLangDateFormat: getLangDateFormat, getLangTimeFormat: getLangTimeFormat, + getLangDateFormatWoZero: getLangDateFormatWoZero, + getLangTimeFormatWoZero: getLangTimeFormatWoZero, getLangDatetimeFormat: getLangDatetimeFormat, }; -- cgit v1.2.3