Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRut committed Sep 19, 2022
2 parents ca53339 + c3c2d59 commit 6d5dae7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
14 changes: 12 additions & 2 deletions 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)
Expand Down
12 changes: 2 additions & 10 deletions 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):
Expand Down Expand Up @@ -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()
8 changes: 3 additions & 5 deletions setup.py
Expand Up @@ -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="",
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions 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"
}
]
}
45 changes: 42 additions & 3 deletions 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)
Expand Down Expand Up @@ -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"),
)

0 comments on commit 6d5dae7

Please sign in to comment.