Make cdate sorting more robust, closes #14

This is a slightly modified version of the patch provided by Leon Bottou
in #14.