Skip to content

Add support for ISO 8601 dates in OPML files#124

Merged
kurtmckee merged 2 commits intokurtmckee:mainfrom
allenhutchison:fix-iso8601-dates
Apr 9, 2025
Merged

Add support for ISO 8601 dates in OPML files#124
kurtmckee merged 2 commits intokurtmckee:mainfrom
allenhutchison:fix-iso8601-dates

Conversation

@allenhutchison
Copy link
Contributor

Fixes issue described in #123 by implementing a path to parse ISO 8601 dates.

Copy link
Owner

@kurtmckee kurtmckee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this, Allen! I left feedback on your original commit, but I also pushed an additional commit that addresses that feedback.

I also switched from "ISO 8601" to "RFC 3339" as the identifier, which more closely describes the datetime format that's supported here.

Comment on lines 189 to 200
iso_pattern = re.compile(
r"^(\d{4})-" # Year
r"(\d{2})-" # Month
r"(\d{2})" # Day
r"[T ]" # T or space separator
r"(\d{2}):" # Hour
r"(\d{2}):" # Minute
r"(\d{2})" # Second
r"(?:\.(\d+))?" # Optional fractional seconds
r"(Z|[+-]\d{2}:?\d{2})?" # Optional timezone (Z or +/-HH:MM)
r"$"
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiling the regex each time the function is can be improved by compiling the regex outside the function.

Comment on lines 237 to 239
tzinfo = datetime.timezone(
datetime.timedelta(minutes=sign * ((tz_hour * 60) + tz_minute))
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to trigger a ValueError here if the timezone were something like +99:00.

]

for input_date, expected_datetime in test_cases:
with self.subTest(input_date=input_date):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of this .subTest() method -- neat! However, the project uses pytest with parametrization, so I want these tests to use that.

@kurtmckee kurtmckee linked an issue Apr 9, 2025 that may be closed by this pull request
@kurtmckee kurtmckee merged commit 45dd347 into kurtmckee:main Apr 9, 2025
5 checks passed
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.

OPML Files with ISO 8601 dates cause failures in listparser.

2 participants