#386 Fixed invalid date handling and added test