From 426f1b91f249f19f20d9f87cde1a486927f3af74 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 21 Apr 2025 22:59:14 +1000 Subject: [PATCH] See #2783. Don't show 0 durations for clarity. --- src/ifcopenshell-python/ifcopenshell/util/date.py | 6 ++++-- src/ifcopenshell-python/test/util/test_date.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) 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"