Fix errors in date handling