From 37a2db2d416141480abd68eb800a61c9c96b8a10 Mon Sep 17 00:00:00 2001 From: Delgan Date: Sun, 10 Sep 2023 18:30:11 +0200 Subject: [PATCH] Fix deprecation of "datetime.utcfromoffset()" Although it's not recommended, we still use a naive datetime for UTC time (to calculate the local offset). I'm sure there's a more elegant solution, but as this is code for old, untestable platforms, I'd rather not radically change the implementation. --- loguru/_datetime.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loguru/_datetime.py b/loguru/_datetime.py index 892511f9..76626dbe 100644 --- a/loguru/_datetime.py +++ b/loguru/_datetime.py @@ -94,7 +94,9 @@ def aware_now(): seconds = local.tm_gmtoff zone = local.tm_zone except AttributeError: - offset = datetime_.fromtimestamp(timestamp) - datetime_.utcfromtimestamp(timestamp) + # Workaround for Python 3.5. + utc_naive = datetime_.fromtimestamp(timestamp, tz=timezone.utc).replace(tzinfo=None) + offset = datetime_.fromtimestamp(timestamp) - utc_naive seconds = offset.total_seconds() zone = strftime("%Z")