Skip to content

DateComparator applies a different timezone rule to ranges than to single dates #508

Closed

Description

@sromoam

Bug

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.

from stickler.comparators import DateComparator
c = DateComparator()
aware = "2024-01-01T23:00-05:00"      # 2024-01-02 04:00 UTC
print("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

  1. added this to the 1.0.2 milestone on Nov 3, 2026
  2. added
    bug
    on Nov 3, 2026
  3. modified the milestones: 1.0.2, 1.0.3 on Nov 3, 2026
  4. moved this from Backlog to In progress in Stickler Kanbanon Nov 5, 2026
  5. moved this from In progress to Done in Stickler Kanbanon Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions