Created
July 26, 2011 00:42
-
-
Save jsnikeris/1105641 to your computer and use it in GitHub Desktop.
Convert "jun" -> 06 and vice versa
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
(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