|
1 | 1 | import numeral from 'numeral';
|
| 2 | +import locales from 'numeral/locales'; // eslint-disable-line no-unused-vars |
2 | 3 | import _ from 'lodash';
|
3 | 4 |
|
4 | 5 | import {i18n} from './i18n';
|
5 | 6 | import {MEGABYTE, TERABYTE, DAY_IN_SECONDS, GIGABYTE} from './constants';
|
6 |
| - |
7 |
| -import locales from 'numeral/locales'; // eslint-disable-line no-unused-vars |
| 7 | +import {isNumeric} from './utils'; |
8 | 8 |
|
9 | 9 | numeral.locale(i18n.lang);
|
10 | 10 |
|
11 | 11 | export const formatBytes = (bytes) => {
|
| 12 | + if (!isNumeric(bytes)) { |
| 13 | + return ''; |
| 14 | + } |
| 15 | + |
12 | 16 | // by agreement, display byte values in decimal scale
|
13 | 17 | return numeral(bytes).format('0 b');
|
14 | 18 | };
|
@@ -53,13 +57,29 @@ export const formatThroughput = (value, total) => {
|
53 | 57 | };
|
54 | 58 |
|
55 | 59 | export const formatNumber = (number) => {
|
| 60 | + if (!isNumeric(number)) { |
| 61 | + return ''; |
| 62 | + } |
| 63 | + |
56 | 64 | return numeral(number).format();
|
57 | 65 | };
|
58 | 66 |
|
59 | 67 | export const formatCPU = (value) => {
|
| 68 | + if (!isNumeric(value)) { |
| 69 | + return ''; |
| 70 | + } |
| 71 | + |
60 | 72 | return numeral(value / 1000000).format('0.00');
|
61 | 73 | };
|
62 | 74 |
|
| 75 | +export const formatDateTime = (value) => { |
| 76 | + if (!isNumeric(value)) { |
| 77 | + return ''; |
| 78 | + } |
| 79 | + |
| 80 | + return value > 0 ? new Date(Number(value)).toUTCString() : 'N/A'; |
| 81 | +}; |
| 82 | + |
63 | 83 | export const calcUptime = (milliseconds) => {
|
64 | 84 | const currentDate = new Date();
|
65 | 85 | return formatUptime((currentDate - Number(milliseconds)) / 1000);
|
|
0 commit comments