diff --git a/src/README.rst b/src/README.rst index 1af9169..c7ef642 100644 --- a/src/README.rst +++ b/src/README.rst @@ -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') @@ -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') @@ -605,4 +605,3 @@ Contact ~~~~~~~ Stuart Bishop - diff --git a/src/pytz/tests/test_tzinfo.py b/src/pytz/tests/test_tzinfo.py index 7d6d788..16018fa 100644 --- a/src/pytz/tests/test_tzinfo.py +++ b/src/pytz/tests/test_tzinfo.py @@ -539,7 +539,7 @@ class NoumeaDSTEndTestCase(USEasternDSTStartTestCase): class NoumeaNoMoreDSTTestCase(NoumeaDSTEndTestCase): - # Noumea dropped DST in 1997. Here we test that it stops occuring. + # Noumea dropped DST in 1997. Here we test that it stops occurring. transition_time = ( NoumeaDSTEndTestCase.transition_time + timedelta(days=365 * 10)) before = NoumeaDSTEndTestCase.after diff --git a/src/pytz/tzinfo.py b/src/pytz/tzinfo.py index 725978d..6e20cb1 100644 --- a/src/pytz/tzinfo.py +++ b/src/pytz/tzinfo.py @@ -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 @@ -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).replace(tzinfo=None) _datetime_cache = {0: _epoch} @@ -33,8 +33,8 @@ def memorized_datetime(seconds): try: return _datetime_cache[seconds] except KeyError: - # NB. We can't just do datetime.utcfromtimestamp(seconds) as this - # fails with negative values under Windows (Bug #90096) + # NB. We can't just do datetime.fromtimestamp(seconds, tz=timezone.utc).replace(tzinfo=None) + # as this fails with negative values under Windows (Bug #90096) dt = _epoch + timedelta(seconds=seconds) _datetime_cache[seconds] = dt return dt @@ -355,7 +355,7 @@ def localize(self, dt, is_dst=False): is_dst=False) + timedelta(hours=6) # If we get this far, we have multiple possible timezones - this - # is an ambiguous case occuring during the end-of-DST transition. + # is an ambiguous case occurring during the end-of-DST transition. # If told to be strict, raise an exception since we have an # ambiguous case