mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 02:54:29 +08:00
Fix problem with return None if Datetime field contained microsecond (Issue #24)
This commit is contained in:
@ -60,9 +60,13 @@ def DateTime_or_None(s):
|
|||||||
def TimeDelta_or_None(s):
|
def TimeDelta_or_None(s):
|
||||||
try:
|
try:
|
||||||
h, m, s = s.split(':')
|
h, m, s = s.split(':')
|
||||||
h, m, s = int(h), int(m), float(s)
|
if '.' in s:
|
||||||
td = timedelta(hours=abs(h), minutes=m, seconds=int(s),
|
s, ms = s.split('.')
|
||||||
microseconds=int(math.modf(s)[0] * 1000000))
|
else:
|
||||||
|
ms = 0
|
||||||
|
h, m, s, ms = int(h), int(m), int(s), int(ms)
|
||||||
|
td = timedelta(hours=abs(h), minutes=m, seconds=s,
|
||||||
|
microseconds=ms)
|
||||||
if h < 0:
|
if h < 0:
|
||||||
return -td
|
return -td
|
||||||
else:
|
else:
|
||||||
@ -74,9 +78,13 @@ def TimeDelta_or_None(s):
|
|||||||
def Time_or_None(s):
|
def Time_or_None(s):
|
||||||
try:
|
try:
|
||||||
h, m, s = s.split(':')
|
h, m, s = s.split(':')
|
||||||
h, m, s = int(h), int(m), float(s)
|
if '.' in s:
|
||||||
return time(hour=h, minute=m, second=int(s),
|
s, ms = s.split('.')
|
||||||
microsecond=int(math.modf(s)[0] * 1000000))
|
else:
|
||||||
|
ms = 0
|
||||||
|
h, m, s, ms = int(h), int(m), int(s), int(ms)
|
||||||
|
return time(hour=h, minute=m, second=s,
|
||||||
|
microsecond=ms)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user