X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d1272ea9203c4d6b644be3159c80eaf136f4e08c..2c8a2efbe5bac7df0a13a17ed773102d95fd1111:/src/common/formatters.ts diff --git a/src/common/formatters.ts b/src/common/formatters.ts index a7680a0454..60e6cd59c5 100644 --- a/src/common/formatters.ts +++ b/src/common/formatters.ts @@ -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 ""; +};