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`.
This commit is contained in:
Jinuk
2013-11-08 12:18:55 +09:00
parent 100485f627
commit fb1c79d85a

View File

@ -52,10 +52,11 @@ def DateTime_or_None(s):
try: try:
d, t = s.split(sep, 1) d, t = s.split(sep, 1)
if '.' in t: if '.' in t:
t, m = t.split('.',1) t, ms = t.split('.',1)
ms = ms.ljust(6, '0')
else: else:
m = 0 ms = 0
return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[m] ]) return datetime(*[ int(x) for x in d.split('-')+t.split(':')+[ms] ])
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
raise raise
except: except:
@ -66,6 +67,7 @@ def TimeDelta_or_None(s):
h, m, s = s.split(':') h, m, s = s.split(':')
if '.' in s: if '.' in s:
s, ms = s.split('.') s, ms = s.split('.')
ms = ms.ljust(6, '0')
else: else:
ms = 0 ms = 0
h, m, s, ms = int(h), int(m), int(s), int(ms) 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(':') h, m, s = s.split(':')
if '.' in s: if '.' in s:
s, ms = s.split('.') s, ms = s.split('.')
ms = ms.ljust(6, '0')
else: else:
ms = 0 ms = 0
h, m, s, ms = int(h), int(m), int(s), int(ms) h, m, s, ms = int(h), int(m), int(s), int(ms)