Refactor formatting datetimes and times