> `USE_TZ`: If this is set to True, Django will use timezone-aware
datetimes internally. Otherwise, Django will use naive datetimes in local
time.
{{{
diff --git a/tests/forms_tests/field_tests/test_datetimefield.py
b/tests/forms_tests/field_tests/test_datetimefield.py
index f0e6ada3c5..ed035497d8 100644
--- a/tests/forms_tests/field_tests/test_datetimefield.py
+++ b/tests/forms_tests/field_tests/test_datetimefield.py
@@ -2,8 +2,8 @@ from datetime import date, datetime
from django.core.exceptions import ValidationError
from django.forms import DateTimeField
-from django.test import SimpleTestCase
-from django.utils.timezone import get_fixed_timezone, utc
+from django.test import SimpleTestCase, override_settings
+from django.utils.timezone import get_fixed_timezone, is_naive, utc
class DateTimeFieldTest(SimpleTestCase):
@@ -65,6 +65,12 @@ class DateTimeFieldTest(SimpleTestCase):
with self.subTest(value=value):
self.assertEqual(f.clean(value), expected_datetime)
+ @override_settings(USE_TZ=False)
+ def test_use_tz_false(self):
+ f = DateTimeField()
+ value = '2014-09-23T22:34Z'
+ self.assertTrue(is_naive(f.clean(value)))
+
def test_datetimefield_clean_invalid(self):
f = DateTimeField()
msg = "'Enter a valid date/time.'"
}}}
Expected behaviour is to return a naive datetime.
--
Ticket URL: <https://code.djangoproject.com/ticket/31608>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Claude Paroz (added)
* stage: Unreviewed => Accepted
Comment:
Regression in 1487f16f2d29c7aeaf48117d02a1d7bbeafa3d94.
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:1>
* owner: nobody => Hasan Ramezani
* status: new => assigned
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/12938 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:2>
Comment (by Claude Paroz):
Repeating what I said on the PR. In my opinion, even if `USE_TZ` is False,
parsing a datetime including timezone information should really keep its
timezone. So I'd rather add an admonition to the docs.
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:3>
Comment (by Carlton Gibson):
So this caused a test failure on Django-Filter.
I've adjusted the test case there to account for the new behaviour.
https://github.com/carltongibson/django-filter/pull/1226
{{{
- @override_settings(USE_TZ=False)
def test_clean(self):
w = RangeWidget()
f = IsoDateTimeRangeField(widget=w)
- self.assertEqual(
- f.clean(['2015-01-01T10:30:01.123000+01:00',
'2015-01-10T08:45:02.345000+01:00']),
- slice(datetime(2015, 1, 1, 9, 30, 1, 123000),
- datetime(2015, 1, 10, 7, 45, 2, 345000)))
+ expected = slice(
+ datetime(2015, 1, 1, 9, 30, 1, 123000, tzinfo=timezone.utc),
+ datetime(2015, 1, 10, 7, 45, 2, 345000, tzinfo=timezone.utc)
+ )
+ actual = f.clean(['2015-01-01T10:30:01.123000+01:00',
'2015-01-10T08:45:02.345000+01:00'])
+ self.assertEqual(expected, actual)
}}}
Let's assume we'll go with the docs change.
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:4>
Comment (by Hasan Ramezani):
Ok, I will create a PR for doc change.
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:5>
Comment (by Hasan Ramezani):
I created a new [https://github.com/django/django/pull/12947 PR] to change
the release note and mention the behavior of forms.DateTimeField per
[https://github.com/django/django/pull/12938#issuecomment-631386529
Carlton comment].
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"643207efaebbff4e7c3ebcbf9ca49fb6197137e1" 643207ef]:
{{{
#!CommitTicketReference repository=""
revision="643207efaebbff4e7c3ebcbf9ca49fb6197137e1"
Fixed #31608 -- Doc'd that form ISO 8601 datetime parsing always retains
tzinfo.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:8>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"a6c773aa869655e9dbb86ce9b500ddf1159c71b0" a6c773a]:
{{{
#!CommitTicketReference repository=""
revision="a6c773aa869655e9dbb86ce9b500ddf1159c71b0"
[3.1.x] Fixed #31608 -- Doc'd that form ISO 8601 datetime parsing always
retains tzinfo.
Backport of 643207efaebbff4e7c3ebcbf9ca49fb6197137e1 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31608#comment:9>