mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Use indices instead of WorkTimeDatesInterface
Checking start/end dates are done very, very often in date calculations (often looping through every day in a date range). So I'd prefer more opaque code but less overhead.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
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
|
||||
@@ -182,15 +181,14 @@ 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)
|
||||
work_time_dates = WorkTimeDatesInterface(work_time)
|
||||
if work_time_dates.Start:
|
||||
start = ifcopenshell.util.date.ifc2datetime(work_time_dates.Start)
|
||||
if work_time[4]:
|
||||
start = ifcopenshell.util.date.ifc2datetime(work_time[4])
|
||||
if day > start:
|
||||
is_day_in_work_time = True
|
||||
else:
|
||||
is_day_in_work_time = False
|
||||
if work_time_dates.Finish:
|
||||
finish = ifcopenshell.util.date.ifc2datetime(work_time_dates.Finish)
|
||||
if work_time[5]:
|
||||
finish = ifcopenshell.util.date.ifc2datetime(work_time[5])
|
||||
if day < finish:
|
||||
is_day_in_work_time = True
|
||||
else:
|
||||
@@ -207,17 +205,16 @@ 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_dates.Start:
|
||||
if not work_time[4]:
|
||||
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_dates.Start:
|
||||
if not work_time[4]:
|
||||
return False
|
||||
return False # TODO
|
||||
elif recurrence.RecurrenceType == "MONTHLY_BY_DAY_OF_MONTH":
|
||||
|
||||
Reference in New Issue
Block a user