mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
@@ -19,7 +19,7 @@
|
||||
import datetime
|
||||
from re import findall
|
||||
from dateutil import parser
|
||||
from typing import Literal, Union, Any
|
||||
from typing import Literal, Union, Any, overload
|
||||
|
||||
try:
|
||||
import isodate
|
||||
@@ -105,8 +105,11 @@ def readable_ifc_duration(string):
|
||||
return final_string
|
||||
|
||||
|
||||
@overload
|
||||
def datetime2ifc(dt: None, ifc_type: Any) -> None: ...
|
||||
@overload
|
||||
def datetime2ifc(
|
||||
dt: Union[datetime.date, str],
|
||||
dt: Union[datetime.date, str, None],
|
||||
ifc_type: Literal[
|
||||
"IfcDuration",
|
||||
"IfcTimeStamp",
|
||||
@@ -116,7 +119,19 @@ def datetime2ifc(
|
||||
"IfcCalendarDate",
|
||||
"IfcLocalTime",
|
||||
],
|
||||
) -> Union[int, str, dict[str, Any]]:
|
||||
) -> Union[int, str, dict[str, Any], None]: ...
|
||||
def datetime2ifc(
|
||||
dt: Union[datetime.date, str, None],
|
||||
ifc_type: Literal[
|
||||
"IfcDuration",
|
||||
"IfcTimeStamp",
|
||||
"IfcDateTime",
|
||||
"IfcDate",
|
||||
"IfcTime",
|
||||
"IfcCalendarDate",
|
||||
"IfcLocalTime",
|
||||
],
|
||||
) -> Union[int, str, dict[str, Any], None]:
|
||||
if isinstance(dt, str):
|
||||
if ifc_type == "IfcDuration":
|
||||
return dt
|
||||
@@ -124,6 +139,8 @@ def datetime2ifc(
|
||||
dt = datetime.datetime.fromisoformat(dt)
|
||||
except:
|
||||
dt = datetime.time.fromisoformat(dt)
|
||||
elif dt is None:
|
||||
return
|
||||
|
||||
if ifc_type == "IfcDuration":
|
||||
return isodate.duration_isoformat(dt)
|
||||
@@ -157,7 +174,8 @@ def datetime2ifc(
|
||||
"MinuteComponent": dt.minute,
|
||||
"SecondComponent": dt.second,
|
||||
}
|
||||
raise TypeError(f"Unsupported ifc_type for conversion from datetime.datetime = {ifc_type}.")
|
||||
|
||||
raise TypeError(f"Unsupported ifc_type for conversion from datetime.datetime = {ifc_type}, value = {dt}")
|
||||
|
||||
|
||||
def string_to_date(string):
|
||||
|
||||
Reference in New Issue
Block a user