Thanks to everyone for their suggestions. This is what I have used finally:
(defn parse-date [date-str]
(when-not (blank? date-str)
(let [clean-date-str (trim date-str)
parse-or-nil
(fn [format]
(try
(.parse format clean-date-str)
Hi,
I am just starting to learn Clojure by writing a small library. I came
across a situation in which I have to parse a String for getting a Date. Now
the string can be in one of the three formats. So I wrote this functions to
parse it:
(def #^{:private true :tag SimpleDateFormat}
Hi,
2010/7/30 abhinav sarkar abhinav.sar...@gmail.com
Hi,
I am just starting to learn Clojure by writing a small library. I came
across a situation in which I have to parse a String for getting a Date. Now
the string can be in one of the three formats. So I wrote this functions to
parse it:
parse-or-nil can be avoided by calling parse with an additional
argument (ParsePosition. 0), in which case parse returns nil on
failure.
On Jul 30, 6:21 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Hi,
2010/7/30 abhinav sarkar abhinav.sar...@gmail.com
Hi,
I am just starting to
Untested, but maybe this:
(def- parse-date [date-str]
(when-not (blank? date-str)
(let [date-str (trim date-str)]
(take 1
(filter identity
(map #(try (.parse % date-str) (catch ParseException e nil))
[full-date-format date-format-wo-tz