summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2016-11-23 15:10:47 +0100
committerTim Graham <timograham@gmail.com>2016-11-23 09:10:47 -0500
commitb63d0c54b05ede2589e2b720eb0c102c02891962 (patch)
tree16244b5a9d249a21b2af80234ea39d5090c56289 /tests
parent2742901ac210361bc2c4b662870d35a1be5a142c (diff)
Fixed #24959 -- Fixed queries using negative timedeltas on MySQL and Oracle.
Diffstat (limited to 'tests')
-rw-r--r--tests/expressions/tests.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index f8301b7161..c6daa504b1 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -1043,6 +1043,26 @@ class FTimeDeltaTests(TestCase):
).order_by('name')
self.assertQuerysetEqual(over_estimate, ['e3', 'e4'], lambda e: e.name)
+ def test_negative_timedelta_update(self):
+ # subtract 30 seconds, 30 minutes, 2 hours and 2 days
+ experiments = Experiment.objects.filter(name='e0').annotate(
+ start_sub_seconds=F('start') + datetime.timedelta(seconds=-30),
+ ).annotate(
+ start_sub_minutes=F('start_sub_seconds') + datetime.timedelta(minutes=-30),
+ ).annotate(
+ start_sub_hours=F('start_sub_minutes') + datetime.timedelta(hours=-2),
+ ).annotate(
+ new_start=F('start_sub_hours') + datetime.timedelta(days=-2),
+ )
+ expected_start = datetime.datetime(2010, 6, 23, 9, 45, 0)
+ if connection.features.supports_microsecond_precision:
+ # subtract 30 microseconds
+ experiments = experiments.annotate(new_start=F('new_start') + datetime.timedelta(microseconds=-30))
+ expected_start += datetime.timedelta(microseconds=+746970)
+ experiments.update(start=F('new_start'))
+ e0 = Experiment.objects.get(name='e0')
+ self.assertEqual(e0.start, expected_start)
+
class ValueTests(TestCase):
def test_update_TimeField_using_Value(self):