You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateComparator applies a different timezone rule to ranges than to single dates #508
The docs give one rule for a naive date against a tz-aware one: "the aware side's tzinfo is borrowed". The single-date path follows it: _align_timezones (comparators/date.py:766-779) stamps the naive side with the aware side's offset.
The range paths do not. _compare_range_single (:429-431) and _jaccard (:566-569) use _normalize_day (:785-795), which converts the aware side to UTC and leaves the naive side as it is. A naive date is therefore read as local time in the single path and as UTC in the range paths.
As a result, the same aware date matches a different calendar day depending on whether the other side is a single date or a range.
Reproduce
Measured on dev at cf90773, with inspect.getfile(stickler) pointing at that tree.
fromstickler.comparatorsimportDateComparatorc=DateComparator()
aware="2024-01-01T23:00-05:00"# 2024-01-02 04:00 UTCprint("single vs single :", c.compare(aware, "2024-01-01"), c.compare(aware, "2024-01-02"))
print("range vs range :", c.compare(f"{aware} to 2024-01-05", "2024-01-01 to 2024-01-05"),
c.compare(f"{aware} to 2024-01-05", "2024-01-02 to 2024-01-05"))
cc=DateComparator(range_mode="contains")
print("single in range :", cc.compare(aware, "2023-12-31 to 2024-01-01"), cc.compare(aware, "2024-01-02 to 2024-01-03"))
single vs single : 1.0 0.0
range vs range : 0.8 1.0
single in range : 0.0 1.0
With the single-date rule, aware is 2024-01-01. With the range rule, it is 2024-01-02.
Expected
Follow the documented rule everywhere: "If both sides are tz-aware, they're normalized to UTC before comparison. If one side is naive and the other aware, the aware side's tzinfo is borrowed" (Guides/Comparators/date-comparator.md:439). Expected output: 1.0 0.0, 1.0 0.8, 1.0 0.0.
Notes
Fix: before calling _normalize_day in the range paths, align each pair with _align_timezones, as the single path does.
This changes range scores for mixed naive/aware inputs only, so it belongs in 1.1.0.
Two planned refactors touch the same file (sharing the range gates, and parsing each string once). Coordinate.
Activity