Skip to content

Compare and hash fixed-offset timezones by UTC offset - #641

Open
Arborsen wants to merge 1 commit into
qlustered:devfrom
Arborsen:fix/timezone-comparison-466
Open

Arborsen wants to merge 1 commit into
qlustered:devfrom
Arborsen:fix/timezone-comparison-466

Conversation

@Arborsen

@Arborsen Arborsen commented Oct 6, 2026

Copy link
Copy Markdown

Fixes #466.

Changes

  • Compare concrete datetime.timezone objects using their native offset-based equality.
  • Hash fixed-offset timezones by utcoffset(None), so different offsets are distinguishable in sets and unordered comparisons, while equal offsets with different display names remain equal.
  • Add 23 regression/control cases for root/nested values, ordered/unordered lists, sets, UTC aliases, negative and microsecond offsets, and datetime truncation options.

This keeps timezone objects in change reports for in-memory Delta replay. Custom tzinfo and ZoneInfo behavior is outside this change.

Validation

  • Focused datetime/hash tests: 142 passed.
  • Full suite including slow tests: 1,332 passed, 8 skipped; 95% total coverage.
  • Original reproduction and controls: 10 passed.
  • Fatal lint checks and git diff --check: passed.
  • Pyright reports the same 50 errors as unchanged dev; no new diagnostics.
  • Tested with Python 3.12.14.

Known limitation for review

The timezone hash follows the existing scalar hashing convention, which shares a namespace with user strings. Consequently, DeepDiff([timezone.utc], ['timezone:0:00:00'], ignore_order=True) returns an empty diff with this change, whereas the baseline reports a type change. Equivalent collisions already exist for other scalars (for example, 1 and 'int:1'). This patch does not redesign hash domain separation; maintainer guidance on the intended scope is welcome.

Existing timezone serialization requirements are unchanged: JSON output needs an appropriate default_mapping, and persisted Delta loading may require safe_to_import={'datetime.timezone'}.

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