This commit is contained in:
Andrej730
2024-02-22 16:16:12 +05:00
parent 515830e52d
commit c1cd228911
4 changed files with 55 additions and 29 deletions
@@ -93,3 +93,37 @@ class Clipping:
second_operand = ifc_file.createIfcHalfSpaceSolid(plane, False)
return ifc_file.createIfcBooleanClippingResult("DIFFERENCE", first_operand, second_operand)
class WorkTimeDatesInterface:
def __init__(self, work_time: ifcopenshell.entity_instance):
"""Utility class for IfcWorkTime dates allowing refer
to it's dates as `.Start`/`.Finish` or `.StartDate`/`.FinishDate`
regardless of the schema version
"""
if hasattr(work_time, "StartDate"): # since IFC4X3
self.start_attr, self.finish_attr = "StartDate", "FinishDate"
else:
self.start_attr, self.finish_attr = "Start", "Finish"
self.work_time = work_time
@property
def Start(self):
return getattr(self.work_time, self.start_attr)
@Start.setter
def Start(self, value):
return setattr(self.work_time, self.start_attr, value)
StartDate = Start
@property
def Finish(self):
return getattr(self.work_time, self.finish_attr)
@Finish.setter
def Finish(self, value):
return setattr(self.work_time, self.finish_attr, value)
FinishDate = Finish
@@ -18,8 +18,10 @@
import datetime
import ifcopenshell.util.date
from ifcopenshell.util.data import WorkTimeDatesInterface
from math import floor
from functools import lru_cache
from collections import namedtuple
def derive_date(task, attribute_name, date=None, is_earliest=False, is_latest=False):
@@ -180,14 +182,15 @@ def is_day_in_work_time(day, work_time):
is_day_in_work_time = True
if isinstance(day, datetime.datetime):
day = datetime.date(day.year, day.month, day.day)
if work_time.Start:
start = ifcopenshell.util.date.ifc2datetime(work_time.Start)
work_time_dates = WorkTimeDatesInterface(work_time)
if work_time_dates.Start:
start = ifcopenshell.util.date.ifc2datetime(work_time_dates.Start)
if day > start:
is_day_in_work_time = True
else:
is_day_in_work_time = False
if work_time.Finish:
finish = ifcopenshell.util.date.ifc2datetime(work_time.Finish)
if work_time_dates.Finish:
finish = ifcopenshell.util.date.ifc2datetime(work_time_dates.Finish)
if day < finish:
is_day_in_work_time = True
else:
@@ -204,16 +207,17 @@ def is_work_time_applicable_to_day(work_time, day):
if isinstance(day, datetime.datetime):
day = datetime.date(day.year, day.month, day.day)
recurrence = work_time.RecurrencePattern
work_time_dates = WorkTimeDatesInterface(work_time)
if recurrence.RecurrenceType == "DAILY":
if not recurrence.Interval and not recurrence.Occurrences:
return True
if not work_time.Start:
if not work_time_dates.Start:
return False
return False # TODO
elif recurrence.RecurrenceType == "WEEKLY":
if not recurrence.Interval and not recurrence.Occurrences:
return (day.weekday() + 1) in recurrence.WeekdayComponent
if not work_time.Start:
if not work_time_dates.Start:
return False
return False # TODO
elif recurrence.RecurrenceType == "MONTHLY_BY_DAY_OF_MONTH":