Support datetime instances in edit_pset

This commit is contained in:
Thomas Krijnen
2025-08-16 13:35:21 +02:00
parent 126accd6a2
commit 0054b27254
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import datetime
import ifcopenshell
import ifcopenshell.util.element
import ifcopenshell.util.pset
@@ -446,6 +447,11 @@ class Usecase:
return "IfcBoolean"
elif isinstance(new_value, int):
return "IfcInteger"
# @nb datetime is also a date, so needs to be checked first
elif isinstance(new_value, datetime.datetime):
return "IfcDateTime"
elif isinstance(new_value, datetime.date):
return "IfcDate"
def cast_value_to_primary_measure_type(self, value, primary_measure_type):
type_str = self.file.create_entity(primary_measure_type).attribute_type(0)
@@ -464,6 +470,8 @@ class Usecase:
return [float(i) for i in value]
elif type_str == "AGGREGATE OF INT":
return [int(i) for i in value]
elif isinstance(value, (datetime.date, datetime.datetime)):
return value.isoformat()
return type_fn(value)
@staticmethod