File tree 3 files changed +11
-7
lines changed 3 files changed +11
-7
lines changed Original file line number Diff line number Diff line change
1
+ 4.3.1 (2024-10-16)
2
+ ------------------
3
+ - Fix regression in parsing xsd:Date with negative timezone
4
+
1
5
4.3.0 (2024-10-13)
2
6
------------------
3
7
- Drop support for Python 3.7 and 3.8 and add support for Python 3.12 and 3.13 (#1421, #1408)
Original file line number Diff line number Diff line change @@ -201,6 +201,7 @@ def pythonvalue(self, value):
201
201
class Date (BuiltinType ):
202
202
_default_qname = xsd_ns ("date" )
203
203
accepted_types = [datetime .date , str ]
204
+ _pattern = re .compile (r"(\d{4})-(\d{2})-(\d{2})" )
204
205
205
206
@check_no_collection
206
207
def xmlvalue (self , value ):
@@ -215,13 +216,10 @@ def pythonvalue(self, value):
215
216
except isodate .ISO8601Error :
216
217
# Recent versions of isodate don't support timezone in date's. This
217
218
# is not really ISO8601 compliant anway, but we should try to handle
218
- # it. This is a hack to support this.
219
- if "+" in value :
220
- value = value .split ("+" )[0 ]
221
- return isodate .parse_date (value )
222
- if "Z" in value :
223
- value = value .split ("Z" )[0 ]
224
- return isodate .parse_date (value )
219
+ # it, so lets just use a regex to parse the date directly.
220
+ m = self ._pattern .match (value )
221
+ if m :
222
+ return datetime .date (* map (int , m .groups ()))
225
223
raise
226
224
227
225
Original file line number Diff line number Diff line change @@ -242,6 +242,8 @@ def test_pythonvalue(self):
242
242
instance = builtins .Date ()
243
243
assert instance .pythonvalue ("2016-03-04" ) == datetime .date (2016 , 3 , 4 )
244
244
assert instance .pythonvalue ("2001-10-26+02:00" ) == datetime .date (2001 , 10 , 26 )
245
+ assert instance .pythonvalue ("2001-10-26-02:00" ) == datetime .date (2001 , 10 , 26 )
246
+ assert instance .pythonvalue ("2024-08-21-10:00" ) == datetime .date (2024 , 8 , 21 )
245
247
assert instance .pythonvalue ("2001-10-26Z" ) == datetime .date (2001 , 10 , 26 )
246
248
assert instance .pythonvalue ("2001-10-26+00:00" ) == datetime .date (2001 , 10 , 26 )
247
249
assert instance .pythonvalue ("\r \n \t 2016-03-04 " ) == datetime .date (2016 , 3 , 4 )
You can’t perform that action at this time.
0 commit comments