Skip to content

Commit

Permalink
Fix regression in parsing xsd:Date with negative timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
mvantellingen committed Oct 16, 2024
1 parent 3b20576 commit d1b0257
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
4.3.1 (2024-10-16)
------------------
- Fix regression in parsing xsd:Date with negative timezone

4.3.0 (2024-10-13)
------------------
- Drop support for Python 3.7 and 3.8 and add support for Python 3.12 and 3.13 (#1421, #1408)
Expand Down
12 changes: 5 additions & 7 deletions src/zeep/xsd/types/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def pythonvalue(self, value):
class Date(BuiltinType):
_default_qname = xsd_ns("date")
accepted_types = [datetime.date, str]
_pattern = re.compile(r"(\d{4})-(\d{2})-(\d{2})")

@check_no_collection
def xmlvalue(self, value):
Expand All @@ -215,13 +216,10 @@ def pythonvalue(self, value):
except isodate.ISO8601Error:
# Recent versions of isodate don't support timezone in date's. This
# is not really ISO8601 compliant anway, but we should try to handle
# it. This is a hack to support this.
if "+" in value:
value = value.split("+")[0]
return isodate.parse_date(value)
if "Z" in value:
value = value.split("Z")[0]
return isodate.parse_date(value)
# it, so lets just use a regex to parse the date directly.
m = self._pattern.match(value)
if m:
return datetime.date(*map(int, m.groups()))
raise


Expand Down
2 changes: 2 additions & 0 deletions tests/test_xsd_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def test_pythonvalue(self):
instance = builtins.Date()
assert instance.pythonvalue("2016-03-04") == datetime.date(2016, 3, 4)
assert instance.pythonvalue("2001-10-26+02:00") == datetime.date(2001, 10, 26)
assert instance.pythonvalue("2001-10-26-02:00") == datetime.date(2001, 10, 26)
assert instance.pythonvalue("2024-08-21-10:00") == datetime.date(2024, 8, 21)
assert instance.pythonvalue("2001-10-26Z") == datetime.date(2001, 10, 26)
assert instance.pythonvalue("2001-10-26+00:00") == datetime.date(2001, 10, 26)
assert instance.pythonvalue("\r\n\t 2016-03-04 ") == datetime.date(2016, 3, 4)
Expand Down

0 comments on commit d1b0257

Please sign in to comment.