Skip to content

Commit

Permalink
Merge pull request #182 from sdementen/fix-tzlocal-change
Browse files Browse the repository at this point in the history
fix #180 (tzlocal upgrade)
  • Loading branch information
sdementen committed Aug 18, 2021
2 parents 5621c1d + 36a94bd commit becbe84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,11 @@
What's new
==========

devel
~~~~~

- fix tzlocal>=2.3 issue with change of tz type returned by tzlocal.get_localzone() (fix #180)

Version 1.1.7 (2021-04-04)
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions piecash/sa_extra.py
Expand Up @@ -69,7 +69,7 @@ def __repr__(self):
return str(self)


tz = tzlocal.get_localzone()
tz = pytz.timezone(str(tzlocal.get_localzone()))
utc = pytz.utc


Expand Down Expand Up @@ -158,8 +158,8 @@ def process_bind_param(self, value, dialect):

def process_result_value(self, value, dialect):
if value is not None:
r = utc.localize(value).astimezone(tz).date()
return r
r = utc.localize(value).astimezone(tz)
return r.date()


class _Date(types.TypeDecorator):
Expand Down
9 changes: 5 additions & 4 deletions tests/test_factories.py
Expand Up @@ -5,6 +5,7 @@
from decimal import Decimal

import pytest
import pytz
import tzlocal

from piecash import GnucashException, Commodity
Expand Down Expand Up @@ -127,13 +128,13 @@ def test_single_transaction(self, book_basic):
assert sp2.account == book_basic.accounts(name="asset")
assert sp1.value == -sp2.value
assert sp1.quantity == sp1.value
assert tr.enter_date == tzlocal.get_localzone().localize(
assert tr.enter_date == pytz.timezone(str(tzlocal.get_localzone())).localize(
today.replace(microsecond=0)
)
assert tr.post_date == tzlocal.get_localzone().localize(today).date()
assert tr.post_date == pytz.timezone(str(tzlocal.get_localzone())).localize(today).date()

def test_single_transaction_tz(self, book_basic):
today = tzlocal.get_localzone().localize(datetime.today())
today = pytz.timezone(str(tzlocal.get_localzone())).localize(datetime.today())
tr = factories.single_transaction(
today.date(),
today,
Expand All @@ -148,7 +149,7 @@ def test_single_transaction_tz(self, book_basic):
assert tr.enter_date == today.replace(microsecond=0)

def test_single_transaction_rollback(self, book_basic):
today = tzlocal.get_localzone().localize(datetime.today())
today = pytz.timezone(str(tzlocal.get_localzone())).localize(datetime.today())
factories.single_transaction(
today.date(),
today,
Expand Down

0 comments on commit becbe84

Please sign in to comment.