summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/framework
diff options
context:
space:
mode:
authorDenis Ledoux <dle@odoo.com>2016-07-05 17:49:10 +0200
committerDenis Ledoux <dle@odoo.com>2016-07-05 18:04:22 +0200
commit489ea4285996662382a31c47bc33c6d7a3e9c80b (patch)
tree042a2b0fe8b5d868887c1b4406d9b3e9f1f8a12c /addons/web/static/src/js/framework
parent3de53fa165baf76cde7f2593d4fb26f2cc7a5383 (diff)
[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
Diffstat (limited to 'addons/web/static/src/js/framework')
-rw-r--r--addons/web/static/src/js/framework/formats.js6
1 files changed, 6 insertions, 0 deletions
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
@@ -163,11 +163,17 @@ function parse_value (value, descriptor, value_if_empty) {
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));
case 'time':
var _time = moment(value, [time_pattern, time_pattern_wo_zero, moment.ISO_8601], true);