Refactoring some date handling