mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-21 12:53:17 +00:00
Avoid using floating points during timestamp-datetime conversions (#591)
This commit is contained in:
parent
9aedf8ed7f
commit
e77672200b
2 changed files with 19 additions and 2 deletions
|
@ -157,7 +157,9 @@ class Timestamp:
|
|||
:rtype: `datetime.datetime`
|
||||
"""
|
||||
utc = datetime.timezone.utc
|
||||
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(seconds=self.to_unix())
|
||||
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
|
||||
seconds=self.seconds, microseconds=self.nanoseconds // 1000
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_datetime(dt):
|
||||
|
@ -165,4 +167,4 @@ class Timestamp:
|
|||
|
||||
:rtype: Timestamp
|
||||
"""
|
||||
return Timestamp.from_unix(dt.timestamp())
|
||||
return Timestamp(seconds=int(dt.timestamp()), nanoseconds=dt.microsecond * 1000)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue