Skip to content

Commit d4dc773

Browse files
author
James William Pye
committed
Incorporate UTC conversion in timestamptz_pack().
1 parent e899946 commit d4dc773

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

postgresql/types/io/stdlib_datetime.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
## Used to convert a PostgreSQL ordinal to an ordinal usable by datetime
4646
pg_time_days = (pg_date_offset - datetime.date(1970, 1, 1).toordinal())
4747

48-
convert_to_utc = methodcaller('astimezone', UTC)
49-
remove_tzinfo = methodcaller('replace', tzinfo = None)
50-
set_as_utc = methodcaller('replace', tzinfo = UTC)
51-
5248
##
5349
# Constants used to special case infinity and -infinity.
5450
time64_pack_constants = {
@@ -118,11 +114,12 @@ def timestamp_unpack(seconds,
118114
def timestamptz_pack(x,
119115
seconds_in_day = seconds_in_day,
120116
pg_epoch_datetime_utc = pg_epoch_datetime_utc,
117+
UTC = UTC,
121118
):
122119
"""
123120
Create a (seconds, microseconds) pair from a `datetime.datetime` instance.
124121
"""
125-
x = (x - pg_epoch_datetime_utc)
122+
x = (x.astimezone(UTC) - pg_epoch_datetime_utc)
126123
return ((x.days * seconds_in_day) + x.seconds, x.microseconds)
127124

128125
def timestamptz_unpack(seconds,
@@ -231,7 +228,7 @@ def _proc(x, get=dict.get):
231228
datetime.datetime
232229
),
233230
(FloatTimes, TIMESTAMPTZOID) : (
234-
proc_when_not_in(compose((convert_to_utc, timestamptz_pack, lib.time_pack)), time_pack_constants),
231+
proc_when_not_in(compose((timestamptz_pack, lib.time_pack)), time_pack_constants),
235232
proc_when_not_in(compose((lib.time_unpack, timestamptz_unpack)), time_unpack_constants),
236233
datetime.datetime
237234
),
@@ -262,7 +259,7 @@ def _proc(x, get=dict.get):
262259
datetime.datetime
263260
),
264261
(IntTimes, TIMESTAMPTZOID) : (
265-
proc_when_not_in(compose((convert_to_utc, timestamptz_pack, lib.time64_pack)), time64_pack_constants),
262+
proc_when_not_in(compose((timestamptz_pack, lib.time64_pack)), time64_pack_constants),
266263
proc_when_not_in(compose((lib.time64_unpack, timestamptz_unpack)), time64_unpack_constants),
267264
datetime.datetime
268265
),

0 commit comments

Comments
 (0)