Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jackrusher/7168249b07cbf5f6c062 to your computer and use it in GitHub Desktop.
Save jackrusher/7168249b07cbf5f6c062 to your computer and use it in GitHub Desktop.
(def date-parsers [nil (java.text.SimpleDateFormat. "yyyy") (java.text.SimpleDateFormat. "yyyy-M") (java.text.SimpleDateFormat. "yyyy-M-dd")])
(def grains [:decade :year :month :day]) ;; what's decade doing?
(map #(let [[_ year month day] (re-find #"(\d{2,4})[-_]([\dx]{2})[-_]([\dx]{2})" %)
date (first (split-with (partial not= "xx") [(if (= (count year) 2) (str "19" year) year) month day]))]
[(.parse (parsers (count date)) (clojure.string/join "-" date)) (grains (count date))])
["thefilehasaname__1939-xx-01.mp3"
"thefilehasaname__39_01_01.mp3"
"thefilehasaname__39-01-01.mp3"
"thefilehasaname__1939-01-01.mp3"
"thefilehasaname__1949-xx-xx.mp3"
"thefilehasaname__1972-xx-xx.mp3"
"thefilehasaname__1972-08-xx.mp3"
"thefilehasaname__1972-08-11.mp3"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment