From c4ee3b208a2c95a5102b5e4fa789b10f8ee29b84 Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Fri, 30 Apr 2021 22:38:42 +0800 Subject: Fixed #32699 -- Fixed comparing to TruncTime() with 0 microseconds on MySQL. --- tests/db_functions/datetime/test_extract_trunc.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/db_functions/datetime/test_extract_trunc.py b/tests/db_functions/datetime/test_extract_trunc.py index 63040f5198..75b8a4f0f9 100644 --- a/tests/db_functions/datetime/test_extract_trunc.py +++ b/tests/db_functions/datetime/test_extract_trunc.py @@ -923,6 +923,22 @@ class DateFunctionTests(TestCase): self.create_model(None, None) self.assertIsNone(DTModel.objects.annotate(truncated=TruncTime('start_datetime')).first().truncated) + def test_trunc_time_no_microseconds(self): + start_datetime = datetime(2015, 6, 15, 14, 30, 26) + if settings.USE_TZ: + start_datetime = timezone.make_aware(start_datetime, is_dst=False) + self.create_model(start_datetime, None) + self.assertIs( + DTModel.objects.filter(start_datetime__time=start_datetime.time()).exists(), + True, + ) + self.assertIs( + DTModel.objects.annotate( + extracted=TruncTime('start_datetime'), + ).filter(extracted=start_datetime.time()).exists(), + True, + ) + def test_trunc_day_func(self): start_datetime = datetime(2015, 6, 15, 14, 30, 50, 321) end_datetime = truncate_to(datetime(2016, 6, 15, 14, 10, 50, 123), 'day') -- cgit v1.3