Skip to content

Commit e0e4e52

Browse files
committed
Transfer date, datetime, time struct to iso format string before request
1 parent 72ebaac commit e0e4e52

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

pycovenantsql/converters.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,18 @@ def escape_timedelta(obj, mapping=None):
114114
return fmt.format(hours, minutes, seconds, obj.microseconds)
115115

116116
def escape_time(obj, mapping=None):
117-
if obj.microsecond:
118-
fmt = "'{0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
119-
else:
120-
fmt = "'{0.hour:02}:{0.minute:02}:{0.second:02}'"
121-
return fmt.format(obj)
117+
return "'{}'".format(obj.isoformat(timespec='microseconds'))
122118

123119
def escape_datetime(obj, mapping=None):
124-
if obj.microsecond:
125-
fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
126-
else:
127-
fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}'"
128-
return fmt.format(obj)
120+
return "'{}'".format(obj.isoformat(sep=' ', timespec='microseconds'))
121+
#if obj.microsecond:
122+
# fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}.{0.microsecond:06}'"
123+
#else:
124+
# fmt = "'{0.year:04}-{0.month:02}-{0.day:02} {0.hour:02}:{0.minute:02}:{0.second:02}'"
125+
#return fmt.format(obj)
129126

130127
def escape_date(obj, mapping=None):
131-
fmt = "'{0.year:04}-{0.month:02}-{0.day:02}'"
132-
return fmt.format(obj)
128+
return "'{}'".format(obj.isoformat())
133129

134130
def escape_struct_time(obj, mapping=None):
135131
return escape_datetime(datetime.datetime(*obj[:6]))

pycovenantsql/tests/test_basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ def test_datetime_microseconds(self):
142142

143143
conn = self.connections[0]
144144
c = conn.cursor()
145-
dt = datetime.datetime(2013, 11, 12, 9, 9, 9, 123450)
145+
#dt = datetime.datetime(2013, 11, 12, 9, 9, 9, 123450, tzinfo=datetime.timezone(datetime.timedelta(hours=10)))
146+
dt = datetime.datetime(2013, 11, 12, 9, 9, 9, 123450, tzinfo=datetime.timezone.utc)
146147
self.safe_create_table(
147-
conn, "test_datetime", "create table test_datetime (id int, ts datetime(6))")
148+
conn, "test_datetime", "create table test_datetime (id int, ts datetime)")
148149
c.execute(
149150
"insert into test_datetime values (%s, %s)",
150151
(1, dt)

0 commit comments

Comments
 (0)