Refactoring dateFormat method.