Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 5e394e1

Browse files
committed
library.edit_library - support datetime for VersionDate attribute
1 parent ebd03e9 commit 5e394e1

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/ifcopenshell-python/ifcopenshell/api/library/edit_library.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
1818
import ifcopenshell
19+
import ifcopenshell.util.date
20+
import datetime
1921
from typing import Any
2022

2123

@@ -41,7 +43,16 @@ def edit_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance,
4143
attributes={"Description": "A Brickschema TTL including only mechanical distribution systems."})
4244
"""
4345

44-
settings = {"library": library, "attributes": attributes}
45-
46-
for name, value in settings["attributes"].items():
47-
setattr(settings["library"], name, value)
46+
if "VersionDate" in attributes:
47+
dt = attributes["VersionDate"]
48+
if isinstance(dt, datetime.datetime):
49+
if file.schema != "IFC2X3":
50+
dt = ifcopenshell.util.date.datetime2ifc(dt, "IfcDateTime")
51+
else:
52+
calendar_date = ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate")
53+
dt = file.create_entity("IfcCalendarDate", **calendar_date)
54+
attributes = attributes.copy()
55+
attributes["VersionDate"] = dt
56+
57+
for name, value in attributes.items():
58+
setattr(library, name, value)

0 commit comments

Comments
 (0)