Refactored date parsing method.