Skip to content

Commit 861a7d3

Browse files
committed
Don't use datetime.isoformat() when encoding
1 parent 1591760 commit 861a7d3

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

MySQLdb/converters.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
except AttributeError:
4747
ArrayType = array.array
4848

49-
try:
50-
set
51-
except NameError:
52-
from sets import Set as set
5349

5450
def Bool2Str(s, d): return str(int(s))
5551

MySQLdb/times.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
33
This module provides some Date and Time classes for dealing with MySQL data.
44
5-
Use Python datetime module to handle date and time columns."""
6-
7-
import math
5+
Use Python datetime module to handle date and time columns.
6+
"""
87
from time import localtime
98
from datetime import date, datetime, time, timedelta
109
from _mysql import string_literal
@@ -33,12 +32,19 @@ def TimestampFromTicks(ticks):
3332

3433
def format_TIMEDELTA(v):
3534
seconds = int(v.seconds) % 60
36-
minutes = int(v.seconds / 60) % 60
37-
hours = int(v.seconds / 3600) % 24
35+
minutes = int(v.seconds // 60) % 60
36+
hours = int(v.seconds // 3600) % 24
3837
return '%d %d:%d:%d' % (v.days, hours, minutes, seconds)
3938

4039
def format_TIMESTAMP(d):
41-
return d.isoformat(" ")
40+
"""
41+
:type d: datetime.datetime
42+
"""
43+
if d.microsecond:
44+
fmt = "{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}"
45+
else:
46+
fmt = "{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}"
47+
return fmt.format(d)
4248

4349

4450
def DateTime_or_None(s):
@@ -102,14 +108,12 @@ def Time_or_None(s):
102108
def Date_or_None(s):
103109
try:
104110
return date(*[ int(x) for x in s.split('-',2)])
105-
except (SystemExit, KeyboardInterrupt):
106-
raise
107-
except:
111+
except (TypeError, ValueError):
108112
return None
109113

110114
def DateTime2literal(d, c):
111115
"""Format a DateTime object as an ISO timestamp."""
112-
return string_literal(format_TIMESTAMP(d),c)
116+
return string_literal(format_TIMESTAMP(d), c)
113117

114118
def DateTimeDelta2literal(d, c):
115119
"""Format a DateTimeDelta object as a time."""

0 commit comments

Comments
 (0)