Commit ff2aa401 authored by Josh Smeaton's avatar Josh Smeaton Committed by Tim Graham
Browse files

Fixed #24486 -- Fixed error with datetime and DurationField arithmetic

parent 81c2d9f6
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -398,6 +398,7 @@ class DurationExpression(Expression):
                output = side.output_field
            except FieldError:
                pass
            else:
                if output.get_internal_type() == 'DurationField':
                    sql, params = compiler.compile(side)
                    return connection.ops.format_for_duration_arithmetic(sql), params
+11 −2
Original line number Diff line number Diff line
@@ -617,8 +617,8 @@ class ExpressionOperatorTests(TestCase):
class FTimeDeltaTests(TestCase):

    def setUp(self):
        sday = datetime.date(2010, 6, 25)
        stime = datetime.datetime(2010, 6, 25, 12, 15, 30, 747000)
        self.sday = sday = datetime.date(2010, 6, 25)
        self.stime = stime = datetime.datetime(2010, 6, 25, 12, 15, 30, 747000)
        midnight = datetime.time(0)

        delta0 = datetime.timedelta(0)
@@ -821,6 +821,15 @@ class FTimeDeltaTests(TestCase):
            Experiment.objects.filter(estimated_time__lt=F('end') - F('start'))]
        self.assertEqual(over_estimate, ['e4'])

    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
        # microsecond_precision.
        over_estimate = Experiment.objects.exclude(name='e1').filter(
            completed__gt=self.stime + F('estimated_time'),
        ).order_by('name')
        self.assertQuerysetEqual(over_estimate, ['e3', 'e4'], lambda e: e.name)


class ValueTests(TestCase):
    def test_update_TimeField_using_Value(self):