mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
@@ -19,7 +19,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from re import findall
|
from re import findall
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
from typing import Literal, Union, Any
|
from typing import Literal, Union, Any, overload
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import isodate
|
import isodate
|
||||||
@@ -105,8 +105,11 @@ def readable_ifc_duration(string):
|
|||||||
return final_string
|
return final_string
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def datetime2ifc(dt: None, ifc_type: Any) -> None: ...
|
||||||
|
@overload
|
||||||
def datetime2ifc(
|
def datetime2ifc(
|
||||||
dt: Union[datetime.date, str],
|
dt: Union[datetime.date, str, None],
|
||||||
ifc_type: Literal[
|
ifc_type: Literal[
|
||||||
"IfcDuration",
|
"IfcDuration",
|
||||||
"IfcTimeStamp",
|
"IfcTimeStamp",
|
||||||
@@ -116,7 +119,19 @@ def datetime2ifc(
|
|||||||
"IfcCalendarDate",
|
"IfcCalendarDate",
|
||||||
"IfcLocalTime",
|
"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 isinstance(dt, str):
|
||||||
if ifc_type == "IfcDuration":
|
if ifc_type == "IfcDuration":
|
||||||
return dt
|
return dt
|
||||||
@@ -124,6 +139,8 @@ def datetime2ifc(
|
|||||||
dt = datetime.datetime.fromisoformat(dt)
|
dt = datetime.datetime.fromisoformat(dt)
|
||||||
except:
|
except:
|
||||||
dt = datetime.time.fromisoformat(dt)
|
dt = datetime.time.fromisoformat(dt)
|
||||||
|
elif dt is None:
|
||||||
|
return
|
||||||
|
|
||||||
if ifc_type == "IfcDuration":
|
if ifc_type == "IfcDuration":
|
||||||
return isodate.duration_isoformat(dt)
|
return isodate.duration_isoformat(dt)
|
||||||
@@ -157,7 +174,8 @@ def datetime2ifc(
|
|||||||
"MinuteComponent": dt.minute,
|
"MinuteComponent": dt.minute,
|
||||||
"SecondComponent": dt.second,
|
"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):
|
def string_to_date(string):
|
||||||
|
|||||||
Reference in New Issue
Block a user