[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
This commit is contained in:
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user