Skip to content

Commit ccc6f2c

Browse files
committed
Fix bug in date calculations when editing task times without sufficient data
1 parent deb0597 commit ccc6f2c

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/ifcopenshell-python/ifcopenshell/api/sequence/edit_task_time.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def execute(self):
4040
del self.settings["attributes"]["ScheduleFinish"]
4141

4242
duration_type = self.settings["attributes"].get("DurationType", self.settings["task_time"].DurationType)
43-
if "ScheduleFinish" in self.settings["attributes"]:
43+
if self.settings["attributes"].get("ScheduleFinish", None):
4444
self.settings["attributes"]["ScheduleFinish"] = ifcopenshell.util.sequence.get_soonest_working_day(
4545
self.settings["attributes"]["ScheduleFinish"], duration_type, self.calendar
4646
)
47-
if "ScheduleStart" in self.settings["attributes"]:
47+
if self.settings["attributes"].get("ScheduleStart", None):
4848
self.settings["attributes"]["ScheduleStart"] = ifcopenshell.util.sequence.get_soonest_working_day(
4949
self.settings["attributes"]["ScheduleStart"], duration_type, self.calendar
5050
)
@@ -63,7 +63,7 @@ def execute(self):
6363
and self.settings["task_time"].ScheduleStart
6464
):
6565
self.calculate_finish()
66-
elif "ScheduleStart" in self.settings["attributes"].keys() and self.settings["task_time"].ScheduleDuration:
66+
elif self.settings["attributes"].get("ScheduleStart", None) and self.settings["task_time"].ScheduleDuration:
6767
self.calculate_finish()
6868
elif self.settings["attributes"].get("ScheduleFinish", None) and self.settings["task_time"].ScheduleStart:
6969
self.calculate_duration()

src/ifcopenshell-python/test/api/sequence/test_edit_task_time.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ def test_editing_just_a_start_date_with_no_duration_or_finish(self):
8888
assert task_time.ScheduleFinish is None
8989
assert task_time.ScheduleDuration is None
9090

91+
def test_editing_just_a_start_date_with_no_duration_or_finish_but_with_a_calendar(self):
92+
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
93+
calendar = ifcopenshell.api.run("sequence.add_work_calendar", self.file)
94+
task = self.file.createIfcTask()
95+
ifcopenshell.api.run("control.assign_control", self.file, relating_control=calendar, related_object=task)
96+
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=task)
97+
ifcopenshell.api.run(
98+
"sequence.edit_task_time",
99+
self.file,
100+
task_time=task_time,
101+
attributes={
102+
"ScheduleDuration": None,
103+
"ScheduleStart": datetime.datetime(2000, 1, 1),
104+
"ScheduleFinish": None,
105+
},
106+
)
107+
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
108+
assert task_time.ScheduleFinish is None
109+
assert task_time.ScheduleDuration is None
110+
91111
def test_schedule_finish_dates_are_auto_calculated_if_possible(self):
92112
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
93113
ifcopenshell.api.run(

0 commit comments

Comments
 (0)