Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0226f1a

Browse filesBrowse files
committed
Fix problem with return None if Datetime field contained microsecond (Issue PyMySQL#24)
1 parent 63ab179 commit 0226f1a
Copy full SHA for 0226f1a

File tree

Expand file treeCollapse file tree

1 file changed

+14
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-6
lines changed

‎MySQLdb/times.py

Copy file name to clipboardExpand all lines: MySQLdb/times.py
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ def DateTime_or_None(s):
6060
def TimeDelta_or_None(s):
6161
try:
6262
h, m, s = s.split(':')
63-
h, m, s = int(h), int(m), float(s)
64-
td = timedelta(hours=abs(h), minutes=m, seconds=int(s),
65-
microseconds=int(math.modf(s)[0] * 1000000))
63+
if '.' in s:
64+
s, ms = s.split('.')
65+
else:
66+
ms = 0
67+
h, m, s, ms = int(h), int(m), int(s), int(ms)
68+
td = timedelta(hours=abs(h), minutes=m, seconds=s,
69+
microseconds=ms)
6670
if h < 0:
6771
return -td
6872
else:
@@ -74,9 +78,13 @@ def TimeDelta_or_None(s):
7478
def Time_or_None(s):
7579
try:
7680
h, m, s = s.split(':')
77-
h, m, s = int(h), int(m), float(s)
78-
return time(hour=h, minute=m, second=int(s),
79-
microsecond=int(math.modf(s)[0] * 1000000))
81+
if '.' in s:
82+
s, ms = s.split('.')
83+
else:
84+
ms = 0
85+
h, m, s, ms = int(h), int(m), int(s), int(ms)
86+
return time(hour=h, minute=m, second=s,
87+
microsecond=ms)
8088
except ValueError:
8189
return None
8290

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.