refactored parseDate method