Skip to content

Commit fb1c79d

Browse files
author
Jinuk
committed
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`.
1 parent 100485f commit fb1c79d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

MySQLdb/times.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ def DateTime_or_None(s):
5252
try:
5353
d, t = s.split(sep, 1)
5454
if '.' in t:
55-
t, m = t.split('.',1)
55+
t, ms = t.split('.',1)
56+
ms = ms.ljust(6, '0')
5657
else:
57-
m = 0
58-
return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[m] ])
58+
ms = 0
59+
return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[ms] ])
5960
except (SystemExit, KeyboardInterrupt):
6061
raise
6162
except:
@@ -66,6 +67,7 @@ def TimeDelta_or_None(s):
6667
h, m, s = s.split(':')
6768
if '.' in s:
6869
s, ms = s.split('.')
70+
ms = ms.ljust(6, '0')
6971
else:
7072
ms = 0
7173
h, m, s, ms = int(h), int(m), int(s), int(ms)
@@ -84,6 +86,7 @@ def Time_or_None(s):
8486
h, m, s = s.split(':')
8587
if '.' in s:
8688
s, ms = s.split('.')
89+
ms = ms.ljust(6, '0')
8790
else:
8891
ms = 0
8992
h, m, s, ms = int(h), int(m), int(s), int(ms)

0 commit comments

Comments
 (0)