Skip to content

Commit e096dbd

Browse files
committed
model.datatypes: Improve BCE date error message
Previously `_parse_xsd_date()` and `_parse_xsd_datetime()` raised `ValueError("Negative Dates are not supported by Python")` when given an XSD value with a leading `-` (BCE year). This was technically false as input is not malformed, only not supported. This change raises `NotImplementedError` instead, allowing callers to distinguish "invalid input" from "known SDK limitation.". Additionally pointing users to https://github.com/eclipse-basyx/basyx-python-sdk/issues to report the lack of implementation.
1 parent 65802ea commit e096dbd

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

sdk/basyx/aas/model/datatypes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ def _parse_xsd_date(value: str) -> Date:
604604
if not match:
605605
raise ValueError("Value is not a valid XSD date string")
606606
if match[1]:
607-
raise ValueError("Negative Dates are not supported by Python")
607+
raise NotImplementedError("Negative dates are not supported: Python stdlib datetime requires year >= 1. "
608+
"Report at https://github.com/eclipse-basyx/basyx-python-sdk/issues")
608609
return Date(int(match[2]), int(match[3]), int(match[4]), _parse_xsd_date_tzinfo(match[5]))
609610

610611

@@ -613,7 +614,8 @@ def _parse_xsd_datetime(value: str) -> DateTime:
613614
if not match:
614615
raise ValueError("Value is not a valid XSD datetime string")
615616
if match[1]:
616-
raise ValueError("Negative Dates are not supported by Python")
617+
raise NotImplementedError("Negative dates are not supported: Python stdlib datetime requires year >= 1. "
618+
"Report at https://github.com/eclipse-basyx/basyx-python-sdk/issues")
617619
microseconds = int(float(match[8]) * 1e6) if match[8] else 0
618620
return DateTime(int(match[2]), int(match[3]), int(match[4]), int(match[5]), int(match[6]), int(match[7]),
619621
microseconds, _parse_xsd_date_tzinfo(match[9]))

sdk/test/model/test_datatypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def test_parse_date(self) -> None:
143143
with self.assertRaises(ValueError) as cm:
144144
model.datatypes.from_xsd("2020-01-24+11", model.datatypes.Date)
145145
self.assertEqual("Value is not a valid XSD date string", str(cm.exception))
146+
with self.assertRaises(NotImplementedError):
147+
model.datatypes.from_xsd("-2020-01-24", model.datatypes.Date)
146148

147149
def test_serialize_date(self) -> None:
148150
self.assertEqual("2020-01-24", model.datatypes.xsd_repr(model.datatypes.Date(2020, 1, 24)))
@@ -211,6 +213,8 @@ def test_parse_datetime(self) -> None:
211213
with self.assertRaises(ValueError) as cm:
212214
model.datatypes.from_xsd("--2020-01-24T15:25:17-00:20", model.datatypes.DateTime)
213215
self.assertEqual("Value is not a valid XSD datetime string", str(cm.exception))
216+
with self.assertRaises(NotImplementedError):
217+
model.datatypes.from_xsd("-2020-01-24T15:25:17+01:00", model.datatypes.DateTime)
214218

215219
def test_serialize_datetime(self) -> None:
216220
self.assertEqual("2020-01-24T15:25:17",

0 commit comments

Comments
 (0)