8000 Avoid using floating points during timestamp-datetime conversions by hakanakyurek · Pull Request #591 · msgpack/msgpack-python · GitHub
[go: up one dir, main page]

Skip to content

Avoid using floating points during timestamp-datetime conversions #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed rounding for sub-second precision in to_datetime
  • Loading branch information
  • 8000
hakanakyurek committed Apr 19, 2024
commit 64c0e6797ffbe29c8c533cdf58a17d9ea64e1ad6
2 changes: 1 addition & 1 deletion msgpack/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def to_datetime(self):
"""
utc = datetime.timezone.utc
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
seconds=self.seconds, microseconds=round(self.nanoseconds / 1e3)
seconds=self.seconds, microseconds=self.nanoseconds // 1e3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
seconds=self.seconds, microseconds=self.nanoseconds // 1e3
seconds=self.seconds, microseconds=self.nanoseconds // 1000

)

@staticmethod
Expand Down
5 changes: 0 additions & 5 deletions test/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ def test_timestamp_datetime():

assert Timestamp.from_datetime(ts).to_datetime() == ts

t2 = Timestamp(1713256989, 420318123)
t3 = Timestamp(1713256989, 420318499)
t4 = Timestamp(1713256989, 420318501)
assert t2.to_datetime() == t3.to_datetime() != t4.to_datetime()


def test_unpack_datetime():
t = Timestamp(42, 14)
Expand Down
Loading
0