Created
November 25, 2015 02:27
-
-
Save chrisguitarguy/66e08fdc84979a3ce324 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (require '[clojure.string :as string]) | |
| (defn- str->int [s] | |
| (Integer/parseInt s)) | |
| (defn- parse-time [timestr] | |
| (let [[hours mins secs-and-ampm] (string/split timestr #":" 3) | |
| secs (subs secs-and-ampm 0 2) | |
| ampm (subs secs-and-ampm 2)] | |
| {:hours (str->int hours) | |
| :minutes (str->int mins) | |
| :seconds (str->int secs) | |
| :ampm (string/lower-case ampm)})) | |
| (defn- am? [tm] | |
| (= "am" (:ampm tm))) | |
| (defn- pm? [tm] | |
| (= "pm" (:ampm tm))) | |
| (defn- format-time [tm] | |
| (format "%02d:%02d:%02d" (:hours tm) (:minutes tm) (:seconds tm))) | |
| (defn print-time [tm] | |
| (println (format-time tm))) | |
| (defn -main [& args] | |
| (let [tm (parse-time (read-line)) | |
| hours (:hours tm)] | |
| (cond | |
| (and (am? tm) (= 12 hours)) (print-time (assoc tm :hours 0)) | |
| (and (pm? tm) (< hours 12)) (print-time (assoc tm :hours (+ hours 12))) | |
| :else (print-time tm)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment