Skip to content
Merged
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions src/dve/metadata_parser/domain_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@

DATE_FORMAT: ClassVar[Optional[str]] = None
"""The specific format of the date as a Python 'strptime' string."""
strict: ClassVar[Optional[bool]] = False
"""Add additional check to ensure that date supplied meets the date format exactly."""
ge: ClassVar[Optional[dt.date]] = None
"""The earliest date allowed."""
le: ClassVar[Optional[dt.date]] = None
Expand All @@ -280,12 +282,17 @@
elif cls.DATE_FORMAT is not None:
try:
date = dt.datetime.strptime(value, cls.DATE_FORMAT).date()
if cls.strict and not (date.strftime(cls.DATE_FORMAT) == value):

Check warning on line 285 in src/dve/metadata_parser/domain_types.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the opposite operator ("!=") instead.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_data-validation-engine&issues=AZze6PEXPx0CsSSXVh45&open=AZze6PEXPx0CsSSXVh45&pullRequest=70
raise ValueError
except ValueError as err:
raise ValueError(
f"Unable to parse provided datetime in format {cls.DATE_FORMAT}"
) from err # pylint: disable=line-too-long
else:
raise ValueError("No date format provided")




return date

Expand Down Expand Up @@ -317,6 +324,7 @@
@validate_arguments
def conformatteddate(
date_format: Optional[str] = None,
strict: Optional[bool] = False,
ge: Optional[dt.date] = None, # pylint: disable=invalid-name
le: Optional[dt.date] = None, # pylint: disable=invalid-name
gt: Optional[dt.date] = None, # pylint: disable=invalid-name
Expand All @@ -331,6 +339,7 @@

dict_ = ConFormattedDate.__dict__.copy()
dict_["DATE_FORMAT"] = date_format
dict_["strict"] = strict
dict_["ge"] = ge
dict_["le"] = le
dict_["gt"] = gt
Expand Down
Loading