Last active
May 4, 2018 19:38
-
-
Save jplaza/1f2b2d8ad6e384f739e3c26a42d76b5c to your computer and use it in GitHub Desktop.
Convert seconds to a stop watch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn strftime [secs] | |
(format "%02d:%02d:%02d" | |
(mod (int (/ secs 3600)) 24) | |
(mod (int (/ secs 60)) 60) | |
(mod secs 60))) | |
(defn secs-elapsed-since-midnight [] | |
(let [now (java.time.ZonedDateTime/now) | |
midnight (.truncatedTo now java.time.temporal.ChronoUnit/DAYS) | |
duration (java.time.Duration/between midnight now)] | |
(.getSeconds duration))) | |
(defn print-clock | |
[] | |
(let [t (atom (secs-elapsed-since-midnight))] | |
(while true | |
(do | |
(print (strftime @t)) | |
(flush) | |
(Thread/sleep 1000) | |
(print "\b\b\b\b\b\b\b\b") | |
(flush) | |
(swap! t inc))))) | |
(print-clock) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn strftime [secs] | |
(format "%02d:%02d:%02d" | |
(mod (int (/ secs 3600)) 24) | |
(mod (int (/ secs 60)) 60) | |
(mod secs 60))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment