15672: Fix NaN runtime
[arvados-workbench2.git] / src / store / processes / process.ts
index ab8093b856c4c259b1bab8992e98293444f7ac78..400d77cfc88ee38942e46a5a1a6692e5a9ee82a2 100644 (file)
@@ -56,10 +56,20 @@ export const getSubprocesses = (uuid: string) => (resources: ResourcesState) =>
     return [];
 };
 
-export const getProcessRuntime = ({ container }: Process) =>
-    container
-        ? getTimeDiff(container.finishedAt || '', container.startedAt || '')
-        : 0;
+export const getProcessRuntime = ({ container }: Process) => {
+    if (container) {
+        if (container.startedAt === null) {
+            return 0;
+        }
+        if (container.finishedAt === null) {
+            // Count it from now
+            return new Date().getTime() - new Date(container.startedAt).getTime();
+        }
+        return getTimeDiff(container.finishedAt, container.startedAt);
+    } else {
+        return 0;
+    }
+};
 
 export const getProcessStatusColor = (status: string, { customs, palette }: ArvadosTheme) => {
     switch (status) {