I released Yaclot 0.1.0 to Clojars. This version can be used to convert single values as well as records.
Converting individual values looks like:
(convert "2011-02-12" (to-type java.util.Date)) ; => #<Date Sat Feb 12 00:00:00 CET 2011> (convert "2/12/11" (using-format "M/dd/yy" (to-type java.util.Date))) ; => #<Date Sat Feb 12 00:00:00 CET 2011> (convert 5000.42 (to-type String (using-format "%,.2f"))) ; => "5,000.42"
Order of using-format
and to-type
doesn’t matter. using-format
is optional (default for dates is yyyy-MM-dd
).
You can also use it to convert records in a single operation:
(map-convert {:dt "2011-02-12" :int 42 :label "Label"} ; Record {:dt (to-type java.util.Date) ; Desired types :int (to-type String)}) ; => {:dt #<Date Sat Feb 12 00:00:00 CET 2011>, :int "42", :label "Label"}
The project originated from a pet web application, where I needed to deal with parsing and formatting numbers and dates between the “presentation”, “business logic” and “database” layers.
To learn more about motivation, features and syntax, take a look at the draft in my previous post.
This version supports conversions between String, Date and numeric types. Next on the road map is exception-free error handling with local bindings and validation.
See also: