mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #28926 -- Fixed loss of precision of big DurationField values on SQLite and MySQL.
This commit is contained in:
committed by
Tim Graham
parent
46d1af2e82
commit
ae6fa914aa
@@ -1250,6 +1250,16 @@ class FTimeDeltaTests(TestCase):
|
||||
]
|
||||
self.assertEqual(over_estimate, ['e4'])
|
||||
|
||||
@skipUnlessDBFeature('supports_temporal_subtraction')
|
||||
def test_datetime_subtraction_microseconds(self):
|
||||
delta = datetime.timedelta(microseconds=8999999999999999)
|
||||
Experiment.objects.update(end=F('start') + delta)
|
||||
qs = Experiment.objects.annotate(
|
||||
delta=ExpressionWrapper(F('end') - F('start'), output_field=models.DurationField())
|
||||
)
|
||||
for e in qs:
|
||||
self.assertEqual(e.delta, delta)
|
||||
|
||||
def test_duration_with_datetime(self):
|
||||
# Exclude e1 which has very high precision so we can test this on all
|
||||
# backends regardless of whether or not it supports
|
||||
@@ -1259,6 +1269,15 @@ class FTimeDeltaTests(TestCase):
|
||||
).order_by('name')
|
||||
self.assertQuerysetEqual(over_estimate, ['e3', 'e4', 'e5'], lambda e: e.name)
|
||||
|
||||
def test_duration_with_datetime_microseconds(self):
|
||||
delta = datetime.timedelta(microseconds=8999999999999999)
|
||||
qs = Experiment.objects.annotate(dt=ExpressionWrapper(
|
||||
F('start') + delta,
|
||||
output_field=models.DateTimeField(),
|
||||
))
|
||||
for e in qs:
|
||||
self.assertEqual(e.dt, e.start + delta)
|
||||
|
||||
def test_date_minus_duration(self):
|
||||
more_than_4_days = Experiment.objects.filter(
|
||||
assigned__lt=F('completed') - Value(datetime.timedelta(days=4), output_field=models.DurationField())
|
||||
|
||||
Reference in New Issue
Block a user