fleet/frontend/components/hosts/HostDetails/helpers.js
2017-01-05 12:08:50 -06:00

24 lines
612 B
JavaScript

import moment from 'moment';
const BYTES_PER_GIGABYTE = 1000000000;
const NANOSECONDS_PER_MILLISECOND = 1000000;
const inGigaBytes = (bytes) => {
return (bytes / BYTES_PER_GIGABYTE).toFixed(2);
};
const inMilliseconds = (nanoseconds) => {
return nanoseconds / NANOSECONDS_PER_MILLISECOND;
};
export const humanUptime = (uptimeInNanoseconds) => {
const milliseconds = inMilliseconds(uptimeInNanoseconds);
return moment.duration(milliseconds, 'milliseconds').humanize();
};
export const humanMemory = (bytes) => {
return `${inGigaBytes(bytes)} GB`;
};
export default { humanMemory, humanUptime };