Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59406a9

Browse filesBrowse files
committed
Merge pull request PyMySQL#20 from PyMySQL/datetime-format
Don't use datetime.isoformat() when encoding
2 parents 1591760 + 861a7d3 commit 59406a9
Copy full SHA for 59406a9

File tree

Expand file treeCollapse file tree

2 files changed

+14
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-14
lines changed

‎MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
-4Lines 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

Copy file name to clipboardExpand all lines: MySQLdb/times.py
+14-10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.