mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #28926 -- Fixed loss of precision of big DurationField values on SQLite and MySQL.
This commit is contained in:
parent
46d1af2e82
commit
ae6fa914aa
7 changed files with 47 additions and 7 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue