diff --git a/src/ifcopenshell-python/ifcopenshell/util/date.py b/src/ifcopenshell-python/ifcopenshell/util/date.py index 47bdd8b722..e6307827da 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/date.py +++ b/src/ifcopenshell-python/ifcopenshell/util/date.py @@ -81,13 +81,15 @@ def readable_ifc_duration(duration): for designator in ("Y", "M", "W", "D"): if designator in period_duration: value, period_duration = period_duration.split(designator) - result.append(f"{value}{designator}") + if int(value): + result.append(f"{value}{designator}") if time_duration: for designator in ("H", "M", "S"): if designator in time_duration: value, time_duration = time_duration.split(designator) - result.append(f"{value}{designator.lower()}") + if int(value): + result.append(f"{value}{designator.lower()}") return " ".join(result) diff --git a/src/ifcopenshell-python/test/util/test_date.py b/src/ifcopenshell-python/test/util/test_date.py index 8be56c3b01..b96e2066dc 100644 --- a/src/ifcopenshell-python/test/util/test_date.py +++ b/src/ifcopenshell-python/test/util/test_date.py @@ -23,5 +23,6 @@ import ifcopenshell.util.date as subject class TestReadableIFCDuration(): def test_run(self): + assert subject.readable_ifc_duration("P0Y0M1DT16H0M0S") == "1D 16h" assert subject.readable_ifc_duration("P2Y3M1W4DT5H45M30S") == "2Y 3M 1W 4D 5h 45m 30s" assert subject.readable_ifc_duration("PT40H") == "40h"