|
45 | 45 | ## Used to convert a PostgreSQL ordinal to an ordinal usable by datetime |
46 | 46 | pg_time_days = (pg_date_offset - datetime.date(1970, 1, 1).toordinal()) |
47 | 47 |
|
48 | | -convert_to_utc = methodcaller('astimezone', UTC) |
49 | | -remove_tzinfo = methodcaller('replace', tzinfo = None) |
50 | | -set_as_utc = methodcaller('replace', tzinfo = UTC) |
51 | | - |
52 | 48 | ## |
53 | 49 | # Constants used to special case infinity and -infinity. |
54 | 50 | time64_pack_constants = { |
@@ -118,11 +114,12 @@ def timestamp_unpack(seconds, |
118 | 114 | def timestamptz_pack(x, |
119 | 115 | seconds_in_day = seconds_in_day, |
120 | 116 | pg_epoch_datetime_utc = pg_epoch_datetime_utc, |
| 117 | + UTC = UTC, |
121 | 118 | ): |
122 | 119 | """ |
123 | 120 | Create a (seconds, microseconds) pair from a `datetime.datetime` instance. |
124 | 121 | """ |
125 | | - x = (x - pg_epoch_datetime_utc) |
| 122 | + x = (x.astimezone(UTC) - pg_epoch_datetime_utc) |
126 | 123 | return ((x.days * seconds_in_day) + x.seconds, x.microseconds) |
127 | 124 |
|
128 | 125 | def timestamptz_unpack(seconds, |
@@ -231,7 +228,7 @@ def _proc(x, get=dict.get): |
231 | 228 | datetime.datetime |
232 | 229 | ), |
233 | 230 | (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), |
235 | 232 | proc_when_not_in(compose((lib.time_unpack, timestamptz_unpack)), time_unpack_constants), |
236 | 233 | datetime.datetime |
237 | 234 | ), |
@@ -262,7 +259,7 @@ def _proc(x, get=dict.get): |
262 | 259 | datetime.datetime |
263 | 260 | ), |
264 | 261 | (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), |
266 | 263 | proc_when_not_in(compose((lib.time64_unpack, timestamptz_unpack)), time64_unpack_constants), |
267 | 264 | datetime.datetime |
268 | 265 | ), |
|
0 commit comments