mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
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:
@ -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)
|
||||||
|
Reference in New Issue
Block a user