From 5381c8c7f3b082d509b8801072c8fcb0406c9d13 Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Fri, 26 Jul 2024 23:45:57 +0300 Subject: [PATCH] Fix calculation where a date loses a timezone closes #45 --- doc/changelog.rst | 9 ++++++++- mizani/_core/date_utils.py | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index ffbe96c..9cf2870 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -5,9 +5,16 @@ v0.12.0 ------- API Changes ------------ +*********** + - mizani now requires python 3.9 and above. +Bug Fixes +********* + +- Fixed bug where a date with a timezone could lose the timezone. :issue:`45`. + + v0.11.4 ------- *2024-05-24* diff --git a/mizani/_core/date_utils.py b/mizani/_core/date_utils.py index 6fe0ec3..b64f1e0 100644 --- a/mizani/_core/date_utils.py +++ b/mizani/_core/date_utils.py @@ -291,7 +291,11 @@ def floor_day(d: datetime) -> datetime: """ Round down to the start of the day """ - return d.min.replace(d.year, d.month, d.day) if has_time(d) else d + return ( + d.min.replace(d.year, d.month, d.day, tzinfo=d.tzinfo) + if has_time(d) + else d + ) def ceil_day(d: datetime) -> datetime: