Repository navigation
Format dates without a time zone and drop made-up zone names from %Z - #193
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 and01/02/2024 10:00._parse_date_stringnow returns the naive result as well._parse_dateuses 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
*_parsedvalue. 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(defaultdate_format)Mon, 01 Jan 2024 10:00:00Mon, 01 Jan 2024 10:00:00Mon, Jan 01 10:00 AM01/02/2024 10:0001/02/2024 10:00Tue, Jan 02 10:00 AM#184:
%ZprintedUTC+01:00The stdlib names a fixed-offset zone
UTC+01:00, and%Zprinted that name. Zones that are only an offset now get a namelessdateutil.tz.tzoffset(None, offset), so%Zprints nothing, as it did in 0.1.12. These keep their names:GMT,Z,+0000) still printsUTC.local_time, Home Assistant's zone prints its real name, such asCET.The offset itself is unchanged, so
%zandlocal_timework as before.Changes for users:
EDTnow print an empty%Z. The stdlib turnsEDTinto a plain-04:00offset, so the name is lost before we see it. 1.x printedUTC-04:00, and 0.1.12 printed nothing.%ZasUTC, 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:%Zfor offsets, UTC,EDTand dates without a zone.test_local_time_conversion: zoned and zoneless dates converted to Europe/Prague.8 of the new cases fail on
masterand pass with this change. The full offline suite passes (252 tests). pre-commit (black, ruff, mypy) is clean, andreader.pycompiles under Python 3.13. None of the saved feeds intests/dataneeded new expected output.The README's date-parsing note now says what happens to dates without a zone and to
%Z.Release notes
%Zis empty again for numeric offsets, since 1.0–1.4 users may have adapted toUTC+01:00.Generated by Claude Code