| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
When a tz-aware datetime is passed, naturalday() and naturaldate() extract the date in the value's timezone but compare it with date.today() which uses system local time. This produces wrong results when the value's timezone differs from the system timezone. Fix: capture the value's tzinfo before converting to a plain date, then derive "today" via datetime.now(tzinfo).date() so both dates are in the same timezone. Fixes python-humanize#152 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #296 +/- ##
==========================================
+ Coverage 99.51% 99.53% +0.01%
==========================================
Files 11 11
Lines 831 859 +28
==========================================
+ Hits 827 855 +28
Misses 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry.
|
Sorry, something went wrong.
|
Please see also similar PR #297, review it, and say which you think is better. |
Sorry, something went wrong.
|
Closing in favor of #297 — both PRs use the same approach (derive "today" from the value's timezone via datetime.now(tzinfo).date()). PR #297 was submitted independently and the implementation is clean. Happy to see the fix land either way! |
Sorry, something went wrong.
|
Thanks for checking, and for the PR! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
When a tz-aware datetime is passed, naturalday() and naturaldate() extract the date in the value's timezone (via dt.date(value.year, value.month, value.day)) but compare it with dt.date.today() which uses system local time. This produces wrong results when the value's timezone differs from the system timezone.
Example from the issue: When the system is in UTC and it's Oct 15 23:00 UTC (Oct 16 10:00 AEDT), calling naturaldate() with an AEDT datetime on Oct 16 should return "today" (both dates are Oct 16 in AEDT), but instead returns "tomorrow" because date.today() returns Oct 15 (the system's UTC date).
Fix
Capture the value's tzinfo before converting to a plain date. If a timezone is present, derive "today" via datetime.now(tzinfo).date() so both dates are in the same timezone.
Test plan
Fixes #152