diff --git a/MySQLdb/MySQLdb/converters.py b/MySQLdb/MySQLdb/converters.py index 1136e8d..4da2603 100644 --- a/MySQLdb/MySQLdb/converters.py +++ b/MySQLdb/MySQLdb/converters.py @@ -127,7 +127,7 @@ conversions = { FIELD_TYPE.SET: Str2Set, FIELD_TYPE.TIMESTAMP: mysql_timestamp_converter, FIELD_TYPE.DATETIME: DateTime_or_None, - FIELD_TYPE.TIME: TimeDelta_or_None, + FIELD_TYPE.TIME: Time_or_None, FIELD_TYPE.DATE: Date_or_None, } diff --git a/MySQLdb/MySQLdb/mxdatetimes.py b/MySQLdb/MySQLdb/mxdatetimes.py index f6d339b..f2200b5 100644 --- a/MySQLdb/MySQLdb/mxdatetimes.py +++ b/MySQLdb/MySQLdb/mxdatetimes.py @@ -43,6 +43,8 @@ def TimeDelta_or_None(s): try: return ISO.ParseTimeDelta(s) except: return None +Time_or_None = TimeDelta_or_None + def Date_or_None(s): try: return ISO.ParseDate(s) except: return None diff --git a/MySQLdb/MySQLdb/pytimes.py b/MySQLdb/MySQLdb/pytimes.py index d0437f9..8f2d1c6 100644 --- a/MySQLdb/MySQLdb/pytimes.py +++ b/MySQLdb/MySQLdb/pytimes.py @@ -43,12 +43,24 @@ def DateTime_or_None(s): return None def TimeDelta_or_None(s): + from math import modf try: - h, m, s = map(float, s.split(':')) + h, m, s = s.split(':') + td = timedelta(hours=int(h), minutes=int(m), seconds=int(s), + microseconds=int(modf(float(s)[0]))*1000000) if h < 0: - return -timedelta(hours=h, minutes=m, seconds=s) + return -td else: - return timedelta(hours=h, minutes=m, seconds=s) + return td + except: + return None + +def Time_or_None(s): + from math import modf + try: + h, m, s = s.split(':') + return time(hour=int(h), minute=int(m), second=int(s), + microsecond=int(modf(float(s))[0])*1000000) except: return None diff --git a/MySQLdb/MySQLdb/stringtimes.py b/MySQLdb/MySQLdb/stringtimes.py index ad01252..24f86bf 100644 --- a/MySQLdb/MySQLdb/stringtimes.py +++ b/MySQLdb/MySQLdb/stringtimes.py @@ -35,4 +35,4 @@ def format_DATE(d): return d format_TIME = format_TIMESTAMP = format_DATE -TimeDelta_or_None = Date_or_None = DateTime_or_None = format_DATE +Time_or_None = TimeDelta_or_None = Date_or_None = DateTime_or_None = format_DATE diff --git a/MySQLdb/MySQLdb/times.py b/MySQLdb/MySQLdb/times.py index 5ffc1d5..924a136 100644 --- a/MySQLdb/MySQLdb/times.py +++ b/MySQLdb/MySQLdb/times.py @@ -6,11 +6,11 @@ This module provides some Date and Time classes for dealing with MySQL data. from _mysql import string_literal try: - from pytimes import * + from mxdatetimes import * except ImportError: try: - from mxdatetimes import * + from pytimes import * except ImportError: # no DateTime? We'll muddle through somehow.