Skip to content

Fix naturaltime comparisons across daylight-saving transitions - #425

Draft
pralav-25 wants to merge 1 commit into
python-humanize:mainfrom
pralav-25:fix-naturaltime-dst-instants
Draft

pralav-25 wants to merge 1 commit into
python-humanize:mainfrom
pralav-25:fix-naturaltime-dst-instants

Conversation

@pralav-25

Copy link
Copy Markdown

Changes proposed in this pull request:

  • Compare timezone-aware naturaltime() inputs as UTC instants. The current conversion to naive local time erases the repeated DST hour: in America/New_York, 2026-11-01 01:30-04:00 relative to 2026-11-01 01:30-05:00 incorrectly produces now instead of an hour ago. The spring transition can similarly report two elapsed hours for one.
  • Preserve the existing local interpretation of naive inputs when mixed with aware inputs. Keep the all-naive comparison path unchanged, and use the current UTC instant when an aware input omits when.
  • Add six regression cases for fallback in both directions, spring-forward, mixed naive/aware inputs, and the default current time. The initial four explicit-time cases fail before the fix.

Validation on Python 3.12.14/macOS:

  • Full suite with benchmarks disabled: 750 passed, 112 skipped. The skipped translation tests require compiled gettext .mo files unavailable locally.
  • Source doctests: 15 passed.
  • Pinned mypy: clean across 14 source files.
  • All applicable configured prek hooks passed with Python 3.12 overrides in a temporary local configuration; the unmodified configuration selected the host Python 3.9, incompatible with current Black/tox-ini-fmt. No lint configuration changes are included.
  • git diff --check passed.

Prepared and independently reviewed with OpenAI Codex assistance.

@pralav-25
pralav-25 marked this pull request as draft October 2, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant