merge-conflicts
[arvados-workbench2.git] / src / common / formatters.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export const formatDate = (isoDate: string) => {
6     const date = new Date(isoDate);
7     return date.toLocaleString();
8 };
9
10 export const formatFileSize = (size?: number) => {
11     if (typeof size === "number") {
12         for (const { base, unit } of fileSizes) {
13             if (size >= base) {
14                 return `${(size / base).toFixed()} ${unit}`;
15             }
16         }
17     }
18     return "";
19 };
20
21 const fileSizes = [
22     {
23         base: 1000000000000,
24         unit: "TB"
25     },
26     {
27         base: 1000000000,
28         unit: "GB"
29     },
30     {
31         base: 1000000,
32         unit: "MB"
33     },
34     {
35         base: 1000,
36         unit: "KB"
37     },
38     {
39         base: 1,
40         unit: "B"
41     }
42 ];