Code review and use isodate library to handle durations for robustly

This commit is contained in:
Dion Moult
2021-05-04 12:52:14 +10:00
parent 8a8bdeeaa3
commit f63479c823
3 changed files with 35 additions and 46 deletions
+7
View File
@@ -184,6 +184,13 @@ endif
cp -r dist/working/python-dateutil-2.8.1/dateutil dist/blenderbim/libs/site/packages/
rm -rf dist/working
# Provides duration parsing for construction sequencing
mkdir dist/working
cd dist/working && wget https://files.pythonhosted.org/packages/b1/80/fb8c13a4cd38eb5021dc3741a9e588e4d1de88d895c1910c6fc8a08b7a70/isodate-0.6.0.tar.gz
cd dist/working && tar -xzvf isodate*
cp -r dist/working/isodate-0.6.0/src/isodate dist/blenderbim/libs/site/packages/
rm -rf dist/working
# Provides jsgantt-improved supports for web-based construction sequencing gantt charts
mkdir dist/working
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.js
@@ -2,6 +2,7 @@ import os
import bpy
import json
import time
import isodate
import pystache
import webbrowser
import ifcopenshell.api
@@ -302,7 +303,7 @@ class LoadTaskProperties(bpy.types.Operator):
task_time = Data.task_times[task["TaskTime"]]
item.start = self.canonicalise_time(task_time["ScheduleStart"])
item.finish = self.canonicalise_time(task_time["ScheduleFinish"])
item.duration = str(task_time["ScheduleDuration"].days) if task_time["ScheduleDuration"] else "-"
item.duration = isodate.duration_isoformat(task_time["ScheduleDuration"]) if task_time["ScheduleDuration"] else "-"
else:
item.start = "-"
item.finish = "-"
@@ -431,7 +432,7 @@ class EnableEditingTaskTime(bpy.types.Operator):
if data_type == "string":
if isinstance(data[attribute.name()], datetime):
new.string_value = "" if new.is_null else data[attribute.name()].isoformat()
elif isinstance(data[attribute.name()], timedelta):
elif isinstance(data[attribute.name()], isodate.Duration):
new.string_value = "" if new.is_null else ifcopenshell.util.date.datetime2ifc(data[attribute.name()], "IfcDuration")
else:
new.string_value = "" if new.is_null else data[attribute.name()]
@@ -500,7 +501,7 @@ class EditTaskTime(bpy.types.Operator):
except:
attributes[key] = None
elif key == "ScheduleDuration":
attributes[key] = ifcopenshell.util.date.ifc2datetime(value)
attributes[key] = isodate.parse_duration(value)
return attributes