]> git.r.bdr.sh - rbdr/forum/blobdiff - src/lib/utils/readable_time.ts
Don't remember what this WIP was about
[rbdr/forum] / src / lib / utils / readable_time.ts
index 86ba044843514d01a4027d2587c10e01ee8111a3..c949981aa96afe17aeb1f377bd4206407d896e3d 100644 (file)
@@ -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');
+       }
 };