From 2dc4c67402732e0892f3da384ad9ec4a0f7824d7 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Wed, 29 Aug 2018 17:15:51 +0900
Subject: [PATCH] Revert "ZMySQLDA: Optimise date & datetime parsing in
 results."

For some reason, unit tests all broke while testing this revision. The
relation between both is not clear to me (this code has worked for me).
In doubt, I revert it for now.
This reverts commit 0057272c35dd2b5cd4a933fe181b7a15d79ed57e.
---
 product/ZMySQLDA/db.py | 40 +++++-----------------------------------
 1 file changed, 5 insertions(+), 35 deletions(-)

diff --git a/product/ZMySQLDA/db.py b/product/ZMySQLDA/db.py
index 50e66fe7fb..d9ed4928c8 100644
--- a/product/ZMySQLDA/db.py
+++ b/product/ZMySQLDA/db.py
@@ -158,39 +158,9 @@ def _mysql_timestamp_converter(s):
                           s[8:10],s[10:12],s[12:14]))
         return DateTime("%04d-%02d-%02d %02d:%02d:%02d" % tuple(parts))
 
-# DateTime(str) is slow. As the date format is part of the specifications,
-# parse it ourselves to save time.
-def DATETIME_to_DateTime_or_None(s):
-    try:
-        date, time = s.split(' ')
-        year, month, day = date.split('-')
-        hour, minte, second = time.split(':')
-        return DateTime(
-            int(year),
-            int(month),
-            int(day),
-            int(hour),
-            int(minute),
-            float(second),
-            'UTC',
-        )
-    except Exception:
-        return None
-
-def DATE_to_DateTime_or_None(s):
-    try:
-        year, month, day = s.split('-')
-        return DateTime(
-            int(year),
-            int(month),
-            int(day),
-            0,
-            0,
-            0,
-            'UTC',
-        )
-    except Exception:
-        return None
+def DateTime_or_None(s):
+    try: return DateTime('%s UTC' % s)
+    except Exception: return None
 
 def ord_or_None(s):
     if s is not None:
@@ -201,8 +171,8 @@ class DB(TM):
 
     conv=conversions.copy()
     conv[FIELD_TYPE.LONG] = int
-    conv[FIELD_TYPE.DATETIME] = DATETIME_to_DateTime_or_None
-    conv[FIELD_TYPE.DATE] = DATE_to_DateTime_or_None
+    conv[FIELD_TYPE.DATETIME] = DateTime_or_None
+    conv[FIELD_TYPE.DATE] = DateTime_or_None
     conv[FIELD_TYPE.DECIMAL] = float
     conv[FIELD_TYPE.BIT] = ord_or_None
     del conv[FIELD_TYPE.TIME]
-- 
2.30.9