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:
Dion Moult
2024-03-31 22:11:06 +11:00
parent f7c03db752
commit 0bc83fedae
4 changed files with 13 additions and 51 deletions
@@ -17,7 +17,6 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.util.date
from ifcopenshell.util.data import WorkTimeDatesInterface
class Usecase:
@@ -55,10 +54,12 @@ class Usecase:
self.settings = {"work_time": work_time, "attributes": attributes or {}}
def execute(self):
work_time_dates = WorkTimeDatesInterface(self.settings["work_time"])
for name, value in self.settings["attributes"].items():
if name in ("Start", "Finish", "StartDate", "FinishDate"):
if name in ("Start", "StartDate"):
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDate")
setattr(work_time_dates, name, value)
self.settings["work_time"][4] = value
elif name in ("Finish", "FinishDate"):
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDate")
self.settings["work_time"][5] = value
else:
setattr(self.settings["work_time"], name, value)