open-consul/ui/packages/consul-ui/app/services/temporal.js
John Cowen a389eab7b0
ui: Adds human formatting to nanosecond based session durations (#10062)
* ui: Adds human formatting to nanosecond based session durations
2021-04-28 12:12:56 +01:00

22 lines
583 B
JavaScript

import format from 'pretty-ms';
import { assert } from '@ember/debug';
import Service from '@ember/service';
export default class TemporalService extends Service {
durationFrom(value, options = {}) {
switch (true) {
case typeof value === 'number':
// if its zero, don't format just return zero as a string
if (value === 0) {
return '0';
}
return format(value / 1000000, { formatSubMilliseconds: true })
.split(' ')
.join('');
}
assert(`${value} is not a valid type`, false);
return value;
}
}