diff options
author | Andy Dustman <farcepest@gmail.com> | 2013-08-18 14:21:12 -0700 |
---|---|---|
committer | Andy Dustman <farcepest@gmail.com> | 2013-08-18 14:21:12 -0700 |
commit | 39406ea3e037c64156f88747471498e5c68993bb (patch) | |
tree | 43a8b4d517f1a4131b3d7788d160a9225303455f | |
parent | 563ed107332359dc1506a25d4b14862c1f5a8002 (diff) | |
parent | 0226f1a727441746bbe2bc396de5eccea7f395f8 (diff) | |
download | mysqldb1-39406ea3e037c64156f88747471498e5c68993bb.tar.gz |
Merge pull request #25 from tyzhnenko/microsecond-bug-fix
Fix problem in Datetime with microsecond returns (Issue #24)
-rw-r--r-- | MySQLdb/times.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/MySQLdb/times.py b/MySQLdb/times.py index bc92eb4..f3a92d7 100644 --- a/MySQLdb/times.py +++ b/MySQLdb/times.py @@ -60,9 +60,13 @@ def DateTime_or_None(s): def TimeDelta_or_None(s): try: h, m, s = s.split(':') - h, m, s = int(h), int(m), float(s) - td = timedelta(hours=abs(h), minutes=m, seconds=int(s), - microseconds=int(math.modf(s)[0] * 1000000)) + if '.' in s: + s, ms = s.split('.') + 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: return -td else: @@ -74,9 +78,13 @@ def TimeDelta_or_None(s): def Time_or_None(s): try: h, m, s = s.split(':') - h, m, s = int(h), int(m), float(s) - return time(hour=h, minute=m, second=int(s), - microsecond=int(math.modf(s)[0] * 1000000)) + if '.' in s: + s, ms = s.split('.') + 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: return None |