Permalink
Browse files

SECONDS-TO-READABLE-STR: Added. WIP for issue #38 in FoD.

Still needs to handle singular vs. plural differences in suffix.
  • Loading branch information...
1 parent 1489f3d commit 82803c8808df92d7a44f8b174b1ee2e919ba2a40 @lnostdal committed May 14, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/symbolicweb/date_and_time.clj
View
18 src/symbolicweb/date_and_time.clj
@@ -16,6 +16,24 @@
(let [[h m s] (seconds-to-hms seconds)]
(format "%02d%c%02d%c%02d" h separator m separator s))))
+(defn seconds-to-readable-str [seconds & {:keys [day-suffix hour-suffix minute-suffix second-suffix]
+ :or {day-suffix " days "
+ hour-suffix " hours "
+ minute-suffix " minutes "
+ second-suffix " seconds"}}]
+ (let [[hours minutes seconds] (seconds-to-hms seconds)
+ days (quot hours 24)
+ hours (rem hours 24)]
+ (if (pos? days)
+ (format "%d%s%d%s%d%s"
+ days day-suffix
+ hours hour-suffix
+ minutes minute-suffix)
+ (format "%d%s%d%s%d%s"
+ hours hour-suffix
+ minutes minute-suffix
+ seconds second-suffix))))
+
(defn hms-to-seconds [hours minutes seconds]
"HOURS, MINUTES and SECONDS are integers. This returns a single integer value; seconds."

0 comments on commit 82803c8

Please sign in to comment.