Merge branch '15166-size-between-icons-on-workflow-panel-is-too-wide'
[arvados-workbench2.git] / src / common / formatters.ts
index a7680a04544f26839dbd3f29bb7e1b56b04073ad..60e6cd59c53e284a929cd6143c618020537ffd3a 100644 (file)
@@ -2,10 +2,15 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export const formatDate = (isoDate: string) => {
-    const date = new Date(isoDate);
-    const text = date.toLocaleString();
-    return text === 'Invalid Date' ? "" : text;
+import { PropertyValue } from "~/models/search-bar";
+
+export const formatDate = (isoDate?: string | null) => {
+    if (isoDate) {
+        const date = new Date(isoDate);
+        const text = date.toLocaleString();
+        return text === 'Invalid Date' ? "(none)" : text;
+    }
+    return "(none)";
 };
 
 export const formatFileSize = (size?: number) => {
@@ -19,14 +24,14 @@ export const formatFileSize = (size?: number) => {
     return "";
 };
 
-export const msToTime = (time: number) => {
+export const formatTime = (time: number) => {
     const minutes = Math.floor(time / (1000 * 60) % 60).toFixed(0);
     const hours = Math.floor(time / (1000 * 60 * 60)).toFixed(0);
 
     return hours + "h " + minutes + "m";
 };
 
-export const getDiffTime = (endTime: string, startTime: string) => {
+export const getTimeDiff = (endTime: string, startTime: string) => {
     return new Date(endTime).getTime() - new Date(startTime).getTime();
 };
 
@@ -64,3 +69,12 @@ const FILE_SIZES = [
         unit: "B"
     }
 ];
+
+export const formatPropertyValue = (pv: PropertyValue) => {
+    if (pv.key) {
+        return pv.value
+            ? `${pv.key}: ${pv.value}`
+            : pv.key;
+    }
+    return "";
+};