changeset af3d7df49a8a in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset;node=af3d7df49a8a
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
diffstat:

 tryton/common/datetime_.py |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (25 lines):

diff -r 76fb0f8e2866 -r af3d7df49a8a 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
@@ -16,9 +16,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