Title: Fix Timestamp.from_datetime returning wrong value for pre-epoch datetimes by bysiber · Pull Request #662 · msgpack/msgpack-python · GitHub
Open Graph Title: Fix Timestamp.from_datetime returning wrong value for pre-epoch datetimes by bysiber · Pull Request #662 · msgpack/msgpack-python
X Title: Fix Timestamp.from_datetime returning wrong value for pre-epoch datetimes by bysiber · Pull Request #662 · msgpack/msgpack-python
Description: Timestamp.from_datetime() uses int(dt.timestamp()) to compute the seconds component, but int() truncates towards zero. For pre-epoch datetimes with non-zero microseconds, this produces the wrong value: import datetime dt = datetime.datetime(1969, 12, 31, 23, 59, 59, 500000, tzinfo=datetime.timezone.utc) # dt.timestamp() == -0.5 # int(-0.5) == 0 (truncation towards zero) # Expected: Timestamp(seconds=-1, nanoseconds=500000000) # Actual: Timestamp(seconds=0, nanoseconds=500000000) <-- +0.5s instead of -0.5s! The sign of the time gets flipped. from_unix() already handles this correctly using floor division (int(unix_sec // 1)). This change makes from_datetime() consistent.
Open Graph Description: Timestamp.from_datetime() uses int(dt.timestamp()) to compute the seconds component, but int() truncates towards zero. For pre-epoch datetimes with non-zero microseconds, this produces the wrong va...
X Description: Timestamp.from_datetime() uses int(dt.timestamp()) to compute the seconds component, but int() truncates towards zero. For pre-epoch datetimes with non-zero microseconds, this produces the wrong va...
Opengraph URL: https://github.com/msgpack/msgpack-python/pull/662
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d3261233-1503-e2ac-7568-e4b5de2e4637 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B6C2:47423:DB082E:12598CF:6A4F013C |
| html-safe-nonce | c0904b34a607fa6bd2557900e766105bfd394e566406095fd7a6284897f591f0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkMyOjQ3NDIzOkRCMDgyRToxMjU5OENGOjZBNEYwMTNDIiwidmlzaXRvcl9pZCI6IjU2NTkzMDk5NTA1MTU0Nzg4NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c83a2f37b4ba3113e80777346c404b5ed5d0239a8ac6f03b541d76d3736b341d |
| hovercard-subject-tag | pull_request:3307600937 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/msgpack/msgpack-python/pull/662/files |
| twitter:image | https://avatars.githubusercontent.com/u/101993364?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/101993364?s=400&v=4 |
| og:image:alt | Timestamp.from_datetime() uses int(dt.timestamp()) to compute the seconds component, but int() truncates towards zero. For pre-epoch datetimes with non-zero microseconds, this produces the wrong va... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/msgpack/msgpack-python git https://github.com/msgpack/msgpack-python.git |
| octolytics-dimension-user_id | 198264 |
| octolytics-dimension-user_login | msgpack |
| octolytics-dimension-repository_id | 2242705 |
| octolytics-dimension-repository_nwo | msgpack/msgpack-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2242705 |
| octolytics-dimension-repository_network_root_nwo | msgpack/msgpack-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b8f23afb982271f1b22258a94aede67a6b77760 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width