Last active
July 22, 2016 15:51
-
-
Save ihercowitz/4263ca4305548bae44e8fce3260deb1c to your computer and use it in GitHub Desktop.
Convert Standard Time (AM/PM) to Militar Time (24h)
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
(defmulti std-to-militar (fn [hour time-info] (keyword time-info))) | |
(defmethod std-to-militar :AM [hour _] | |
(format "%02d" (if (= hour 12) 0 hour))) | |
(defmethod std-to-militar :PM [hour _] | |
(if (= hour 12) hour (+ hour 12))) | |
(defn convert-time [hour] | |
(let [[hour minute seconds time-info] (rest (re-find #"(\d+):(\d+):(\d+)(\w+)" hour))] | |
(clojure.string/join ":" [(std-to-militar (Integer/parseInt hour) time-info) minute seconds]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment