From 489ea4285996662382a31c47bc33c6d7a3e9c80b Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 5 Jul 2016 17:49:10 +0200 Subject: [PATCH] [FIX] web: parsing of date with abbreviated month/day When using the abbreviated month in the language date format (`%b`), e.g. `%d %b %Y` in some languages, the parsing of the date from this format to the database format (YYYY-mm-dd) failed because of a dot `.` added from time to time to the end of the abbreviated name e.g., in French, `5 juil. 2016` This is a bug of `moment.js` < 2.13.0, handling badly this dot. This is solved from `moment.js` 2.13.0, thanks to the below revision moment/moment@41fdb58572546740c3a840ebd36fbe9e1bcdc9cb moment/moment#3078 Unfortunately, we cannot update this library to its latest release in stable release of Odoo (e.g. 9.0), as this is seen as an unstable change (if some API changes occured in the given library) Instead, if the parsing of the date fails with the strict mode (meaning the date must respect the format exactly), we perform a second pass without the strict mode, so this dot will be ignored, and the date can be correctly parsed. The issue can be reproduced by loading the French language, and setting `%d %b %Y` as date format, and then performing an advanced search on a date field. The value of the date in the advanced search will be empty without this revision (for the months having more than 4 chars, other than `mars`, `mai`, `juin`, `aout`). Fixes #11854 opw-682534 --- addons/web/static/src/js/framework/formats.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/web/static/src/js/framework/formats.js b/addons/web/static/src/js/framework/formats.js index 52a2fa5b0b0..8a5a8ffedb7 100644 --- a/addons/web/static/src/js/framework/formats.js +++ b/addons/web/static/src/js/framework/formats.js @@ -161,11 +161,17 @@ function parse_value (value, descriptor, value_if_empty) { return parse_value(value, {type: "float"}); case 'datetime': 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()); + datetime = moment(value, [date_pattern + ' ' + time_pattern, date_pattern_wo_zero + ' ' + time_pattern_wo_zero, moment.ISO_8601]); 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, moment.ISO_8601], true); + if (date.isValid()) + return time.date_to_str(date.toDate()); + date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601]); if (date.isValid()) return time.date_to_str(date.toDate()); throw new Error(_.str.sprintf(_t("'%s' is not a correct date"), value));