Skip to content
Open
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
7 changes: 7 additions & 0 deletions changelog.d/20261001_w3dtf_hhmm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fixed
-----

* Keep the minutes of a four-digit timezone offset in W3C dates.

``2003-12-31T10:14:55+0530`` was read as +05:00.
``+05:30`` is unchanged.
11 changes: 9 additions & 2 deletions feedparser/datetimes/w3dtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ def _parse_date_w3dtf(datestr):
# minutes and seconds, if missing, will default to 0.
time.extend(["0"] * (3 - len(time)))
if parts[2][:1] in ("-", "+"):
rest = parts[2][1:]
try:
tzhour = int(parts[2][1:3])
tzmin = int(parts[2][4:])
# ``+0530`` has no colon, so the minutes are the last two digits.
# ``+05:30`` keeps the colon between the hours and the minutes.
if len(rest) == 4 and rest.isdigit():
tzhour = int(rest[:2])
tzmin = int(rest[2:])
else:
tzhour = int(rest[:2])
tzmin = int(rest[3:])
except ValueError:
return None
if parts[2].startswith("-"):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_date_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ def test_year_10000_date():
"2003-12-31T18:14:55+08:00",
(2003, 12, 31, 10, 14, 55, 2, 365, 0),
), # Tokyo timezone
(
_parse_date_w3dtf,
"2003-12-31T10:14:55+0530",
(2003, 12, 31, 4, 44, 55, 2, 365, 0),
), # +hhmm, same offset as +05:30
(
_parse_date_w3dtf,
"2003-12-31T10:14:55-0530",
(2003, 12, 31, 15, 44, 55, 2, 365, 0),
), # -hhmm, same offset as -05:30
(
_parse_date_w3dtf,
"2007-04-23T23:25:47.538+10:00",
Expand Down