Skip to content

Commit 827f193

Browse files
committed
fix timeutils import warning on Python 3.12+ by removing EPOCH_NAIVE
1 parent 6a363e6 commit 827f193

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

boltons/timeutils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import time
5555
import bisect
5656
import operator
57-
from datetime import tzinfo, timedelta, date, datetime
57+
from datetime import tzinfo, timedelta, date, datetime, timezone
5858

5959

6060
def total_seconds(td):
@@ -70,7 +70,9 @@ def dt_to_timestamp(dt):
7070
7171
.. _Epoch-based timestamps: https://en.wikipedia.org/wiki/Unix_time
7272
73-
>>> abs(round(time.time() - dt_to_timestamp(datetime.utcnow()), 2))
73+
>>> timestamp = int(time.time())
74+
>>> utc_dt = datetime.fromtimestamp(timestamp, timezone.utc)
75+
>>> timestamp - dt_to_timestamp(utc_dt)
7476
0.0
7577
7678
``dt_to_timestamp`` supports both timezone-aware and naïve
@@ -86,7 +88,7 @@ def dt_to_timestamp(dt):
8688
if dt.tzinfo:
8789
td = dt - EPOCH_AWARE
8890
else:
89-
td = dt - EPOCH_NAIVE
91+
td = dt.replace(tzinfo=timezone.utc) - EPOCH_AWARE
9092
return timedelta.total_seconds(td)
9193

9294

@@ -423,7 +425,6 @@ def __repr__(self):
423425

424426
UTC = ConstantTZInfo('UTC')
425427
EPOCH_AWARE = datetime.fromtimestamp(0, UTC)
426-
EPOCH_NAIVE = datetime.utcfromtimestamp(0)
427428

428429

429430
class LocalTZInfo(tzinfo):

0 commit comments

Comments
 (0)