Merge branch '17305-projects-file-size-always-0'
[arvados-workbench2.git] / src / common / formatters.ts
index 819875bec14c6527ce177ee6478ac435a698844d..d8228bf5eb007f5c0843d0f16990a73e9b9a1d28 100644 (file)
@@ -20,21 +20,31 @@ export const formatDate = (isoDate?: string | null, utc: boolean = false) => {
     return "(none)";
 };
 
-export const formatFileSize = (size?: number) => {
+export const formatFileSize = (size?: number | string) => {
     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}`;
             }
         }
+    } 
+    if ((typeof size === "string" && size === '') || size === undefined) {
+        return '';
     }
-    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";
 };