Skip to content

Commit

Permalink
support timezone data in iso date strings
Browse files Browse the repository at this point in the history
The latest release of the isodate package (0.7.2) doesn’t handle
timezone information for dates. While this is indeed not valid according
to the ISO specs we want to handle it anway.

At a workaround by stripping the timezone data ourselves
  • Loading branch information
mvantellingen committed Oct 13, 2024
1 parent 5f35e85 commit 0bf80d6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/zeep/xsd/types/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,19 @@ def xmlvalue(self, value):

@treat_whitespace("collapse")
def pythonvalue(self, value):
return isodate.parse_date(value)
try:
return isodate.parse_date(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)
raise


class gYearMonth(BuiltinType):
Expand Down

2 comments on commit 0bf80d6

@sysnux
Copy link
Contributor

@sysnux sysnux commented on 0bf80d6 Oct 14, 2024

Choose a reason for hiding this comment

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

This does not take into account negative time zones, I'm getting this error:
isodate.isoerror.ISO8601Error: Unrecognised ISO 8601 date format: '2024-08-21-10:00'

@santiagoblancov
Copy link

Choose a reason for hiding this comment

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

This does not take into account negative time zones, I'm getting this error: isodate.isoerror.ISO8601Error: Unrecognised ISO 8601 date format: '2024-08-21-10:00'

What about to take the first 10 characters of the string if string has more than 10?

Also, I have solve this problem fixing the version to the last one that works well in my requirements file.

Please sign in to comment.