Skip to content

Commit 37a2db2

Browse files
committed
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.
1 parent f1e94ab commit 37a2db2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

loguru/_datetime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def aware_now():
9494
seconds = local.tm_gmtoff
9595
zone = local.tm_zone
9696
except AttributeError:
97-
offset = datetime_.fromtimestamp(timestamp) - datetime_.utcfromtimestamp(timestamp)
97+
# Workaround for Python 3.5.
98+
utc_naive = datetime_.fromtimestamp(timestamp, tz=timezone.utc).replace(tzinfo=None)
99+
offset = datetime_.fromtimestamp(timestamp) - utc_naive
98100
seconds = offset.total_seconds()
99101
zone = strftime("%Z")
100102

0 commit comments

Comments
 (0)