diff --git a/CHANGELOG.md b/CHANGELOG.md index f65f083..2c11ff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,23 @@ # Changelog -## [v1.4.1](https://github.com/SebRut/pygrocy/tree/v1.4.1) (2022-07-28) +## [v1.5.0](https://github.com/SebRut/pygrocy/tree/v1.5.0) (2022-09-19) -[Full Changelog](https://github.com/SebRut/pygrocy/compare/v1.4.0...v1.4.1) +[Full Changelog](https://github.com/SebRut/pygrocy/compare/v1.4.1...v1.5.0) + +**Closed issues:** + +- Update pydantic requirements from 1.10.0 to 1.10.2 [\#252](https://github.com/SebRut/pygrocy/issues/252) **Merged pull requests:** +- Update pydantic requirement from \<1.10.0,\>=1.8.2 to \>=1.8.2,\<1.11.0 [\#251](https://github.com/SebRut/pygrocy/pull/251) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Fix tzlocal dependency causing an exception [\#250](https://github.com/SebRut/pygrocy/pull/250) ([marcelvriend](https://github.com/marcelvriend)) - Fix enabled features lookup [\#248](https://github.com/SebRut/pygrocy/pull/248) ([marcelvriend](https://github.com/marcelvriend)) +## [v1.4.1](https://github.com/SebRut/pygrocy/tree/v1.4.1) (2022-07-28) + +[Full Changelog](https://github.com/SebRut/pygrocy/compare/v1.4.0...v1.4.1) + ## [v1.4.0](https://github.com/SebRut/pygrocy/tree/v1.4.0) (2022-07-24) [Full Changelog](https://github.com/SebRut/pygrocy/compare/v1.3.0...v1.4.0) diff --git a/pygrocy/utils.py b/pygrocy/utils.py index 4e85a91..e139f5f 100644 --- a/pygrocy/utils.py +++ b/pygrocy/utils.py @@ -1,14 +1,10 @@ from datetime import datetime -import iso8601 -import pytz -from tzlocal import get_localzone - def parse_date(input_value): if input_value == "" or input_value is None: return None - return iso8601.parse_date(input_value) + return datetime.fromisoformat(input_value) def parse_int(input_value, default_value=None): @@ -40,8 +36,4 @@ def parse_bool_int(input_value): def localize_datetime(timestamp: datetime) -> datetime: - if timestamp.tzinfo is not None: - return timestamp - - local_tz = get_localzone() - return local_tz.localize(timestamp).astimezone(pytz.utc) + return timestamp.astimezone() diff --git a/setup.py b/setup.py index 253dda9..e2012f8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pygrocy", - version="1.4.1", + version="1.5.0", author="Sebastian Rutofski", author_email="kontakt@sebastian-rutofski.de", description="", @@ -16,11 +16,9 @@ packages=setuptools.find_packages(), install_requires=[ "requests", - "iso8601>=0.1.16,<1.1.0", - "pytz>=2021.1,<2023.0", - "tzlocal>=2.1,<5.0", + "backports.zoneinfo;python_version<'3.9'", # backports can be removed when python 3.8 support is dropped "deprecation~=2.1.0", - "pydantic>=1.8.2,<1.10.0", + "pydantic>=1.8.2,<1.11.0", ], classifiers=[ "Programming Language :: Python :: 3", diff --git a/stackaid.json b/stackaid.json new file mode 100644 index 0000000..f31bc28 --- /dev/null +++ b/stackaid.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "dependencies": [ + { + "source": "https://github.com/psf/requests" + }, + { + "source": "https://github.com/pydantic/pydantic" + }, + { + "source": "https://github.com/tox-dev/tox" + } + ] +} \ No newline at end of file diff --git a/test/test_utils.py b/test/test_utils.py index 171bf0c..06fb838 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,12 +1,17 @@ from datetime import datetime -from unittest import TestCase + +try: + import zoneinfo +except ImportError: + # backports can be removed when python 3.8 support is dropped + from backports import zoneinfo import pygrocy.utils as utils -class TestUtils(TestCase): +class TestUtils: def test_parse_date_valid(self): - date_str = "2019-05-04T11:31:04.563Z" + date_str = "2022-07-10 21:10:53" date_obj = utils.parse_date(date_str) assert isinstance(date_obj, datetime) @@ -58,3 +63,37 @@ def test_parse_float_error(self): float_number = utils.parse_float(float_str, -1) assert float_number == -1 + + def test_localize_datetime_input_timezone_unaware(self): + date = datetime(2022, 7, 10, 21, 17, 34, 633809, tzinfo=None) + + localized_datetime = utils.localize_datetime(date) + + assert localized_datetime == datetime( + 2022, 7, 10, 21, 17, 34, 633809, tzinfo=zoneinfo.ZoneInfo("localtime") + ) + + def test_localize_datetime_input_timezone_aware(self): + date = datetime( + 2022, + 7, + 10, + 13, + 17, + 34, + 633809, + tzinfo=zoneinfo.ZoneInfo("America/Los_Angeles"), + ) + + localized_datetime = utils.localize_datetime(date) + + assert localized_datetime == datetime( + 2022, + 7, + 10, + 13, + 17, + 34, + 633809, + tzinfo=zoneinfo.ZoneInfo("America/Los_Angeles"), + )