Add support for ISO 8601 dates in OPML files#124
Conversation
There was a problem hiding this comment.
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.
src/listparser/dates.py
Outdated
| 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"$" | ||
| ) |
There was a problem hiding this comment.
Compiling the regex each time the function is can be improved by compiling the regex outside the function.
src/listparser/dates.py
Outdated
| tzinfo = datetime.timezone( | ||
| datetime.timedelta(minutes=sign * ((tz_hour * 60) + tz_minute)) | ||
| ) |
There was a problem hiding this comment.
It's possible to trigger a ValueError here if the timezone were something like +99:00.
tests/test_iso8601.py
Outdated
| ] | ||
|
|
||
| for input_date, expected_datetime in test_cases: | ||
| with self.subTest(input_date=input_date): |
There was a problem hiding this comment.
I wasn't aware of this .subTest() method -- neat! However, the project uses pytest with parametrization, so I want these tests to use that.
Fixes issue described in #123 by implementing a path to parse ISO 8601 dates.