diff options
author | Lily Foote <code@lilyf.org> | 2022-09-25 13:32:05 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-10-03 12:13:27 +0200 |
commit | 649b28eab6765cd6b2b40c779a18ecafc99b43d7 (patch) | |
tree | 64bd716f73eb776573bc6c14000fe6b31b6b70a1 /tests/db_functions | |
parent | f71b0cf769d9ac582ee3d1a8c33d73dad3a770da (diff) | |
download | django-649b28eab6765cd6b2b40c779a18ecafc99b43d7.tar.gz |
Fixed #34070 -- Added subsecond support to Now() on SQLite and MySQL.
Diffstat (limited to 'tests/db_functions')
-rw-r--r-- | tests/db_functions/datetime/test_now.py | 18 |
1 files changed, 17 insertions, 1 deletions
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}}}") |