1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { PropertyValue } from "~/models/search-bar";
7 export const formatDate = (isoDate?: string) => {
9 const date = new Date(isoDate);
10 const text = date.toLocaleString();
11 return text === 'Invalid Date' ? "" : text;
16 export const formatFileSize = (size?: number) => {
17 if (typeof size === "number") {
18 for (const { base, unit } of FILE_SIZES) {
20 return `${(size / base).toFixed()} ${unit}`;
27 export const formatTime = (time: number) => {
28 const minutes = Math.floor(time / (1000 * 60) % 60).toFixed(0);
29 const hours = Math.floor(time / (1000 * 60 * 60)).toFixed(0);
31 return hours + "h " + minutes + "m";
34 export const getTimeDiff = (endTime: string, startTime: string) => {
35 return new Date(endTime).getTime() - new Date(startTime).getTime();
38 export const formatProgress = (loaded: number, total: number) => {
39 const progress = loaded >= 0 && total > 0 ? loaded * 100 / total : 0;
40 return `${progress.toFixed(2)}%`;
43 export function formatUploadSpeed(prevLoaded: number, loaded: number, prevTime: number, currentTime: number) {
44 const speed = loaded > prevLoaded && currentTime > prevTime
45 ? (loaded - prevLoaded) / (currentTime - prevTime)
47 return `${(speed / 1000).toFixed(2)} KB/s`;
73 export const formatPropertyValue = (pv: PropertyValue) => {
76 ? `${pv.key}: ${pv.value}`