Skip to content

Commit

Permalink
SECONDS-TO-READABLE-STR: Added. WIP for issue #38 in FoD.
Browse files Browse the repository at this point in the history
Still needs to handle singular vs. plural differences in suffix.
  • Loading branch information
lnostdal committed May 14, 2012
1 parent 1489f3d commit 82803c8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/symbolicweb/date_and_time.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 82803c8

Please sign in to comment.