Skip to content

Commit

Permalink
fix timeutils import warning on Python 3.12+ by removing EPOCH_NAIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed Jun 24, 2024
1 parent 6a363e6 commit 1bca5e9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions boltons/timeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import time
import bisect
import operator
from datetime import tzinfo, timedelta, date, datetime
from datetime import tzinfo, timedelta, date, datetime, timezone


def total_seconds(td):
Expand All @@ -70,7 +70,9 @@ def dt_to_timestamp(dt):
.. _Epoch-based timestamps: https://en.wikipedia.org/wiki/Unix_time
>>> abs(round(time.time() - dt_to_timestamp(datetime.utcnow()), 2))
>>> timestamp = int(time.time())
>>> utc_dt = datetime.fromtimestamp(timestamp, timezone.utc)
>>> timestamp - dt_to_timestamp(utc_dt)
0.0
``dt_to_timestamp`` supports both timezone-aware and naïve
Expand All @@ -86,7 +88,7 @@ def dt_to_timestamp(dt):
if dt.tzinfo:
td = dt - EPOCH_AWARE
else:
td = dt - EPOCH_NAIVE
td = dt.replace(tzinfo=timezone.utc) - EPOCH_AWARE
return timedelta.total_seconds(td)


Expand Down Expand Up @@ -423,7 +425,6 @@ def __repr__(self):

UTC = ConstantTZInfo('UTC')
EPOCH_AWARE = datetime.fromtimestamp(0, UTC)
EPOCH_NAIVE = datetime.utcfromtimestamp(0)


class LocalTZInfo(tzinfo):
Expand Down

0 comments on commit 1bca5e9

Please sign in to comment.