changeset e60c2e04fc9b in tryton:4.4
details: https://hg.tryton.org/tryton?cmd=changeset;node=e60c2e04fc9b
description:
Prevent exception when parsing date
We should first try parsing for locale format to avoid ambiguity.
But also the index may fail if the locale format is not using numeric
value.
issue8087
review273221002
(grafted from af3d7df49a8a92e47a6fb6c47c82db3769dd5a63)
diffstat:
tryton/common/datetime_.py | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diffs (25 lines):
diff -r 36795f51918b -r e60c2e04fc9b tryton/common/datetime_.py
--- a/tryton/common/datetime_.py Mon Apr 15 15:56:48 2019 +0200
+++ b/tryton/common/datetime_.py Tue Apr 23 09:07:50 2019 +0200
@@ -21,9 +21,19 @@
def date_parse(text, format_='%x'):
+ try:
+ return datetime.datetime.strptime(text, format_)
+ except ValueError:
+ pass
formatted_date = datetime.date(1988, 7, 16).strftime(format_)
- dayfirst = formatted_date.index('16') == 0
- monthfirst = formatted_date.index('7') <= 1
+ try:
+ dayfirst = formatted_date.index('16') == 0
+ except ValueError:
+ dayfirst = False
+ try:
+ monthfirst = formatted_date.index('7') <= 1
+ except ValueError:
+ monthfirst = False
yearfirst = not dayfirst and not monthfirst
return parse(text, dayfirst=dayfirst, yearfirst=yearfirst, ignoretz=True)