DateTimeField For Lift That CouchDB Can Sort

23 August 2010

The other day I ran into a slight problem with the interaction between Lift and CouchDB. I wanted to have Couch emit a list of records sorted by date, but the format of Lift’s DateTimeField doesn’t sort lexicographically.

To remedy this (and as an exercise in Scala and Lift) I decided to write a new class that extended DataTimeField, but converted the date to and from a format that would work better with Couch.

I ran into a few small hurdles that were due to my lack of Scala knowledge, but the entire process took less time than I expected.

I decided to use the ISO 8601 format and the most important change was going from:

SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US)

to:

SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz", Locale.US)

To make things easier for the next person I threw the class onto Github

Fork me on GitHub