Skip to content

Commit

Permalink
Replace deprecated datetime.utcfromtimestamp()
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Aug 3, 2023
1 parent efeb395 commit 8d38f87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ section for more details)
Converting between timezones is more easily done, using the
standard astimezone method.

>>> utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899))
>>> utc_dt = datetime.fromtimestamp(1143408899, tz=utc)
>>> utc_dt.strftime(fmt)
'2006-03-26 21:34:59 UTC+0000'
>>> au_tz = timezone('Australia/Sydney')
Expand All @@ -166,7 +166,7 @@ conversions. ``normalize()`` and ``localize()`` are not really
necessary when there are no daylight saving time transitions to
deal with.

>>> utc_dt = datetime.utcfromtimestamp(1143408899).replace(tzinfo=utc)
>>> utc_dt = datetime.fromtimestamp(1143408899, tz=utc)
>>> utc_dt.strftime(fmt)
'2006-03-26 21:34:59 UTC+0000'
>>> au_tz = timezone('Australia/Sydney')
Expand Down Expand Up @@ -605,4 +605,3 @@ Contact
~~~~~~~

Stuart Bishop <stuart@stuartbishop.net>

6 changes: 3 additions & 3 deletions src/pytz/tzinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''Base classes and helpers for building zone specific tzinfo classes'''

from datetime import datetime, timedelta, tzinfo
from datetime import datetime, timedelta, timezone, tzinfo
from bisect import bisect_right
try:
set
Expand All @@ -24,7 +24,7 @@ def memorized_timedelta(seconds):
_timedelta_cache[seconds] = delta
return delta

_epoch = datetime.utcfromtimestamp(0)
_epoch = datetime.fromtimestamp(0, tz=timezone.utc)
_datetime_cache = {0: _epoch}


Expand All @@ -33,7 +33,7 @@ def memorized_datetime(seconds):
try:
return _datetime_cache[seconds]
except KeyError:
# NB. We can't just do datetime.utcfromtimestamp(seconds) as this
# NB. We can't just do datetime.fromtimestamp(seconds, tz=timezone.utc) as this
# fails with negative values under Windows (Bug #90096)
dt = _epoch + timedelta(seconds=seconds)
_datetime_cache[seconds] = dt
Expand Down

0 comments on commit 8d38f87

Please sign in to comment.