mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-06 09:50:01 +00:00
Have unpacked datetime timezone being local
This commit is contained in:
parent
19b5d33ded
commit
3715b72d57
2 changed files with 5 additions and 2 deletions
|
|
@ -157,9 +157,10 @@ class Timestamp:
|
|||
:rtype: `datetime.datetime`
|
||||
"""
|
||||
utc = datetime.timezone.utc
|
||||
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
|
||||
utcDatetime = datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
|
||||
seconds=self.seconds, microseconds=self.nanoseconds // 1000
|
||||
)
|
||||
return utcDatetime.astimezone(tz=None)
|
||||
|
||||
@staticmethod
|
||||
def from_datetime(dt):
|
||||
|
|
|
|||
|
|
@ -355,10 +355,12 @@ static int unpack_callback_ext(unpack_user* u, const char* base, const char* pos
|
|||
return -1;
|
||||
}
|
||||
|
||||
py = PyNumber_Add(epoch, d);
|
||||
PyObject *added = PyNumber_Add(epoch, d);
|
||||
py = PyObject_CallMethod(added, "astimezone", "O", Py_None);
|
||||
|
||||
Py_DECREF(epoch);
|
||||
Py_DECREF(d);
|
||||
Py_DECREF(added);
|
||||
}
|
||||
else { // float
|
||||
PyObject *a = PyFloat_FromDouble((double)ts.tv_nsec);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue