diff options
| author | Scott Ostler <scottbot9000@gmail.com> | 2011-02-22 21:42:33 -0500 |
|---|---|---|
| committer | Scott Ostler <scottbot9000@gmail.com> | 2011-02-22 21:42:33 -0500 |
| commit | 92fc288f6200ff0c8943cde89c62f675862cb1fa (patch) | |
| tree | f1b34e0451eb296b4b6931d6ed4c04a72250b636 /src/utils.clj | |
| parent | e9f3ddc2286f93ba07788dea0a1cecb24af60d03 (diff) | |
Add friendly dates to mute error
Diffstat (limited to 'src/utils.clj')
| -rwxr-xr-x | src/utils.clj | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/utils.clj b/src/utils.clj index a332898..c1a998c 100755 --- a/src/utils.clj +++ b/src/utils.clj @@ -157,14 +157,21 @@ (defn pluralize [word val] (if (= val 1) word (str word "s"))) +(defn build-interval-table [i] + [[(.getYears i) "year" ] + [(.getMonths i) "month" ] + [(.getDays i) "day" ] + [(.getHours i) "hour" ] + [(.getMinutes i) "minute"]]) + +(defn format-friendly-interval [i] + (if-let [[val unit] (first + (filter #(> (first %) 0) + (build-interval-table i)))] + (format "%s %s" (inc val) (pluralize unit (inc val))))) + (defn format-interval [i] - (let [vals [(.getYears i) - (.getMonths i) - (.getDays i) - (.getHours i) - (.getMinutes i)] - labels ["year" "month" "day" "hour" "minute"] - arr (into [] (for [[l v] (map vector labels vals) :when (> v 0)] + (let [arr (into [] (for [[v l] (build-interval-table i) :when (> v 0)] (str v " " (pluralize l v))))] (str-join ", " arr))) |
