summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-11-18 11:21:21 -0500
committerTim Graham <timograham@gmail.com>2015-01-17 09:32:33 -0500
commit1b0365ad34151f266fe3faecb4edf31a51a8642c (patch)
tree4258aacd6970e4dffba58c8e8878b9679da53a31
parent25264d4e2a4b3fd6a25e6b617388ea24f3d48d63 (diff)
Removed django.utils.tzinfo per deprecation timeline; refs #17262.
-rw-r--r--django/utils/tzinfo.py117
-rw-r--r--docs/ref/utils.txt23
-rw-r--r--tests/utils_tests/test_tzinfo.py92
3 files changed, 0 insertions, 232 deletions
diff --git a/django/utils/tzinfo.py b/django/utils/tzinfo.py
deleted file mode 100644
index 25efd20222..0000000000
--- a/django/utils/tzinfo.py
+++ /dev/null
@@ -1,117 +0,0 @@
-"Implementation of tzinfo classes for use with datetime.datetime."
-
-from __future__ import unicode_literals
-
-from datetime import timedelta, tzinfo
-import time
-import warnings
-
-from django.utils.deprecation import RemovedInDjango19Warning
-from django.utils.encoding import force_str, force_text, DEFAULT_LOCALE_ENCODING
-
-warnings.warn(
- "django.utils.tzinfo will be removed in Django 1.9. "
- "Use django.utils.timezone instead.",
- RemovedInDjango19Warning, stacklevel=2)
-
-
-# Python's doc say: "A tzinfo subclass must have an __init__() method that can
-# be called with no arguments". FixedOffset and LocalTimezone don't honor this
-# requirement. Defining __getinitargs__ is sufficient to fix copy/deepcopy as
-# well as pickling/unpickling.
-
-class FixedOffset(tzinfo):
- "Fixed offset in minutes east from UTC."
- def __init__(self, offset):
- warnings.warn(
- "django.utils.tzinfo.FixedOffset will be removed in Django 1.9. "
- "Use django.utils.timezone.get_fixed_timezone instead.",
- RemovedInDjango19Warning)
- if isinstance(offset, timedelta):
- self.__offset = offset
- offset = self.__offset.seconds // 60
- else:
- self.__offset = timedelta(minutes=offset)
-
- sign = '-' if offset < 0 else '+'
- self.__name = "%s%02d%02d" % (sign, abs(offset) / 60., abs(offset) % 60)
-
- def __repr__(self):
- return self.__name
-
- def __getinitargs__(self):
- return self.__offset,
-
- def utcoffset(self, dt):
- return self.__offset
-
- def tzname(self, dt):
- return self.__name
-
- def dst(self, dt):
- return timedelta(0)
-
-
-# This implementation is used for display purposes. It uses an approximation
-# for DST computations on dates >= 2038.
-
-# A similar implementation exists in django.utils.timezone. It's used for
-# timezone support (when USE_TZ = True) and focuses on correctness.
-
-class LocalTimezone(tzinfo):
- "Proxy timezone information from time module."
- def __init__(self, dt):
- warnings.warn(
- "django.utils.tzinfo.LocalTimezone will be removed in Django 1.9. "
- "Use django.utils.timezone.get_default_timezone instead.",
- RemovedInDjango19Warning)
- tzinfo.__init__(self)
- self.__dt = dt
- self._tzname = self.tzname(dt)
-
- def __repr__(self):
- return force_str(self._tzname)
-
- def __getinitargs__(self):
- return self.__dt,
-
- def utcoffset(self, dt):
- if self._isdst(dt):
- return timedelta(seconds=-time.altzone)
- else:
- return timedelta(seconds=-time.timezone)
-
- def dst(self, dt):
- if self._isdst(dt):
- return timedelta(seconds=-time.altzone) - timedelta(seconds=-time.timezone)
- else:
- return timedelta(0)
-
- def tzname(self, dt):
- is_dst = False if dt is None else self._isdst(dt)
- try:
- return force_text(time.tzname[is_dst], DEFAULT_LOCALE_ENCODING)
- except UnicodeDecodeError:
- return None
-
- def _isdst(self, dt):
- tt = (dt.year, dt.month, dt.day,
- dt.hour, dt.minute, dt.second,
- dt.weekday(), 0, 0)
- try:
- stamp = time.mktime(tt)
- except (OverflowError, ValueError):
- # 32 bit systems can't handle dates after Jan 2038, and certain
- # systems can't handle dates before ~1901-12-01:
- #
- # >>> time.mktime((1900, 1, 13, 0, 0, 0, 0, 0, 0))
- # OverflowError: mktime argument out of range
- # >>> time.mktime((1850, 1, 13, 0, 0, 0, 0, 0, 0))
- # ValueError: year out of range
- #
- # In this case, we fake the date, because we only care about the
- # DST flag.
- tt = (2037,) + tt[1:]
- stamp = time.mktime(tt)
- tt = time.localtime(stamp)
- return tt.tm_isdst > 0
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index 2ed5cee619..f3e1520502 100644
--- a/docs/ref/utils.txt
+++ b/docs/ref/utils.txt
@@ -1121,26 +1121,3 @@ For a complete discussion on the usage of the following see the
Session key under which the active language for the current session is
stored.
-
-``django.utils.tzinfo``
-=======================
-
-.. deprecated:: 1.7
- Use :mod:`~django.utils.timezone` instead.
-
-.. module:: django.utils.tzinfo
- :synopsis: Implementation of ``tzinfo`` classes for use with ``datetime.datetime``.
-
-.. class:: FixedOffset
-
- Fixed offset in minutes east from UTC.
-
- .. deprecated:: 1.7
- Use :func:`~django.utils.timezone.get_fixed_timezone` instead.
-
-.. class:: LocalTimezone
-
- Proxy timezone information from time module.
-
- .. deprecated:: 1.7
- Use :func:`~django.utils.timezone.get_default_timezone` instead.
diff --git a/tests/utils_tests/test_tzinfo.py b/tests/utils_tests/test_tzinfo.py
deleted file mode 100644
index b1a08fb600..0000000000
--- a/tests/utils_tests/test_tzinfo.py
+++ /dev/null
@@ -1,92 +0,0 @@
-import copy
-import datetime
-import os
-import pickle
-import time
-import unittest
-import warnings
-
-from django.test import ignore_warnings
-from django.utils.deprecation import RemovedInDjango19Warning
-
-
-# Swallow the import-time warning to test the deprecated implementation.
-with warnings.catch_warnings():
- warnings.filterwarnings("ignore", category=RemovedInDjango19Warning)
- from django.utils.tzinfo import FixedOffset, LocalTimezone
-
-
-@ignore_warnings(category=RemovedInDjango19Warning)
-class TzinfoTests(unittest.TestCase):
-
- @classmethod
- def setUpClass(cls):
- super(TzinfoTests, cls).setUpClass()
- cls.old_TZ = os.environ.get('TZ')
- os.environ['TZ'] = 'US/Eastern'
-
- try:
- # Check if a timezone has been set
- time.tzset()
- cls.tz_tests = True
- except AttributeError:
- # No timezone available. Don't run the tests that require a TZ
- cls.tz_tests = False
-
- @classmethod
- def tearDownClass(cls):
- if cls.old_TZ is None:
- del os.environ['TZ']
- else:
- os.environ['TZ'] = cls.old_TZ
-
- # Cleanup - force re-evaluation of TZ environment variable.
- if cls.tz_tests:
- time.tzset()
- super(TzinfoTests, cls).tearDownClass()
-
- def test_fixedoffset(self):
- self.assertEqual(repr(FixedOffset(0)), '+0000')
- self.assertEqual(repr(FixedOffset(60)), '+0100')
- self.assertEqual(repr(FixedOffset(-60)), '-0100')
- self.assertEqual(repr(FixedOffset(280)), '+0440')
- self.assertEqual(repr(FixedOffset(-280)), '-0440')
- self.assertEqual(repr(FixedOffset(-78.4)), '-0118')
- self.assertEqual(repr(FixedOffset(78.4)), '+0118')
- self.assertEqual(repr(FixedOffset(-5.5 * 60)), '-0530')
- self.assertEqual(repr(FixedOffset(5.5 * 60)), '+0530')
- self.assertEqual(repr(FixedOffset(-.5 * 60)), '-0030')
- self.assertEqual(repr(FixedOffset(.5 * 60)), '+0030')
-
- def test_16899(self):
- if not self.tz_tests:
- return
- ts = 1289106000
- # Midnight at the end of DST in US/Eastern: 2010-11-07T05:00:00Z
- dt = datetime.datetime.utcfromtimestamp(ts)
- # US/Eastern -- we force its representation to "EST"
- tz = LocalTimezone(dt + datetime.timedelta(days=1))
- self.assertEqual(
- repr(datetime.datetime.fromtimestamp(ts - 3600, tz)),
- 'datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST)')
- self.assertEqual(
- repr(datetime.datetime.fromtimestamp(ts, tz)),
- 'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
- self.assertEqual(
- repr(datetime.datetime.fromtimestamp(ts + 3600, tz)),
- 'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
-
- def test_copy(self):
- now = datetime.datetime.now()
- self.assertIsInstance(copy.copy(FixedOffset(90)), FixedOffset)
- self.assertIsInstance(copy.copy(LocalTimezone(now)), LocalTimezone)
-
- def test_deepcopy(self):
- now = datetime.datetime.now()
- self.assertIsInstance(copy.deepcopy(FixedOffset(90)), FixedOffset)
- self.assertIsInstance(copy.deepcopy(LocalTimezone(now)), LocalTimezone)
-
- def test_pickling_unpickling(self):
- now = datetime.datetime.now()
- self.assertIsInstance(pickle.loads(pickle.dumps(FixedOffset(90))), FixedOffset)
- self.assertIsInstance(pickle.loads(pickle.dumps(LocalTimezone(now))), LocalTimezone)