Skip to content

Instantly share code, notes, and snippets.

@ihercowitz
Last active July 22, 2016 15:51
Show Gist options
  • Save ihercowitz/4263ca4305548bae44e8fce3260deb1c to your computer and use it in GitHub Desktop.
Save ihercowitz/4263ca4305548bae44e8fce3260deb1c to your computer and use it in GitHub Desktop.
Convert Standard Time (AM/PM) to Militar Time (24h)
(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