Skip to content

Instantly share code, notes, and snippets.

@jsnikeris
Created July 26, 2011 00:42
Show Gist options
  • Save jsnikeris/1105641 to your computer and use it in GitHub Desktop.
Save jsnikeris/1105641 to your computer and use it in GitHub Desktop.
Convert "jun" -> 06 and vice versa
(require '[clj-time.format :as tf])
(defn format-month [month]
(let [letter-fmt (tf/formatter "MMM")
num-fmt (tf/formatter "MM")
converter (fn [month from-fmt to-fmt]
(->> month
(tf/parse from-fmt)
(tf/unparse to-fmt)
str/lower-case))]
(if (re-matches #"\d{2}" month)
(converter month num-fmt letter-fmt)
(converter month letter-fmt num-fmt))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment