Skip to content

Format dates without a time zone and drop made-up zone names from %Z - #193

Merged
iantrich merged 1 commit into
masterfrom
claude/ecstatic-einstein-y394gc
Nov 18, 2026
Merged

iantrich merged 1 commit into
masterfrom
claude/ecstatic-einstein-y394gc

Conversation

@iantrich

Copy link
Copy Markdown
Member

Fixes #184 and #186. Both bugs are in the same two date functions in reader.py, so they're fixed together.

#186: dates without a time zone weren't formatted

If a date had no time zone and only dateutil could read it, the sensor kept the raw feed text instead of applying date_format. That covers RFC 822 dates without a zone and 01/02/2024 10:00. _parse_date_string now returns the naive result as well. _parse_date uses it as a last resort and assumes UTC, which is what feedparser already assumes for ISO dates without a zone.

The naive result is used only after feedparser's own *_parsed value. A zone name that dateutil can't resolve (CEST, for example) makes dateutil return a naive time, but feedparser may have read it correctly, so its reading wins.

pubDate (default date_format) before after
Mon, 01 Jan 2024 10:00:00 Mon, 01 Jan 2024 10:00:00 Mon, Jan 01 10:00 AM
01/02/2024 10:00 01/02/2024 10:00 Tue, Jan 02 10:00 AM

#184: %Z printed UTC+01:00

The stdlib names a fixed-offset zone UTC+01:00, and %Z printed that name. Zones that are only an offset now get a nameless dateutil.tz.tzoffset(None, offset), so %Z prints nothing, as it did in 0.1.12. These keep their names:

  • UTC (GMT, Z, +0000) still prints UTC.
  • With local_time, Home Assistant's zone prints its real name, such as CET.

The offset itself is unchanged, so %z and local_time work as before.

Changes for users:

  • Dates with US abbreviations such as EDT now print an empty %Z. The stdlib turns EDT into a plain -04:00 offset, so the name is lost before we see it. 1.x printed UTC-04:00, and 0.1.12 printed nothing.
  • A date without a zone prints %Z as UTC, because it's assumed to be UTC. 1.x already did this for ISO dates without a zone. 0.1.12 printed nothing.

Tests

  • test_date_formats: three dates without a zone.
  • test_zone_name_in_date_format: %Z for offsets, UTC, EDT and dates without a zone.
  • test_local_time_conversion: zoned and zoneless dates converted to Europe/Prague.

8 of the new cases fail on master and pass with this change. The full offline suite passes (252 tests). pre-commit (black, ruff, mypy) is clean, and reader.py compiles under Python 3.13. None of the saved feeds in tests/data needed new expected output.

The README's date-parsing note now says what happens to dates without a zone and to %Z.

Release notes

  • Worth a line saying that %Z is empty again for numeric offsets, since 1.0–1.4 users may have adapted to UTC+01:00.

Generated by Claude Code

A date with no time zone that only dateutil could read (an RFC 822 date
without a zone, or "01/02/2024 10:00") was kept as the raw feed string
instead of being formatted with date_format. Such dates are now taken to
be UTC, the same assumption feedparser makes for ISO dates without a zone.
They're used only after feedparser's own *_parsed value, so dates with
zone names that dateutil can't resolve still use feedparser's reading.

A numeric offset such as +0100 was printed by %Z as "UTC+01:00", the name
the stdlib gives a fixed-offset zone; before 1.0 %Z printed nothing for it.
Offset-only zones now get a nameless tzinfo again, while UTC and real zone
names (including Home Assistant's zone with local_time) keep their names.

Fixes #184
Fixes #186

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvqVzfJq7yZSkZfSyG3YHT
@iantrich
iantrich marked this pull request as ready for review November 17, 2026 18:23
@iantrich
iantrich merged commit 80ee770 into master Nov 18, 2026
10 checks passed
@iantrich
iantrich deleted the claude/ecstatic-einstein-y394gc branch November 18, 2026 01:04
@iantrich iantrich mentioned this pull request Nov 18, 2026
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.

%Z in date_format now prints UTC+01:00 instead of nothing

2 participants