Skip to content
Merged
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
40 changes: 17 additions & 23 deletions aas_core3_rc02/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,15 +1274,14 @@ def _is_leap_year(year: int) -> bool:


def is_xs_date(value: str) -> bool:
"""
Check that :paramref:`value` is a valid ``xs:date``.

We can not use :py:func:`datetime.date.strptime` as it does not
handle years below 1000 correctly on Windows (*e.g.*, ``-999-01-01``).
"""
if matches_xs_date(value) is False:
"""Check that :paramref:`value` is a valid ``xs:date``."""
if not matches_xs_date(value):
return False

# NOTE (mristin, 2022-11-23):
# We can not use :py:func:`datetime.datetime.strptime` as it does not
# handle years below 1000 correctly on Windows (*e.g.*, ``-999-01-01``).

# NOTE (mristin, 2022-10-30):
# We need to match the prefix as zone offsets are allowed in the dates. Optimally,
# we would re-use the pattern matching from :py:func`matches_xs_date`, but this
Expand Down Expand Up @@ -1312,39 +1311,34 @@ def is_xs_date(value: str) -> bool:
else:
max_days = _DAYS_IN_MONTH[month]

# We accept the zero year for astronomical settings,
# see: https://en.wikipedia.org/wiki/Year_zero

if day > max_days:
return False

return True


def is_xs_date_time(value: str) -> bool:
"""
Check that :paramref:`value` is a valid ``xs:dateTime``.
"""Check that :paramref:`value` is a valid ``xs:dateTime``."""
# NOTE (mristin, 2022-11-23):
# We can not use :py:func:`datetime.datetime.strptime` as it does not
# handle years below 1000 correctly on Windows (*e.g.*, ``-999-01-01``).

We can not use :py:func:`datetime.datetime.strptime` as it does not
handle years below 1000 correctly on Windows (*e.g.*, ``-999-01-01``).
"""
if matches_xs_date_time(value) is False:
if not matches_xs_date_time(value):
return False

date, _ = value.split("T")
return is_xs_date(date)


def is_xs_date_time_stamp(value: str) -> bool:
"""
Check that :paramref:`value` is a valid ``xs:dateTimeStamp``.

We can not use :py:func:`datetime.datetime.strptime` as it does not
handle years below 1000 correctly on Windows (*e.g.*, ``-999-01-01``).
"""
if matches_xs_date_time_stamp(value) is False:
"""Check that :paramref:`value` is a valid ``xs:dateTimeStamp``."""
if not matches_xs_date_time_stamp(value):
return False

# NOTE (mristin, 2022-11-23):
# We can not use :py:func:`datetime.datetime.strptime` as it does not
# handle years below 1000 correctly on Windows (*e.g.*, ``-999-01-01``).

date, _ = value.split("T")
return is_xs_date(date)

Expand Down