mirror of https://github.com/django/django.git
Refs #29546 -- Removed django.utils.timezone.FixedOffset per deprecation timeline.
This commit is contained in:
parent
3d716467a9
commit
cb2be9d5d5
|
@ -3,7 +3,6 @@ Timezone-related classes and functions.
|
|||
"""
|
||||
|
||||
import functools
|
||||
import warnings
|
||||
from contextlib import ContextDecorator
|
||||
from datetime import datetime, timedelta, timezone, tzinfo
|
||||
|
||||
|
@ -11,7 +10,6 @@ import pytz
|
|||
from asgiref.local import Local
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.deprecation import RemovedInDjango31Warning
|
||||
|
||||
__all__ = [
|
||||
'utc', 'get_fixed_timezone',
|
||||
|
@ -23,40 +21,6 @@ __all__ = [
|
|||
]
|
||||
|
||||
|
||||
# UTC and local time zones
|
||||
|
||||
ZERO = timedelta(0)
|
||||
|
||||
|
||||
class FixedOffset(tzinfo):
|
||||
"""
|
||||
Fixed offset in minutes east from UTC. Taken from Python's docs.
|
||||
|
||||
Kept as close as possible to the reference version. __init__ was changed
|
||||
to make its arguments optional, according to Python's requirement that
|
||||
tzinfo subclasses can be instantiated without arguments.
|
||||
"""
|
||||
|
||||
def __init__(self, offset=None, name=None):
|
||||
warnings.warn(
|
||||
'FixedOffset is deprecated in favor of datetime.timezone',
|
||||
RemovedInDjango31Warning, stacklevel=2,
|
||||
)
|
||||
if offset is not None:
|
||||
self.__offset = timedelta(minutes=offset)
|
||||
if name is not None:
|
||||
self.__name = name
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self.__offset
|
||||
|
||||
def tzname(self, dt):
|
||||
return self.__name
|
||||
|
||||
def dst(self, dt):
|
||||
return ZERO
|
||||
|
||||
|
||||
# UTC time zone as a tzinfo instance.
|
||||
utc = pytz.utc
|
||||
|
||||
|
|
|
@ -835,15 +835,6 @@ appropriate entities.
|
|||
|
||||
:class:`~datetime.tzinfo` instance that represents UTC.
|
||||
|
||||
.. class:: FixedOffset(offset=None, name=None)
|
||||
|
||||
A :class:`~datetime.tzinfo` subclass modeling a fixed offset from UTC.
|
||||
``offset`` is an integer number of minutes east of UTC.
|
||||
|
||||
.. deprecated:: 2.2
|
||||
|
||||
Use :class:`datetime.timezone` instead.
|
||||
|
||||
.. function:: get_fixed_timezone(offset)
|
||||
|
||||
Returns a :class:`~datetime.tzinfo` instance that represents a time zone
|
||||
|
|
|
@ -230,6 +230,8 @@ in Django 3.1.
|
|||
See :ref:`deprecated-features-2.2` for details on these changes, including how
|
||||
to remove usage of these features.
|
||||
|
||||
* ``django.utils.timezone.FixedOffset`` is removed.
|
||||
|
||||
* ``django.contrib.postgres.fields.FloatRangeField`` and
|
||||
``django.contrib.postgres.forms.FloatRangeField`` are removed.
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import datetime
|
||||
import pickle
|
||||
from unittest import mock
|
||||
|
||||
import pytz
|
||||
|
||||
from django.test import SimpleTestCase, ignore_warnings, override_settings
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.utils import timezone
|
||||
from django.utils.deprecation import RemovedInDjango31Warning
|
||||
|
||||
CET = pytz.timezone("Europe/Paris")
|
||||
EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi
|
||||
|
@ -202,24 +200,3 @@ class TimezoneTests(SimpleTestCase):
|
|||
def test_fixedoffset_negative_timedelta(self):
|
||||
delta = datetime.timedelta(hours=-2)
|
||||
self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(None), delta)
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango31Warning)
|
||||
def test_fixedoffset_pickle(self):
|
||||
self.assertEqual(pickle.loads(pickle.dumps(timezone.FixedOffset(0, 'tzname'))).tzname(''), 'tzname')
|
||||
|
||||
def test_fixedoffset_deprecation(self):
|
||||
msg = 'FixedOffset is deprecated in favor of datetime.timezone'
|
||||
with self.assertWarnsMessage(RemovedInDjango31Warning, msg) as cm:
|
||||
timezone.FixedOffset()
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango31Warning)
|
||||
def test_fixedoffset_utcoffset(self):
|
||||
delta = datetime.timedelta(minutes=1)
|
||||
self.assertEqual(timezone.FixedOffset(1).utcoffset(None), delta)
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango31Warning)
|
||||
def test_fixedoffset_dst(self):
|
||||
ZERO = datetime.timedelta(minutes=0)
|
||||
delta = datetime.timedelta(hours=0)
|
||||
self.assertEqual(timezone.FixedOffset().dst(delta), ZERO)
|
||||
|
|
Loading…
Reference in New Issue