changeset 4dcaa207e5b6 in tryton:5.0
details: https://hg.tryton.org/tryton?cmd=changeset;node=4dcaa207e5b6
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 a18e2005adbe -r 4dcaa207e5b6 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
@@ -18,9 +18,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)
 

Reply via email to