This is an automated email from the ASF dual-hosted git repository.

bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b02141b0f9e Fix getDuration not showing elapsed time for running tasks 
#63602 (#63619)
b02141b0f9e is described below

commit b02141b0f9edb705afe0ceb1672060a29ae764b1
Author: Haseeb Malik <[email protected]>
AuthorDate: Wed Mar 18 13:23:49 2026 -0400

    Fix getDuration not showing elapsed time for running tasks #63602 (#63619)
---
 .../src/airflow/ui/src/utils/datetimeUtils.test.ts        | 15 +++++++++++++++
 airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts    |  5 +++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/airflow-core/src/airflow/ui/src/utils/datetimeUtils.test.ts 
b/airflow-core/src/airflow/ui/src/utils/datetimeUtils.test.ts
index 0f9ba62c67c..a0a39211257 100644
--- a/airflow-core/src/airflow/ui/src/utils/datetimeUtils.test.ts
+++ b/airflow-core/src/airflow/ui/src/utils/datetimeUtils.test.ts
@@ -60,8 +60,23 @@ describe("getDuration", () => {
     // eslint-disable-next-line unicorn/no-null
     expect(getDuration(null, null)).toBe(undefined);
     expect(getDuration(undefined, undefined)).toBe(undefined);
+    // eslint-disable-next-line unicorn/no-null
+    expect(getDuration(null, "2024-03-14T10:00:10.000Z")).toBe(undefined);
     expect(renderDuration(0.000_01)).toBe(undefined);
   });
+
+  it("falls back to current time when endDate is null (running task)", () => {
+    vi.useFakeTimers();
+    vi.setSystemTime(new Date("2024-03-14T10:00:10.000Z"));
+
+    const start = "2024-03-14T10:00:00.000Z";
+
+    // eslint-disable-next-line unicorn/no-null
+    expect(getDuration(start, null)).toBe("00:00:10.000");
+    expect(getDuration(start, undefined)).toBe("00:00:10.000");
+
+    vi.useRealTimers();
+  });
 });
 
 describe("getRelativeTime", () => {
diff --git a/airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts 
b/airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts
index 1fe6b65ef88..773e6d2b072 100644
--- a/airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts
+++ b/airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts
@@ -52,11 +52,12 @@ export const getDuration = (
   endDate?: string | null,
   withMilliseconds: boolean = true,
 ) => {
-  if (startDate === undefined || startDate === null || endDate === undefined 
|| endDate === null) {
+  if (startDate === undefined || startDate === null) {
     return undefined;
   }
 
-  const seconds = dayjs.duration(dayjs(endDate).diff(startDate)).asSeconds();
+  const end = endDate ?? dayjs().toISOString();
+  const seconds = dayjs.duration(dayjs(end).diff(startDate)).asSeconds();
 
   return renderDuration(seconds, withMilliseconds);
 };

Reply via email to