changeset 627b7fbf911f in tryton:4.8
details: https://hg.tryton.org/tryton?cmd=changeset;node=627b7fbf911f
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 3e14cfdbd62a -r 627b7fbf911f 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)