Skip to content

Commit 3715b72

Browse files
committed
Have unpacked datetime timezone being local
1 parent 19b5d33 commit 3715b72

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

msgpack/ext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ def to_datetime(self):
157157
:rtype: `datetime.datetime`
158158
"""
159159
utc = datetime.timezone.utc
160-
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
160+
utcDatetime = datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
161161
seconds=self.seconds, microseconds=self.nanoseconds // 1000
162162
)
163+
return utcDatetime.astimezone(tz=None)
163164

164165
@staticmethod
165166
def from_datetime(dt):

msgpack/unpack.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,12 @@ static int unpack_callback_ext(unpack_user* u, const char* base, const char* pos
355355
return -1;
356356
}
357357

358-
py = PyNumber_Add(epoch, d);
358+
PyObject *added = PyNumber_Add(epoch, d);
359+
py = PyObject_CallMethod(added, "astimezone", "O", Py_None);
359360

360361
Py_DECREF(epoch);
361362
Py_DECREF(d);
363+
Py_DECREF(added);
362364
}
363365
else { // float
364366
PyObject *a = PyFloat_FromDouble((double)ts.tv_nsec);

0 commit comments

Comments
 (0)