refactor formatDate function and create test