Skip to content

Reject nonexistent local datetime inputs - #406

Merged
Eigenwise merged 1 commit into
Eigenwise:mainfrom
Afloat16:datetime-local-gaps
Nov 17, 2026
Merged

Eigenwise merged 1 commit into
Eigenwise:mainfrom
Afloat16:datetime-local-gaps

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

Attaching an IANA timezone with datetime.replace(tzinfo=...) does not validate whether the local clock time exists. The tool currently accepts New York's skipped springtime 02:30 and returns a timestamp that converts back to 03:30. The same issue affects half-hour gaps and entire skipped dates, and propagates into conversion, shifting and differences.

Change

Validate offset-free inputs when attaching their IANA timezone. PEP 495's transition rules distinguish a gap by an increase in the UTC offset from fold=0 to fold=1. Return the existing structured error output for these missing times.

Keep the first occurrence of an ambiguous overlap, the authority of explicitly supplied offsets, and ordinary dates at the datetime range boundaries. Comparing the offsets avoids UTC round-trip overflow for valid local inputs in years 1 and 9999.

This validates input parsing. The separate shift-arithmetic change in #353 handles a valid input whose shifted result crosses a clock change; it is not included here.

Validation

  • New local-time suite: 8 failures and 8 passing controls on unchanged main, then 16 passed with the fix.
  • Complete DateTime tool suite: 29 passed.
  • Cases cover the exact start/end of New York's gap, Lord Howe's half-hour gap, Apia's skipped date, all parsing operations, both diff inputs, overlap default behavior, explicit offsets and year-boundary controls.
  • Complete core suite: 1,152 passed, 14 skipped.
  • Repository-wide Black and Flake8, plus git diff --check, pass.
  • Linux / Python 3.12.14. Tests use the installed IANA timezone data and local datetime operations; no external API calls.

@Eigenwise
Eigenwise merged commit f3a6345 into Eigenwise:main Nov 17, 2026
3 checks passed
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.

2 participants