Add date support.
Some refactorings to simplify code.