aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/tau/util.cljs
blob: d23ef9a97e068d606705fea43d1a499742124361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(ns tau.util
  (:require
   ["timeago.js" :as timeago]))

(defn format-date
  [date]
  (if (-> date js/Date.parse js/isNaN)
    date
    (timeago/format date)))

(defn format-quantity
  [num]
  (.format
   (js/Intl.NumberFormat
    "en-US" #js {"notation" "compact" "maximumFractionDigits" 1})
   num))

(defn format-duration
  [num]
  (let [duration (js/Date. (* num 1000))
        slice (if (> (.getHours duration) 1)
                #(.slice % 11 19)
                #(.slice % 14 19))]
    (-> duration (.toISOString) slice)))