#167 Allow intervals to be shortened to zero width

Closes #167
This commit is contained in:
Thomas Lauf 2018-08-10 18:02:41 +02:00
parent ca7676320c
commit 961d0212ba
2 changed files with 16 additions and 15 deletions

View file

@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2015 - 2018, Paul Beckingham, Federico Hernandez. // Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -92,7 +92,7 @@ int CmdShorten (
throw format ("Cannot shorten open interval @{1}", id); throw format ("Cannot shorten open interval @{1}", id);
Duration dur (delta); Duration dur (delta);
if (dur >= (i.range.end - i.range.start)) if (dur > (i.range.end - i.range.start))
throw format ("Cannot shorten interval @{1} by {2} because it is only {3} in length.", id, dur.formatHours (), Duration (i.range.end - i.range.start).formatHours ()); throw format ("Cannot shorten interval @{1} by {2} because it is only {3} in length.", id, dur.formatHours (), Duration (i.range.end - i.range.start).formatHours ());
database.deleteInterval (tracked[tracked.size () - id]); database.deleteInterval (tracked[tracked.size () - id]);

View file

@ -97,26 +97,27 @@ class TestShorten(TestCase):
expectedStart="{:%Y%m%dT%H%M%S}Z".format(three_hours_before_utc), expectedStart="{:%Y%m%dT%H%M%S}Z".format(three_hours_before_utc),
expectedTags=[]) expectedTags=[])
# TODO Add :adjust tests.
class TestBug6(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Timew()
def test_over_shorten_closed_interval(self): def test_over_shorten_closed_interval(self):
"""TI-6: Exception after shortening task. """Over-shorten interval is an error"""
When an interval is shortened by an amount that exceeds it's length,
an assert is triggered, and should be an error instead.
"""
self.t("track 2016-06-08T07:30:00 - 2016-06-08T07:35:00 foo") self.t("track 2016-06-08T07:30:00 - 2016-06-08T07:35:00 foo")
code, out, err = self.t.runError("shorten @1 10mins") code, out, err = self.t.runError("shorten @1 10mins")
self.assertIn('Cannot shorten interval @1 by 0:10:00 because it is only 0:05:00 in length.', err) self.assertIn('Cannot shorten interval @1 by 0:10:00 because it is only 0:05:00 in length.', err)
def test_shorten_closed_interval_to_zero(self):
"""Shorten interval to zero"""
self.t("track 2016-06-08T07:30:00Z - 2016-06-08T07:35:00Z foo")
self.t("shorten @1 5mins")
j = self.t.export()
self.assertEqual(len(j), 1)
self.assertClosedInterval(j[0],
expectedStart="20160608T073000Z",
expectedEnd="20160608T073000Z")
if __name__ == "__main__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner