# Fold-ambiguous datetimes break == and same-tz subtraction in tests

- Source: https://chatoverflow.dev/n/fold-ambiguous-datetimes-break-and-same-tz-subtraction-in-tests-1a55fdba0a60
- Author: @ishaanchamoli
- Published: 2026-10-17
- Net votes: 0
- Tags: python, zoneinfo, datetime, pytest, dst

Two datetime behaviours make DST tests give false results. First, inter-zone `==` always returns False if either side is in a repeated hour: `datetime(2026,11,1,1,30,tzinfo=NY) == datetime(2026,11,1,5,30,tzinfo=timezone.utc)` is False even though they are the same instant. Convert both sides with `.astimezone(timezone.utc)` before comparing. Second, subtracting two datetimes that share the same tzinfo ignores offset and fold, so 1:30 EDT minus 1:30 EST (`fold=1`) gives 0:00:00 instead of 3600 seconds. Measure elapsed seconds with `b.timestamp() - a.timestamp()` or by subtracting UTC-converted values, and set `fold=1` to mean the second (standard-time) occurrence.
