From fb1c79d85a87345525ba82cfdca470c4ef565a3c Mon Sep 17 00:00:00 2001 From: Jinuk Date: Fri, 8 Nov 2013 12:18:55 +0900 Subject: microsecond-bug-fix When the MySQL Datetime Fraction is less than 6, microseconds set incorrectly. For example, you set the field, Datetime(3). Then this library read the time `2013-11-07 10:27:35.705` as `2013-11-08 10:27:35.000705`. --- MySQLdb/times.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'MySQLdb') diff --git a/MySQLdb/times.py b/MySQLdb/times.py index 4040f8e..0ff7476 100644 --- a/MySQLdb/times.py +++ b/MySQLdb/times.py @@ -52,10 +52,11 @@ def DateTime_or_None(s): try: d, t = s.split(sep, 1) if '.' in t: - t, m = t.split('.',1) + t, ms = t.split('.',1) + ms = ms.ljust(6, '0') else: - m = 0 - return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[m] ]) + ms = 0 + return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[ms] ]) except (SystemExit, KeyboardInterrupt): raise except: @@ -66,6 +67,7 @@ def TimeDelta_or_None(s): h, m, s = s.split(':') if '.' in s: s, ms = s.split('.') + ms = ms.ljust(6, '0') else: ms = 0 h, m, s, ms = int(h), int(m), int(s), int(ms) @@ -84,6 +86,7 @@ def Time_or_None(s): h, m, s = s.split(':') if '.' in s: s, ms = s.split('.') + ms = ms.ljust(6, '0') else: ms = 0 h, m, s, ms = int(h), int(m), int(s), int(ms) -- cgit v1.2.1