From 50b94ef079b2fd9f4e9201ea8f977fadab109aea Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 9 May 2016 15:11:35 +0200 Subject: [FIX] web: search input of date When the user searches for date (or a datetime) in the search bar, the suggested date can become completely wrong. For example, in the French localization where the date format is DD/MM/YYYY, the system will search for the date MM/DD/YYYY. This is even worse when the date is not fully written: DD/MM could be converted to MM/DD/0000, which doesn't make any sense. This is related to the moment issue https://github.com/moment/moment/issues/1407. The fix is to make sure that the input date has a correct format thanks to `parse_value`. The latter converts the date into a fixed format. Fixes #11876 opw-676604 --- addons/web/static/src/js/framework/formats.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/framework') diff --git a/addons/web/static/src/js/framework/formats.js b/addons/web/static/src/js/framework/formats.js index 4b5ff8b4048..52a2fa5b0b0 100644 --- a/addons/web/static/src/js/framework/formats.js +++ b/addons/web/static/src/js/framework/formats.js @@ -160,17 +160,17 @@ function parse_value (value, descriptor, value_if_empty) { case 'progressbar': return parse_value(value, {type: "float"}); case 'datetime': - var datetime = moment(value, [date_pattern + ' ' + time_pattern, date_pattern_wo_zero + ' ' + time_pattern_wo_zero], true); + var datetime = moment(value, [date_pattern + ' ' + time_pattern, date_pattern_wo_zero + ' ' + time_pattern_wo_zero, moment.ISO_8601], true); if (datetime.isValid()) return time.datetime_to_str(datetime.toDate()); throw new Error(_.str.sprintf(_t("'%s' is not a correct datetime"), value)); case 'date': - var date = moment(value, [date_pattern, date_pattern_wo_zero], true); + var date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true); if (date.isValid()) return time.date_to_str(date.toDate()); throw new Error(_.str.sprintf(_t("'%s' is not a correct date"), value)); case 'time': - var _time = moment(value, [time_pattern, time_pattern_wo_zero], true); + var _time = moment(value, [time_pattern, time_pattern_wo_zero, moment.ISO_8601], true); if (_time.isValid()) return time.time_to_str(_time.toDate()); throw new Error(_.str.sprintf(_t("'%s' is not a correct time"), value)); -- cgit v1.2.3