From 7b1d1e3a274187d70e3ec016fedaf663d7b27eaa Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Tue, 8 Nov 2022 18:34:23 +0300 Subject: [PATCH] fix: timezone offset with old pytz and pandas 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 --- CHANGELOG.md | 1 + Makefile | 2 +- tarantool/msgpack_ext/types/datetime.py | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4526d9d3..12b7ea27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Makefile b/Makefile index 4bf34be6..1ab6441b 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ rpm-dist-check: .PHONY: deb-changelog-entry deb-changelog-entry: - DEBEMAIL=admin@tarantool.org dch --distribution unstable \ + DEBEMAIL=admin@tarantool.org dch --distribution unstable -b \ --package "python3-tarantool" \ --newversion $$(python3 setup.py --version) \ "Nightly build" diff --git a/tarantool/msgpack_ext/types/datetime.py b/tarantool/msgpack_ext/types/datetime.py index f5912dda..d2e4b903 100644 --- a/tarantool/msgpack_ext/types/datetime.py +++ b/tarantool/msgpack_ext/types/datetime.py @@ -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 @@ -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): """