mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Refs #31640 -- Made Extract raise ValueError when using tzinfo with Date/TimeField.
This commit is contained in:
committed by
Mariusz Felisiak
parent
b26ec77deb
commit
a0571c1003
@@ -1111,6 +1111,18 @@ class DateFunctionWithTimeZoneTests(DateFunctionTests):
|
||||
self.assertEqual(model.day_melb, 16)
|
||||
self.assertEqual(model.day_utc, 15)
|
||||
|
||||
def test_extract_invalid_field_with_timezone(self):
|
||||
melb = pytz.timezone('Australia/Melbourne')
|
||||
msg = 'tzinfo can only be used with DateTimeField.'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
DTModel.objects.annotate(
|
||||
day_melb=Extract('start_date', 'day', tzinfo=melb),
|
||||
).get()
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
DTModel.objects.annotate(
|
||||
hour_melb=Extract('start_time', 'hour', tzinfo=melb),
|
||||
).get()
|
||||
|
||||
def test_trunc_timezone_applied_before_truncation(self):
|
||||
start_datetime = datetime(2016, 1, 1, 1, 30, 50, 321)
|
||||
end_datetime = datetime(2016, 6, 15, 14, 10, 50, 123)
|
||||
|
||||
Reference in New Issue
Block a user