17337: Fixed failing unit test
[arvados-workbench2.git] / src / common / formatters.ts
index 819875bec14c6527ce177ee6478ac435a698844d..17917127f1c26ac18221f8b34a2efcfd6413da5f 100644 (file)
@@ -22,19 +22,26 @@ export const formatDate = (isoDate?: string | null, utc: boolean = false) => {
 
 export const formatFileSize = (size?: number) => {
     if (typeof size === "number") {
+        if (size === 0) { return "0 B"; }
+
         for (const { base, unit } of FILE_SIZES) {
             if (size >= base) {
                 return `${(size / base).toFixed()} ${unit}`;
             }
         }
     }
-    return "";
+    return "0 B";
 };
 
-export const formatTime = (time: number) => {
+export const formatTime = (time: number, seconds?: boolean) => {
     const minutes = Math.floor(time / (1000 * 60) % 60).toFixed(0);
     const hours = Math.floor(time / (1000 * 60 * 60)).toFixed(0);
 
+    if (seconds) {
+        const seconds = Math.floor(time / (1000) % 60).toFixed(0);
+        return hours + "h " + minutes + "m " + seconds + "s";
+    }
+
     return hours + "h " + minutes + "m";
 };