From 5c4f1576245a2aae4ef57301d57c22332a3ba5ea Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 21 Apr 2025 18:58:29 +0500 Subject: [PATCH] readable_ifc_duration - add doc-string and note --- src/ifcopenshell-python/ifcopenshell/util/date.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/date.py b/src/ifcopenshell-python/ifcopenshell/util/date.py index f3cc59078f..ac64d189a2 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/date.py +++ b/src/ifcopenshell-python/ifcopenshell/util/date.py @@ -70,7 +70,18 @@ def ifc2datetime(element: Union[str, int, ifcopenshell.entity_instance]): ) -def readable_ifc_duration(duration): +def readable_ifc_duration(duration: str) -> str: + """Convert ISO duration to more readable string format. + + Examples: + - "P2Y3M1W4DT5H45M30S" -> "2 Y 3 M 1 W 4 D 5 h 45 m 30 s" + - "P2Y3MT30S" -> "2 Y 3 M 30 s" + - "PT2500H" -> "2500 h" (hours are not converted to days) + """ + # NOTE: we don't use isodate.parseduration as it's going to + # represent "PT2500H" as "12w 6d 4h", though user may want + # intentionally to use just hours. + if "T" in duration: period_duration, time_duration = duration.split("T") period_duration = period_duration[1:] @@ -78,7 +89,7 @@ def readable_ifc_duration(duration): period_duration = duration[1:] time_duration = "" - result = [] + result: list[str] = [] for designator in ("Y", "M", "W", "D"): if designator in period_duration: value, period_duration = period_duration.split(designator)