John Cowen a148ae660f
ui: Adds licensing overview tab (#12706)
* Add some utilities/helpers to temporal for formatting etc

* Enable the licensing tab

* Add licensing page

* Add CSS for licensing page

* Fixup typo

* Remove box shadow from panel
2022-04-12 09:56:54 +01:00

48 lines
1.1 KiB
JavaScript

import format from 'pretty-ms';
import parse from 'parse-duration';
import { assert } from '@ember/debug';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import Service from '@ember/service';
dayjs.extend(relativeTime);
export default class TemporalService extends Service {
format(value, options) {
const djs = dayjs(value);
if(dayjs().isBefore(djs)) {
return dayjs().to(djs, true);
} else {
return dayjs().from(djs, true);
}
}
within([value, d], options) {
return dayjs(value).isBefore(dayjs().add(d, 'ms'));
}
parse(value, options) {
return parse(value);
}
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('');
case typeof value === 'string':
return value;
default:
assert(`${value} is not a valid type`, false);
return value;
}
}
}