From 21decd80eed61cf8f6d52ccf247104d2fac976eb Mon Sep 17 00:00:00 2001 From: Dima Tyzhnenko Date: Tue, 22 Apr 2014 01:48:38 +0300 Subject: [PATCH 1/2] Fix wrong sign with negative zero hour timediff. Fixes #63 --- MySQLdb/times.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MySQLdb/times.py b/MySQLdb/times.py index 0ff74766..3be05ecb 100644 --- a/MySQLdb/times.py +++ b/MySQLdb/times.py @@ -70,10 +70,14 @@ def TimeDelta_or_None(s): ms = ms.ljust(6, '0') else: ms = 0 + if h[0] == '-': + isNegative = True + else: + isNegative = False 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 isNegative: return -td else: return td From 61a5acd39bfddbebb4cbc395bc681f672010f41a Mon Sep 17 00:00:00 2001 From: Dima Tyzhnenko Date: Tue, 22 Apr 2014 13:00:29 +0300 Subject: [PATCH 2/2] fix camelCase. Move abs() --- MySQLdb/times.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MySQLdb/times.py b/MySQLdb/times.py index 3be05ecb..85dfbd78 100644 --- a/MySQLdb/times.py +++ b/MySQLdb/times.py @@ -71,13 +71,13 @@ def TimeDelta_or_None(s): else: ms = 0 if h[0] == '-': - isNegative = True + negative = True else: - isNegative = False - h, m, s, ms = int(h), int(m), int(s), int(ms) - td = timedelta(hours=abs(h), minutes=m, seconds=s, + negative = False + h, m, s, ms = abs(int(h)), int(m), int(s), int(ms) + td = timedelta(hours=h, minutes=m, seconds=s, microseconds=ms) - if isNegative: + if negative: return -td else: return td