This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-3-test by this push:
new 72837d91a5b [v3-3-test] Fix td_format rendering of negative durations
(#72694) (#72774) (#72798)
72837d91a5b is described below
commit 72837d91a5be995352d92cdb53c29e8934ea2629
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Sep 9 13:12:28 2026 +0200
[v3-3-test] Fix td_format rendering of negative durations (#72694) (#72774)
(#72798)
(cherry picked from commit 3e8f91818cf53a75802bcc19f45c2fd50aed6c3f)
Signed-off-by: SHIVANSH-ux-ys <[email protected]>
Co-authored-by: Shivansh Goel <[email protected]>
---
shared/timezones/src/airflow_shared/timezones/timezone.py | 13 ++++++++++++-
shared/timezones/tests/timezones/test_timezone.py | 11 +++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/shared/timezones/src/airflow_shared/timezones/timezone.py
b/shared/timezones/src/airflow_shared/timezones/timezone.py
index 45b538a52a8..b8919943e02 100644
--- a/shared/timezones/src/airflow_shared/timezones/timezone.py
+++ b/shared/timezones/src/airflow_shared/timezones/timezone.py
@@ -234,6 +234,17 @@ def td_format(td_object: None | dt.timedelta | float |
int) -> str | None:
"""
if td_object is None:
return None
+
+ prefix = ""
+ if isinstance(td_object, dt.timedelta):
+ if td_object < dt.timedelta(0):
+ prefix = "-"
+ td_object = -td_object
+ elif isinstance(td_object, (int, float)):
+ if td_object < 0:
+ prefix = "-"
+ td_object = -td_object
+
if isinstance(td_object, dt.timedelta):
delta = relativedelta() + td_object
else:
@@ -258,7 +269,7 @@ def td_format(td_object: None | dt.timedelta | float | int)
-> str | None:
joined = ":".join(part for part in parts if part)
if not joined:
return "<1s"
- return joined
+ return f"{prefix}{joined}"
def parse_timezone(name: str | int) -> FixedTimezone | Timezone:
diff --git a/shared/timezones/tests/timezones/test_timezone.py
b/shared/timezones/tests/timezones/test_timezone.py
index 83889dfe076..af68e25c319 100644
--- a/shared/timezones/tests/timezones/test_timezone.py
+++ b/shared/timezones/tests/timezones/test_timezone.py
@@ -96,6 +96,17 @@ class TestTimezone:
assert timezone.td_format(td) == "3d:11h:32M:32s"
td = 434343600.0
assert timezone.td_format(td) == "13y:11m:17d:3h"
+ # Negative durations
+ td = datetime.timedelta(seconds=-3752)
+ assert timezone.td_format(td) == "-1h:2M:32s"
+ td = -3752
+ assert timezone.td_format(td) == "-1h:2M:32s"
+ td = datetime.timedelta(days=-5)
+ assert timezone.td_format(td) == "-5d"
+ td = datetime.timedelta(seconds=-0.4)
+ assert timezone.td_format(td) == "<1s"
+ td = -0.4
+ assert timezone.td_format(td) == "<1s"
@pytest.mark.parametrize(