Skip to content

Commit

Permalink
fix: timezone offset with old pytz and pandas
Browse files Browse the repository at this point in the history
It seems that older pandas and pytz distributions (for example, ones
from Debian 10 deb repositories) are prone to issues when pytz timezone
offset ignores current datetime value [1]. Using explicit localize is
both valid in modern version and fixes the bug for older ones.

1. https://stackoverflow.com/questions/11473721/weird-timezone-issue-with-pytz

Part of #198
  • Loading branch information
DifferentialOrange committed Nov 9, 2022
1 parent af6f4bd commit 7b1d1e3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Puting test files in pip package (#238).
- Make connection close idempotent (#250).
- readthedocs version (#255).
- timezone offset with old pytz and pandas (#198).

## 0.9.0 - 2022-06-20

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rpm-dist-check:

.PHONY: deb-changelog-entry
deb-changelog-entry:
[email protected] dch --distribution unstable \
[email protected] dch --distribution unstable -b \
--package "python3-tarantool" \
--newversion $$(python3 setup.py --version) \
"Nightly build"
Expand Down
6 changes: 3 additions & 3 deletions tarantool/msgpack_ext/types/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def __init__(self, *, timestamp=None, year=None, month=None,
datetime = pandas.to_datetime(timestamp, unit='s')

if not timestamp_since_utc_epoch:
self._datetime = datetime.replace(tzinfo=tzinfo)
self._datetime = datetime.tz_localize(tzinfo)
else:
self._datetime = datetime.replace(tzinfo=pytz.UTC).tz_convert(tzinfo)
self._datetime = datetime.tz_localize(pytz.UTC).tz_convert(tzinfo)
else:
if nsec is not None:
microsecond = nsec // NSEC_IN_MKSEC
Expand All @@ -306,7 +306,7 @@ def __init__(self, *, timestamp=None, year=None, month=None,
year=year, month=month, day=day,
hour=hour, minute=minute, second=sec,
microsecond=microsecond,
nanosecond=nanosecond, tzinfo=tzinfo)
nanosecond=nanosecond).tz_localize(tzinfo)

def _interval_operation(self, other, sign=1):
"""
Expand Down

0 comments on commit 7b1d1e3

Please sign in to comment.