summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/framework/formats.js
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2017-01-18 15:50:04 +0100
committerNicolas Martinelli <nim@odoo.com>2017-01-19 10:13:51 +0100
commit4cb94c901933dd42d91b8ec5a2bdaeb08095f884 (patch)
tree21f822a2c4a8d07f3a717050483e22e622c05c5a /addons/web/static/src/js/framework/formats.js
parent0ae1f591433103f54e8c352a973e723bb54127f2 (diff)
[FIX] web: date < 01-01-1900
The Python method `strftime` raises an error when the date is older than 01-01-1900 ("The datetime strftime() methods require year >= 1900"). If the user mistyped the date (or was expecting 01-01-16 to be converted into 01-01-2016), this can lead errors since the ORM uses this method frequently. opw-702313
Diffstat (limited to 'addons/web/static/src/js/framework/formats.js')
-rw-r--r--addons/web/static/src/js/framework/formats.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/addons/web/static/src/js/framework/formats.js b/addons/web/static/src/js/framework/formats.js
index d084b285f6c..479fa1082cd 100644
--- a/addons/web/static/src/js/framework/formats.js
+++ b/addons/web/static/src/js/framework/formats.js
@@ -161,26 +161,30 @@ 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())
+ if (datetime.isValid() && datetime.year() >= 1900)
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()) {
if (datetime.year() === 0) {
datetime.year(moment.utc().year());
}
- return time.datetime_to_str(datetime.toDate());
+ if (datetime.year() >= 1900) {
+ 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())
+ if (date.isValid() && date.year() >= 1900)
return time.date_to_str(date.toDate());
date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601]);
if (date.isValid()) {
if (date.year() === 0) {
date.year(moment.utc().year());
}
- return time.date_to_str(date.toDate());
+ if (date.year() >= 1900) {
+ return time.date_to_str(date.toDate());
+ }
}
throw new Error(_.str.sprintf(_t("'%s' is not a correct date"), value));
case 'time':