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: redirect.github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a8c79ccf-07ee-3d57-2196-88f66b4d9eee |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A9BA:E6D1D:1FC0A3:2A71AA:6A51D5D5 |
| html-safe-nonce | a2ca7925da1f13d22bd1d7dee4ec7af76756738916c4cdf35a147f6fa69eaf00 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUJBOkU2RDFEOjFGQzBBMzoyQTcxQUE6NkE1MUQ1RDUiLCJ2aXNpdG9yX2lkIjoiNzQyOTc5MTgxODkyODIxNTUwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8d2cb6d82dc7163833d571d91c83d53495e1afe1efa97b2e36376bee169e2c2e |
| 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 | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width