X-Git-Url: https://git.r.bdr.sh/rbdr/forum/blobdiff_plain/a7cf03c192470cbab13edeb1aec99e0c66dede10..7b66f8a69c747932118a3e81f50c69258200d1e5:/src/lib/utils/readable_time.ts?ds=sidebyside diff --git a/src/lib/utils/readable_time.ts b/src/lib/utils/readable_time.ts index 86ba044..c949981 100644 --- a/src/lib/utils/readable_time.ts +++ b/src/lib/utils/readable_time.ts @@ -1,46 +1,43 @@ type DateMagnitude = 'day' | 'hour' | 'minute' | 'second'; type ReadableTime = { - count: number, - label: string + count: number; + label: string; }; - const internals = { - magnitudes: { - day: 86400000, - hour: 3600000, - minute: 60000, - second: 1000 - }, - labels: { - day: 'time.days', - hour: 'time.hours', - minute: 'time.minutes', - second: 'time.seconds' - }, - - makeTimeReadable(time: number, magnitude: DateMagnitude): ReadableTime { + magnitudes: { + day: 86400000, + hour: 3600000, + minute: 60000, + second: 1000 + }, + labels: { + day: 'time.days', + hour: 'time.hours', + minute: 'time.minutes', + second: 'time.seconds' + }, - return { - count: Math.floor(time / internals.magnitudes[magnitude]), - label: internals.labels[magnitude] - }; - } + makeTimeReadable(time: number, magnitude: DateMagnitude): ReadableTime { + return { + count: Math.floor(time / internals.magnitudes[magnitude]), + label: internals.labels[magnitude] + }; + } }; export const readableTime = function readableTime(time: number): ReadableTime { - - switch (true) { - case time >= internals.magnitudes.day: - return internals.makeTimeReadable(time, 'day'); - case time >= internals.magnitudes.hour: - return internals.makeTimeReadable(time, 'hour'); - case time >= internals.magnitudes.minute: - return internals.makeTimeReadable(time, 'minute'); - case time < 0: - return internals.makeTimeReadable(0, 'second'); - default: - return internals.makeTimeReadable(time, 'second'); - } + switch (true) { + case time >= internals.magnitudes.day: + return internals.makeTimeReadable(time, 'day'); + case time >= internals.magnitudes.hour: + return internals.makeTimeReadable(time, 'hour'); + case time >= internals.magnitudes.minute: + return internals.makeTimeReadable(time, 'minute'); + case time < 0: + return internals.makeTimeReadable(0, 'second'); + default: + return internals.makeTimeReadable(time, 'second'); + } };