diff --git a/dev_requirements/requirements-type_check.in b/dev_requirements/requirements-type_check.in index 4446a91..0944839 100644 --- a/dev_requirements/requirements-type_check.in +++ b/dev_requirements/requirements-type_check.in @@ -1,2 +1,3 @@ # specific requirements for the tox type_check environment mypy +types-pytz diff --git a/dev_requirements/requirements-type_check.txt b/dev_requirements/requirements-type_check.txt index 0332a5b..2131bc8 100644 --- a/dev_requirements/requirements-type_check.txt +++ b/dev_requirements/requirements-type_check.txt @@ -1,13 +1,14 @@ -# SHA1:7983aaa01d64547827c20395d77e248c41b2572f # -# This file is autogenerated by pip-compile-multi -# To update, run: +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: # -# pip-compile-multi +# pip-compile requirements-type_check.in # mypy==1.11.1 - # via -r dev_requirements/requirements-type_check.in + # via -r requirements-type_check.in mypy-extensions==1.0.0 # via mypy +types-pytz==2024.1.0.20240417 + # via -r requirements-type_check.in typing-extensions==4.10.0 # via mypy diff --git a/pyproject.toml b/pyproject.toml index 8c2b673..2bab039 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", ] -dependencies = [] # add all the dependencies here +dependencies = ["pytz"] # add all the dependencies here dynamic = ["readme", "version"] [project.urls] diff --git a/requirements.txt b/requirements.txt index 79ca470..7a78c06 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ # # pip-compile pyproject.toml # +pytz==2024.1 + # via efoli (pyproject.toml) diff --git a/src/efoli/edifact_format_version.py b/src/efoli/edifact_format_version.py index d20fd42..d0d168a 100644 --- a/src/efoli/edifact_format_version.py +++ b/src/efoli/edifact_format_version.py @@ -1,9 +1,14 @@ """contains the EdifactFormatVersion enum""" import datetime +from typing import Union + +import pytz from .strenum import StrEnum +_berlin = pytz.timezone("Europe/Berlin") + class EdifactFormatVersion(StrEnum): """ @@ -25,7 +30,7 @@ def __str__(self) -> str: return self.value -def get_edifact_format_version(key_date: datetime.datetime) -> EdifactFormatVersion: +def get_edifact_format_version(key_date: Union[datetime.datetime, datetime.date]) -> EdifactFormatVersion: """ Retrieves the appropriate Edifact format version applicable for the given key date. @@ -36,6 +41,8 @@ def get_edifact_format_version(key_date: datetime.datetime) -> EdifactFormatVers :param key_date: The date for which the Edifact format version is to be determined. :return: The Edifact format version valid for the specified key date. """ + if not isinstance(key_date, datetime.datetime) and isinstance(key_date, datetime.date): + key_date = _berlin.localize(datetime.datetime.combine(key_date, datetime.time(0, 0, 0, 0))) format_version_thresholds = [ (datetime.datetime(2021, 9, 30, 22, 0, 0, 0, tzinfo=datetime.timezone.utc), EdifactFormatVersion.FV2104), (datetime.datetime(2022, 9, 30, 22, 0, 0, 0, tzinfo=datetime.timezone.utc), EdifactFormatVersion.FV2110), diff --git a/unittests/test_edifact_format_version.py b/unittests/test_edifact_format_version.py index 674e220..7d04e61 100644 --- a/unittests/test_edifact_format_version.py +++ b/unittests/test_edifact_format_version.py @@ -1,4 +1,4 @@ -from datetime import datetime, timezone +from datetime import date, datetime, timezone import pytest @@ -11,7 +11,12 @@ pytest.param( datetime(2021, 1, 1, 0, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2104, - id="Anything before 2021-04-01", + id="Anything before 2021-04-01 (datetime)", + ), + pytest.param( + date(2021, 1, 1), + EdifactFormatVersion.FV2104, + id="Anything before 2021-04-01 (date)", ), pytest.param(datetime(2021, 5, 1, 0, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2104), pytest.param(datetime(2021, 10, 1, 0, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2110), @@ -28,6 +33,8 @@ pytest.param(datetime(2024, 9, 30, 22, 0, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2410), pytest.param(datetime(2025, 3, 31, 22, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2410), pytest.param(datetime(2025, 4, 3, 22, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2504), + pytest.param(date(2025, 4, 3), EdifactFormatVersion.FV2410), + pytest.param(date(2025, 4, 4), EdifactFormatVersion.FV2504), pytest.param(datetime(2025, 9, 30, 22, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2510), pytest.param( datetime(2050, 10, 1, 0, 0, 0, tzinfo=timezone.utc), EdifactFormatVersion.FV2510