From d57be3fb50892ee155eb1bc9066cbcf3f02e4bf8 Mon Sep 17 00:00:00 2001 From: adustman Date: Wed, 11 Mar 2009 00:48:08 +0000 Subject: [PATCH] Fix for bug #2479317 (patch #2496558) by kylev. Make some time handling stuff more consistent. --- MySQLdb/MySQLdb/times.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/MySQLdb/MySQLdb/times.py b/MySQLdb/MySQLdb/times.py index bb1c75c..abd360c 100644 --- a/MySQLdb/MySQLdb/times.py +++ b/MySQLdb/MySQLdb/times.py @@ -4,6 +4,7 @@ This module provides some Date and Time classes for dealing with MySQL data. Use Python datetime module to handle date and time columns.""" +import math from time import localtime from datetime import date, datetime, time, timedelta from _mysql import string_literal @@ -55,25 +56,26 @@ def DateTime_or_None(s): return Date_or_None(s) def TimeDelta_or_None(s): - from math import modf try: h, m, s = s.split(':') - td = timedelta(hours=int(h), minutes=int(m), seconds=int(float(s)), - microseconds=int(modf(float(s))[0]*1000000)) + 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 h < 0: return -td else: return td - except: + except ValueError: + # unpacking or int/float conversion failed 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(float(s)), - microsecond=int(modf(float(s))[0]*1000000)) - except: + 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)) + except ValueError: return None def Date_or_None(s):