1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

[3.2.x] Refs #32365 -- Allowed use of non-pytz timezone implementations.

Backport of 10d1261984 from master
This commit is contained in:
Paul Ganssle
2021-01-19 11:16:01 +01:00
committed by Carlton Gibson
parent de4e854f07
commit a5d70cca12
11 changed files with 477 additions and 306 deletions

View File

@@ -987,21 +987,24 @@ appropriate entities.
:class:`~datetime.datetime`. If ``timezone`` is set to ``None``, it
defaults to the :ref:`current time zone <default-current-time-zone>`.
The ``pytz.AmbiguousTimeError`` exception is raised if you try to make
``value`` aware during a DST transition where the same time occurs twice
(when reverting from DST). Setting ``is_dst`` to ``True`` or ``False`` will
avoid the exception by choosing if the time is pre-transition or
post-transition respectively.
When using ``pytz``, the ``pytz.AmbiguousTimeError`` exception is raised if
you try to make ``value`` aware during a DST transition where the same time
occurs twice (when reverting from DST). Setting ``is_dst`` to ``True`` or
``False`` will avoid the exception by choosing if the time is
pre-transition or post-transition respectively.
The ``pytz.NonExistentTimeError`` exception is raised if you try to make
``value`` aware during a DST transition such that the time never occurred.
For example, if the 2:00 hour is skipped during a DST transition, trying to
make 2:30 aware in that time zone will raise an exception. To avoid that
you can use ``is_dst`` to specify how ``make_aware()`` should interpret
such a nonexistent time. If ``is_dst=True`` then the above time would be
interpreted as 2:30 DST time (equivalent to 1:30 local time). Conversely,
if ``is_dst=False`` the time would be interpreted as 2:30 standard time
(equivalent to 3:30 local time).
When using ``pytz``, the ``pytz.NonExistentTimeError`` exception is raised
if you try to make ``value`` aware during a DST transition such that the
time never occurred. For example, if the 2:00 hour is skipped during a DST
transition, trying to make 2:30 aware in that time zone will raise an
exception. To avoid that you can use ``is_dst`` to specify how
``make_aware()`` should interpret such a nonexistent time. If
``is_dst=True`` then the above time would be interpreted as 2:30 DST time
(equivalent to 1:30 local time). Conversely, if ``is_dst=False`` the time
would be interpreted as 2:30 standard time (equivalent to 3:30 local time).
The ``is_dst`` parameter has no effect when using non-``pytz`` timezone
implementations.
.. function:: make_naive(value, timezone=None)

View File

@@ -657,6 +657,9 @@ MySQL 5.7 and higher.
Miscellaneous
-------------
* Django now supports non-``pytz`` time zones, such as Python 3.9+'s
:mod:`zoneinfo` module and its backport.
* The undocumented ``SpatiaLiteOperations.proj4_version()`` method is renamed
to ``proj_version()``.

View File

@@ -26,8 +26,15 @@ to this problem is to use UTC in the code and use local time only when
interacting with end users.
Time zone support is disabled by default. To enable it, set :setting:`USE_TZ =
True <USE_TZ>` in your settings file. Time zone support uses pytz_, which is
installed when you install Django.
True <USE_TZ>` in your settings file. By default, time zone support uses pytz_,
which is installed when you install Django; Django also supports the use of
other time zone implementations like :mod:`zoneinfo` by passing
:class:`~datetime.tzinfo` objects directly to functions in
:mod:`django.utils.timezone`.
.. versionchanged:: 3.2
Support for non-``pytz`` timezone implementations was added.
.. note::
@@ -680,7 +687,8 @@ Usage
pytz_ provides helpers_, including a list of current time zones and a list
of all available time zones -- some of which are only of historical
interest.
interest. :mod:`zoneinfo` also provides similar functionality via
:func:`zoneinfo.available_timezones`.
.. _pytz: http://pytz.sourceforge.net/
.. _more examples: http://pytz.sourceforge.net/#example-usage