mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Refs #36005 -- Used datetime.UTC alias instead of datetime.timezone.utc.
datetime.UTC was added in Python 3.11.
This commit is contained in:
@@ -355,7 +355,7 @@ that deal with date-parts can be used with ``DateField``:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from datetime import datetime, timezone
|
||||
>>> from datetime import UTC, datetime
|
||||
>>> from django.db.models.functions import (
|
||||
... ExtractDay,
|
||||
... ExtractMonth,
|
||||
@@ -366,8 +366,8 @@ that deal with date-parts can be used with ``DateField``:
|
||||
... ExtractIsoYear,
|
||||
... ExtractYear,
|
||||
... )
|
||||
>>> start_2015 = datetime(2015, 6, 15, 23, 30, 1, tzinfo=timezone.utc)
|
||||
>>> end_2015 = datetime(2015, 6, 16, 13, 11, 27, tzinfo=timezone.utc)
|
||||
>>> start_2015 = datetime(2015, 6, 15, 23, 30, 1, tzinfo=UTC)
|
||||
>>> end_2015 = datetime(2015, 6, 16, 13, 11, 27, tzinfo=UTC)
|
||||
>>> Experiment.objects.create(
|
||||
... start_datetime=start_2015,
|
||||
... start_date=start_2015.date(),
|
||||
@@ -424,7 +424,7 @@ Each class is also a ``Transform`` registered on ``DateTimeField`` as
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from datetime import datetime, timezone
|
||||
>>> from datetime import UTC, datetime
|
||||
>>> from django.db.models.functions import (
|
||||
... ExtractDay,
|
||||
... ExtractHour,
|
||||
@@ -438,8 +438,8 @@ Each class is also a ``Transform`` registered on ``DateTimeField`` as
|
||||
... ExtractIsoYear,
|
||||
... ExtractYear,
|
||||
... )
|
||||
>>> start_2015 = datetime(2015, 6, 15, 23, 30, 1, tzinfo=timezone.utc)
|
||||
>>> end_2015 = datetime(2015, 6, 16, 13, 11, 27, tzinfo=timezone.utc)
|
||||
>>> start_2015 = datetime(2015, 6, 15, 23, 30, 1, tzinfo=UTC)
|
||||
>>> end_2015 = datetime(2015, 6, 16, 13, 11, 27, tzinfo=UTC)
|
||||
>>> Experiment.objects.create(
|
||||
... start_datetime=start_2015,
|
||||
... start_date=start_2015.date(),
|
||||
@@ -664,12 +664,12 @@ that deal with date-parts can be used with ``DateField``:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from datetime import datetime, timezone
|
||||
>>> from datetime import UTC, datetime
|
||||
>>> from django.db.models import Count
|
||||
>>> from django.db.models.functions import TruncMonth, TruncYear
|
||||
>>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=timezone.utc)
|
||||
>>> start2 = datetime(2015, 6, 15, 14, 40, 2, 123, tzinfo=timezone.utc)
|
||||
>>> start3 = datetime(2015, 12, 31, 17, 5, 27, 999, tzinfo=timezone.utc)
|
||||
>>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=UTC)
|
||||
>>> start2 = datetime(2015, 6, 15, 14, 40, 2, 123, tzinfo=UTC)
|
||||
>>> start3 = datetime(2015, 12, 31, 17, 5, 27, 999, tzinfo=UTC)
|
||||
>>> Experiment.objects.create(start_datetime=start1, start_date=start1.date())
|
||||
>>> Experiment.objects.create(start_datetime=start2, start_date=start2.date())
|
||||
>>> Experiment.objects.create(start_datetime=start3, start_date=start3.date())
|
||||
@@ -744,7 +744,7 @@ Usage example:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from datetime import date, datetime, timezone
|
||||
>>> from datetime import UTC, date, datetime
|
||||
>>> from django.db.models import Count
|
||||
>>> from django.db.models.functions import (
|
||||
... TruncDate,
|
||||
@@ -754,7 +754,7 @@ Usage example:
|
||||
... TruncSecond,
|
||||
... )
|
||||
>>> import zoneinfo
|
||||
>>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=timezone.utc)
|
||||
>>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=UTC)
|
||||
>>> Experiment.objects.create(start_datetime=start1, start_date=start1.date())
|
||||
>>> melb = zoneinfo.ZoneInfo("Australia/Melbourne")
|
||||
>>> Experiment.objects.annotate(
|
||||
@@ -767,8 +767,8 @@ Usage example:
|
||||
{'date': datetime.date(2014, 6, 15),
|
||||
'day': datetime.datetime(2014, 6, 16, 0, 0, tzinfo=zoneinfo.ZoneInfo('Australia/Melbourne')),
|
||||
'hour': datetime.datetime(2014, 6, 16, 0, 0, tzinfo=zoneinfo.ZoneInfo('Australia/Melbourne')),
|
||||
'minute': 'minute': datetime.datetime(2014, 6, 15, 14, 30, tzinfo=timezone.utc),
|
||||
'second': datetime.datetime(2014, 6, 15, 14, 30, 50, tzinfo=timezone.utc)
|
||||
'minute': 'minute': datetime.datetime(2014, 6, 15, 14, 30, tzinfo=UTC),
|
||||
'second': datetime.datetime(2014, 6, 15, 14, 30, 50, tzinfo=UTC)
|
||||
}
|
||||
|
||||
``TimeField`` truncation
|
||||
@@ -799,12 +799,12 @@ that deal with time-parts can be used with ``TimeField``:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from datetime import datetime, timezone
|
||||
>>> from datetime import UTC, datetime
|
||||
>>> from django.db.models import Count, TimeField
|
||||
>>> from django.db.models.functions import TruncHour
|
||||
>>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=timezone.utc)
|
||||
>>> start2 = datetime(2014, 6, 15, 14, 40, 2, 123, tzinfo=timezone.utc)
|
||||
>>> start3 = datetime(2015, 12, 31, 17, 5, 27, 999, tzinfo=timezone.utc)
|
||||
>>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=UTC)
|
||||
>>> start2 = datetime(2014, 6, 15, 14, 40, 2, 123, tzinfo=UTC)
|
||||
>>> start3 = datetime(2015, 12, 31, 17, 5, 27, 999, tzinfo=UTC)
|
||||
>>> Experiment.objects.create(start_datetime=start1, start_time=start1.time())
|
||||
>>> Experiment.objects.create(start_datetime=start2, start_time=start2.time())
|
||||
>>> Experiment.objects.create(start_datetime=start3, start_time=start3.time())
|
||||
|
||||
Reference in New Issue
Block a user