Make date handling more robust