René's URL Explorer Experiment
Title: Carry the UTC shift into the date in the Rust precise_diff by ybai08 · Pull Request #1060 · python-pendulum/pendulum · GitHub
Open Graph Title: Carry the UTC shift into the date in the Rust precise_diff by ybai08 · Pull Request #1060 · python-pendulum/pendulum
X Title: Carry the UTC shift into the date in the Rust precise_diff by ybai08 · Pull Request #1060 · python-pendulum/pendulum
Description: Pull Request Check List
Added tests for changed code.
Updated documentation for changed code. (no documented behaviour changes)
When the two datetimes are in different time zones (or fall on the same day), the Rust precise_diff moves each one to UTC by adjusting the hour, minute and second fields by hand. That adjustment only carries when a field goes strictly past 60 or 24, and it never carries into the month or year. So:
a time that lands exactly on 24:00 stays as hour 24,
a day pushed past either end of the month becomes day 0 or day 32.
The pure-Python precise_diff subtracts the offset with datetime arithmetic and does not have this problem, so the results depend on whether the extension is loaded:
import pendulum
a = pendulum.datetime(2024, 6, 1, tz="UTC")
b = pendulum.datetime(2024, 6, 1, 20, tz="America/New_York") # 2024-06-02 00:00 UTC
a.diff(b).in_words()
# extension: '24 hours' (diff.days == 1, diff.hours == 24)
# pure Python: '1 day'
a = pendulum.datetime(2023, 6, 1, tz="UTC")
b = pendulum.datetime(2023, 12, 31, 20, tz="America/New_York") # 2024-01-01 01:00 UTC
a.diff(b).in_words()
# extension: '6 months 4 weeks 3 days 1 hour'
# pure Python: '7 months 1 hour'
a = pendulum.datetime(2024, 1, 30, tz="UTC")
b = pendulum.datetime(2024, 3, 1, 5, tz="Asia/Tokyo") # 2024-02-29 20:00 UTC
a.diff(b).in_words()
# extension: '1 month 20 hours'
# pure Python: '4 weeks 2 days 20 hours'
This change does the shift on the total seconds of the day and carries any day change into the day, month and year. Since UTC offsets are always less than a day, the date moves by at most one day. The two hand-written copies (one per datetime) are replaced by one DateTimeInfo::shift_to_utc method.
This is separate from #901 / #906. The example in #901 comes from is_exact_type_of on the second argument, which #953 changes. The new test uses stdlib datetime objects with zoneinfo, so it does not depend on that change.
Testing
New test test_precise_diff_timezone_crossing_a_date_boundary in tests/test_helpers.py. It covers the three cases above, in both argument orders.
Before the fix, with the extension: 1 failed, 18 passed (assert 0 == 1, PreciseDiff(... days=0, hours=24 ...)).
With PENDULUM_EXTENSIONS=0, before and after: 19 passed.
After the fix, with the extension: 19 passed.
pytest -q tests with the extension: 1871 passed, 3 skipped. With PENDULUM_EXTENSIONS=0: 1871 passed, 3 skipped.
A random comparison of pendulum._pendulum.precise_diff against pendulum._helpers.precise_diff. It used 200k pairs per seed and three seeds, with stdlib aware, naive and date inputs over UTC, New York, Paris, Kolkata, Lord Howe, St Johns, Kathmandu and Chatham. Before: 59 mismatches for seed 1. After: 0 mismatches for every seed.
cargo fmt --all -- --check and cargo clippy --tests -- -D warnings are clean, and so are ruff check and ruff format --check (0.14.11) on the test file.
Not run: mypy, PyPy, the codspeed benchmarks, and other platforms (macOS arm64, CPython 3.13 only).
Note: this changes the diff() / Interval results that the extension returns for datetimes in different time zones (or on the same day) when the UTC shift crosses a date boundary. They now match the pure-Python results.
Open Graph Description: Pull Request Check List
Added tests for changed code.
Updated documentation for changed code. (no documented behaviour changes)
When the two datetimes are in different time zones (or fall on th...
X Description: Pull Request Check List
Added tests for changed code.
Updated documentation for changed code. (no documented behaviour changes)
When the two datetimes are in different time zones (or fall on th...
Opengraph URL: https://github.com/python-pendulum/pendulum/pull/1060
X: @github
direct link
Domain: github.com
IPv4 address: 140.82.113.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2bfec845-3575-efd9-7d3b-c9f9a1d12625 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E376:34BF4C:6D7BC9:94E8D5:6B04CD77 |
| html-safe-nonce | 6b2e44e9c1187acae715b6640dd2cf52b9add617735b0eb581384be4346038c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzc2OjM0QkY0Qzo2RDdCQzk6OTRFOEQ1OjZCMDRDRDc3IiwidmlzaXRvcl9pZCI6IjQ0NDc5MzYyMjU5NDQ1ODc2MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 29d131355df9b6321d630e6cdf25a4490bb7d2cfcaed7f7501ba50286fb85f1b |
| hovercard-subject-tag | pull_request:4913778461 |
| 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 | ///pull_requests/show/files |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-pendulum/pendulum/pull/1060/files |
| twitter:image | https://avatars.githubusercontent.com/u/271969568?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/271969568?s=400&v=4 |
| og:image:alt | Pull Request Check List
Added tests for changed code.
Updated documentation for changed code. (no documented behaviour changes)
When the two datetimes are in different time zones (or fall on th... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27ed421e5c2dac040a37529b5b9191edcc4a3de70521471e81fb4b4d9dc2aa7d |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git |
| octolytics-dimension-user_id | 191041900 |
| octolytics-dimension-user_login | python-pendulum |
| octolytics-dimension-repository_id | 62095504 |
| octolytics-dimension-repository_nwo | python-pendulum/pendulum |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62095504 |
| octolytics-dimension-repository_network_root_nwo | python-pendulum/pendulum |
| 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 | 63dc19014c621c67306d7899c04c78dcd0d95803 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Skip to content | https://github.com/python-pendulum/pendulum/pull/1060/files#start-of-content |
| https://github.com/ |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fpull%2F1060%2Ffiles |
| GitHubRepository hosting, code review, and collaboration | https://github.com/platform |
| CopilotAI coding agent for tasks, projects, and automated work | https://github.com/features/copilot |
| ActionsCI/CD and automation | https://github.com/features/actions |
| Code QualityQuality analysis, fixes, and enforcement | https://github.com/features/code-quality |
| CodespacesCloud development environments | https://github.com/features/codespaces |
| Code SecurityVulnerability detection and remediation | https://github.com/security/advanced-security/code-security |
| Secret ProtectionSecret scanning and leak prevention | https://github.com/security/advanced-security/secret-protection |
| All Features | https://github.com/features |
| Documentation | https://docs.github.com/en |
| Training | https://learn.github.com/skills |
| Certifications | https://learn.github.com/credentials |
| Build with Copilot | https://github.com/features/ai |
| Customize Copilot | https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview |
| Integrations | https://github.com/marketplace |
| Trending repos | https://github.com/trending |
| GitHub Sponsors | https://github.com/open-source/sponsors |
| Developer articles | https://github.com/resources/articles |
| ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place. | https://github.blog/changelog/ |
| Enterprises | https://github.com/enterprise |
| Team | https://github.com/team |
| Startups | https://github.com/enterprise/startups |
| Nonprofits | https://github.com/solutions/industry/nonprofits |
| Healthcare | https://github.com/solutions/industry/healthcare |
| Financial services | https://github.com/solutions/industry/financial-services |
| Manufacturing | https://github.com/solutions/industry/manufacturing |
| Government | https://github.com/solutions/industry/government |
| See all industries | https://github.com/solutions/industry |
| Why GitHub | https://github.com/why-github |
| Customer Stories | https://github.com/customer-stories |
| Business insights | https://github.com/solutions/executive-insights |
| Trust Center | https://github.com/trust-center |
| GitHub Advanced SecurityEnterprise-grade code security | https://github.com/security/advanced-security |
| Copilot for businessEnterprise-grade AI features | https://github.com/features/copilot/copilot-business |
| Premium SupportEnterprise-grade 24/7 support | https://github.com/enterprise/premium-support |
| Documentation | https://docs.github.com/en |
| Resource center | https://github.com/resources |
| Blog | https://github.blog/ |
| Events & webinars | https://github.com/resources/events |
| Community Forum | https://github.com/orgs/community/discussions |
| Customer Stories | https://github.com/customer-stories |
| Integrations | https://github.com/marketplace |
| Customer support | https://help.github.com/ |
| Training | https://learn.github.com/skills |
| GitHub Status | https://www.githubstatus.com/ |
| About | https://github.com/about |
| Partners | https://github.com/partners |
| Changelog | https://github.blog/changelog/ |
| GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub. | https://githubuniverse.com/ |
| Pricing | https://github.com/pricing |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fpull%2F1060%2Ffiles |
| Sign up | https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-pendulum%2Fpendulum |
| Reload | https://github.com/python-pendulum/pendulum/pull/1060/files |
| Reload | https://github.com/python-pendulum/pendulum/pull/1060/files |
| Reload | https://github.com/python-pendulum/pendulum/pull/1060/files |
| python-pendulum | https://github.com/python-pendulum |
| pendulum | https://github.com/python-pendulum/pendulum |
| Code | https://github.com/python-pendulum/pendulum |
| Issues211 (211) | https://github.com/python-pendulum/pendulum/issues |
| Pull requests96 (96) | https://github.com/python-pendulum/pendulum/pulls |
| Discussions | https://github.com/python-pendulum/pendulum/discussions |
| Actions | https://github.com/python-pendulum/pendulum/actions |
| Projects | https://github.com/python-pendulum/pendulum/projects |
| Security and quality | https://github.com/python-pendulum/pendulum/security |
| Insights | https://github.com/python-pendulum/pendulum/insights |
| Sign up for GitHub
| https://github.com/signup?return_to=%2Fpython-pendulum%2Fpendulum%2Fissues%2Fnew%2Fchoose |
| terms of service | https://docs.github.com/terms |
| privacy statement | https://docs.github.com/privacy |
| Sign in | https://github.com/login?return_to=%2Fpython-pendulum%2Fpendulum%2Fissues%2Fnew%2Fchoose |
| ybai08 | https://github.com/ybai08 |
| python-pendulum:master | https://github.com/python-pendulum/pendulum/tree/master |
| ybai08:fix-rust-precise-diff-utc-rollover | https://github.com/ybai08/pendulum/tree/fix-rust-precise-diff-utc-rollover |
|
Conversation
0
| https://github.com/python-pendulum/pendulum/pull/1060 |
|
Commits
1
| https://github.com/python-pendulum/pendulum/pull/1060/commits |
|
Checks
0
| https://github.com/python-pendulum/pendulum/pull/1060/checks |
|
Files changed
| https://github.com/python-pendulum/pendulum/pull/1060/files |
| Please reload this page | https://github.com/python-pendulum/pendulum/pull/1060/files |
|
Carry the UTC shift into the date in the Rust precise_diff
| https://github.com/python-pendulum/pendulum/pull/1060/files#top |
|
Show all changes
1 commit
| https://github.com/python-pendulum/pendulum/pull/1060/files |
|
f7c4a44
Carry the UTC shift into the date in the Rust precise_diff
ybai08 Oct 18, 2026
| https://github.com/python-pendulum/pendulum/pull/1060/commits/f7c4a442862aa379d33a67b52f1c5da4037869c1 |
|
Clear filters
| https://github.com/python-pendulum/pendulum/pull/1060/files |
| Please reload this page | https://github.com/python-pendulum/pendulum/pull/1060/files |
| Please reload this page | https://github.com/python-pendulum/pendulum/pull/1060/files |
|
helpers.rs
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
|
test_helpers.py
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-08a6944653efc734f4c8cb856fc854b9f21d655ca69796af2b170c53bff7919e |
| rust/src/python/helpers.rs | https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
|
View file
| https://github.com/python-pendulum/pendulum/blob/f7c4a442862aa379d33a67b52f1c5da4037869c1/rust/src/python/helpers.rs |
|
Open in desktop
| https://desktop.github.com |
| https://github.co/hiddenchars |
| https://github.com/python-pendulum/pendulum/pull/1060/{{ revealButtonHref }} |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-ae49215e00c412d1aae2c37e2ec302b58314c990c63d5ff1e66927d99b063422 |
| tests/test_helpers.py | https://github.com/python-pendulum/pendulum/pull/1060/files#diff-08a6944653efc734f4c8cb856fc854b9f21d655ca69796af2b170c53bff7919e |
|
View file
| https://github.com/python-pendulum/pendulum/blob/f7c4a442862aa379d33a67b52f1c5da4037869c1/tests/test_helpers.py |
|
Open in desktop
| https://desktop.github.com |
| https://github.co/hiddenchars |
| https://github.com/python-pendulum/pendulum/pull/1060/{{ revealButtonHref }} |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-08a6944653efc734f4c8cb856fc854b9f21d655ca69796af2b170c53bff7919e |
|
| https://github.com/python-pendulum/pendulum/pull/1060/files#diff-08a6944653efc734f4c8cb856fc854b9f21d655ca69796af2b170c53bff7919e |
|
| https://github.com |
| Terms | https://docs.github.com/site-policy/github-terms/github-terms-of-service |
| Privacy | https://docs.github.com/site-policy/privacy-policies/github-privacy-statement |
| Security | https://github.com/security |
| Status | https://www.githubstatus.com/ |
| Community | https://github.community/ |
| Docs | https://docs.github.com/ |
| Contact | https://support.github.com?tags=dotcom-footer |
Response headers:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width
URLs of crawlers that visited me.