1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export const formatDate = (isoDate: string) => {
6 const date = new Date(isoDate);
7 const text = date.toLocaleString();
8 return text === 'Invalid Date' ? "" : text;
11 export const formatFileSize = (size?: number) => {
12 if (typeof size === "number") {
13 for (const { base, unit } of FILE_SIZES) {
15 return `${(size / base).toFixed()} ${unit}`;
22 export const formatProgress = (loaded: number, total: number) => {
23 const progress = loaded >= 0 && total > 0 ? loaded * 100 / total : 0;
24 return `${progress.toFixed(2)}%`;
27 export function formatUploadSpeed(prevLoaded: number, loaded: number, prevTime: number, currentTime: number) {
28 const speed = loaded > prevLoaded && currentTime > prevTime
29 ? (loaded - prevLoaded) / (currentTime - prevTime)
31 return `${(speed / 1000).toFixed(2)} KB/s`;