From 817fdead9b18752a4ee1e1458c63b901a878f6a8 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 21 Jan 2022 18:52:40 +1100 Subject: [PATCH] Fix bug where zero durations were not allowed in task times. --- .../api/sequence/edit_task_time.py | 2 +- .../test/api/sequence/test_edit_task_time.py | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_task_time.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_task_time.py index f9f0dd4d5f..722ea46f45 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_task_time.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_task_time.py @@ -50,7 +50,7 @@ class Usecase: ) for name, value in self.settings["attributes"].items(): - if value: + if value is not None: if "Start" in name or "Finish" in name or name == "StatusTime": value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime") elif name == "ScheduleDuration" or name == "ActualDuration" or name == "RemainingTime": diff --git a/src/ifcopenshell-python/test/api/sequence/test_edit_task_time.py b/src/ifcopenshell-python/test/api/sequence/test_edit_task_time.py index a1e69295ae..3a42742efb 100644 --- a/src/ifcopenshell-python/test/api/sequence/test_edit_task_time.py +++ b/src/ifcopenshell-python/test/api/sequence/test_edit_task_time.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . +import datetime import test.bootstrap import ifcopenshell.api @@ -66,3 +67,64 @@ class TestEditTaskTime(test.bootstrap.IFC4): assert task_time.ActualFinish == "2000-01-02T00:00:00" assert task_time.RemainingTime == "P1D" assert task_time.Completion == 0.5 + + def test_schedule_finish_dates_are_auto_calculated_if_possible(self): + task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask()) + ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={ + "DurationType": "ELAPSEDTIME", + "ScheduleDuration": "P1D", + "ScheduleStart": "2000-01-01T00:00:00", + }) + assert task_time.DurationType == "ELAPSEDTIME" + assert task_time.ScheduleDuration == "P1D" + assert task_time.ScheduleStart == "2000-01-01T00:00:00" + assert task_time.ScheduleFinish == "2000-01-02T00:00:00" + + def test_schedule_durations_are_auto_calculated_if_possible(self): + task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask()) + ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={ + "DurationType": "ELAPSEDTIME", + "ScheduleStart": "2000-01-01T00:00:00", + "ScheduleFinish": "2000-01-02T00:00:00", + }) + assert task_time.DurationType == "ELAPSEDTIME" + assert task_time.ScheduleDuration == "P1D" + assert task_time.ScheduleStart == "2000-01-01T00:00:00" + assert task_time.ScheduleFinish == "2000-01-02T00:00:00" + + def test_a_duration_takes_priority_over_start_and_finish_dates(self): + task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask()) + ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={ + "DurationType": "ELAPSEDTIME", + "ScheduleDuration": "P1D", + "ScheduleStart": "2000-01-01T00:00:00", + "ScheduleFinish": "2000-01-03T00:00:00", + }) + assert task_time.DurationType == "ELAPSEDTIME" + assert task_time.ScheduleDuration == "P1D" + assert task_time.ScheduleStart == "2000-01-01T00:00:00" + assert task_time.ScheduleFinish == "2000-01-02T00:00:00" + + def test_durations_can_be_specified_in_datetime_objects(self): + task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask()) + ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={ + "DurationType": "ELAPSEDTIME", + "ScheduleDuration": datetime.timedelta(days=1), + "ScheduleStart": "2000-01-01T00:00:00", + }) + assert task_time.DurationType == "ELAPSEDTIME" + assert task_time.ScheduleDuration == "P1D" + assert task_time.ScheduleStart == "2000-01-01T00:00:00" + assert task_time.ScheduleFinish == "2000-01-02T00:00:00" + + def test_zero_durations_are_allowed(self): + task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask()) + ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={ + "DurationType": "ELAPSEDTIME", + "ScheduleDuration": datetime.timedelta(), + "ScheduleStart": "2000-01-01T00:00:00", + }) + assert task_time.DurationType == "ELAPSEDTIME" + assert task_time.ScheduleDuration == "P0D" + assert task_time.ScheduleStart == "2000-01-01T00:00:00" + assert task_time.ScheduleFinish == "2000-01-01T00:00:00"