Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed
-----

* Preserve the leading minus when parsing RFC 822 numeric timezones
with a zero hour, such as ``-00:30`` and ``-0030``.
12 changes: 7 additions & 5 deletions src/listparser/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,21 @@ def parse_rfc822(date: str) -> datetime.datetime | None:

# Parse numeric timezones like '-0500' and '+0500'.
if tz_hour is None:
sign = -1 if timezone.startswith("-") else 1
body = timezone[1:] if timezone[:1] in "+-" else timezone
try:
tz_left, tz_right = timezone.split(":")
tz_left, tz_right = body.split(":")
tz_hour = int(tz_left)
tz_min = int(tz_right)
except ValueError:
# Perhaps there was no ':' in *timezone*.
try:
tz_hour = int(timezone[:-2])
tz_min = int(timezone[-2:])
tz_hour = int(body[:-2])
tz_min = int(body[-2:])
except ValueError:
return None
if tz_hour < 0:
tz_min = tz_min * -1
tz_hour *= sign
tz_min *= sign

# Create the datetime and timezone offset return values.
try:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def test_month_names(date, expected_month):
("Mon, 22 Jun 2009 13:15:17 -0430", 13, 15, (-4 * 60) - 30),
("Mon, 22 Jun 2009 13:15:17 +0545", 13, 15, (5 * 60) + 45),
("Mon, 22 Jun 2009 13:15:17 0545", 13, 15, (5 * 60) + 45),
("Mon, 22 Jun 2009 13:15:17 -0030", 13, 15, -30),
("Mon, 22 Jun 2009 13:15:17 -00:30", 13, 15, -30),
("Mon, 22 Jun 2009 13:15:17 +00:30", 13, 15, 30),
# Non-standard timezones
("Mon, 22 Jun 2009 13:15:17 UTC", 13, 15, 0),
("Mon, 22 Jun 2009 13:15:17 Etc/GMT", 13, 15, 0),
Expand Down
Loading