From 649b28eab6765cd6b2b40c779a18ecafc99b43d7 Mon Sep 17 00:00:00 2001 From: Lily Foote Date: Sun, 25 Sep 2022 13:32:05 +0100 Subject: Fixed #34070 -- Added subsecond support to Now() on SQLite and MySQL. --- tests/db_functions/datetime/test_now.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/db_functions/datetime/test_now.py b/tests/db_functions/datetime/test_now.py index 669a973be0..716c5744e9 100644 --- a/tests/db_functions/datetime/test_now.py +++ b/tests/db_functions/datetime/test_now.py @@ -1,6 +1,8 @@ from datetime import datetime, timedelta -from django.db.models.functions import Now +from django.db import connection +from django.db.models import TextField +from django.db.models.functions import Cast, Now from django.test import TestCase from django.utils import timezone @@ -47,3 +49,17 @@ class NowTests(TestCase): ["How to Time Travel"], lambda a: a.title, ) + + def test_microseconds(self): + Article.objects.create( + title="How to Django", + text=lorem_ipsum, + written=timezone.now(), + ) + now_string = ( + Article.objects.annotate(now_string=Cast(Now(), TextField())) + .get() + .now_string + ) + precision = connection.features.time_cast_precision + self.assertRegex(now_string, rf"^.*\.\d{{1,{precision}}}") -- cgit v1.3