mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Improved date calculations during import and editing ensure that start / finish dates are always on working days.
This commit is contained in:
@@ -12,11 +12,27 @@ class Usecase:
|
||||
|
||||
def execute(self):
|
||||
# If the user specifies both an end date and a duration, the duration takes priority
|
||||
if "ScheduleDuration" in self.settings["attributes"].keys() and "ScheduleFinish" in self.settings["attributes"].keys():
|
||||
if (
|
||||
"ScheduleDuration" in self.settings["attributes"].keys()
|
||||
and "ScheduleFinish" in self.settings["attributes"].keys()
|
||||
):
|
||||
del self.settings["attributes"]["ScheduleFinish"]
|
||||
if "ActualDuration" in self.settings["attributes"].keys() and "ActualFinish" in self.settings["attributes"].keys():
|
||||
if (
|
||||
"ActualDuration" in self.settings["attributes"].keys()
|
||||
and "ActualFinish" in self.settings["attributes"].keys()
|
||||
):
|
||||
del self.settings["attributes"]["ActualFinish"]
|
||||
|
||||
duration_type = self.settings["attributes"].get("DurationType", self.settings["task_time"].DurationType)
|
||||
if "ScheduleFinish" in self.settings["attributes"]:
|
||||
self.settings["attributes"]["ScheduleFinish"] = ifcopenshell.util.sequence.get_soonest_working_day(
|
||||
self.settings["attributes"]["ScheduleFinish"], duration_type, self.get_calendar()
|
||||
)
|
||||
if "ScheduleStart" in self.settings["attributes"]:
|
||||
self.settings["attributes"]["ScheduleStart"] = ifcopenshell.util.sequence.get_soonest_working_day(
|
||||
self.settings["attributes"]["ScheduleStart"], duration_type, self.get_calendar()
|
||||
)
|
||||
|
||||
for name, value in self.settings["attributes"].items():
|
||||
if value:
|
||||
if "Start" in name or "Finish" in name or name == "StatusTime":
|
||||
@@ -37,21 +53,13 @@ class Usecase:
|
||||
self.calculate_duration()
|
||||
|
||||
def calculate_finish(self):
|
||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
||||
current_date = datetime.date(start.year, start.month, start.day)
|
||||
duration = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration).days
|
||||
|
||||
calendar = self.get_calendar()
|
||||
|
||||
while duration >= 0:
|
||||
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
|
||||
duration -= 1
|
||||
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
|
||||
duration -= 1
|
||||
current_date += datetime.timedelta(days=1)
|
||||
|
||||
current_date -= datetime.timedelta(days=1)
|
||||
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(current_date, "IfcDateTime")
|
||||
finish_date = ifcopenshell.util.sequence.get_finish_date(
|
||||
ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart),
|
||||
ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration),
|
||||
self.settings["task_time"].DurationType,
|
||||
self.get_calendar(),
|
||||
)
|
||||
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(finish_date, "IfcDateTime")
|
||||
|
||||
def calculate_duration(self):
|
||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
||||
|
||||
Reference in New Issue
Block a user