JoshClose/CsvHelper — Issue #24: ICsvReader.TryGetField<DateTime> should fail for an invalid DateTime (blank strings, null etc.)
Author: Sironfoot
Created: 2011-12-20 19:18:45+00:00
State: open

reader.TryGetField(fieldName)

...should return false (i.e. fail to parse to a DateTime for fields that are blank, null, invalid dates etc.). Instead it returns the date *"1/1/0000 00:00:00"*. Note that other value types (int, bool etc.) work correctly, .TryGetField will return false for blank/null fields.

E.g. consider the following CSV

IntType, DateTimeType
lalala," "
1234,"2011-12-20"

For the first row:
reader.TryGetField("IntType", out value) will return false, but
reader.TryGetField("DateTimeType", out value) will return true and 'value' will be DateTime.MinValue

Both return correct results for the second row.

Note: I'm thinking that the behaviour for TryGetField should be inline with DateTime.TryParse() method in the .NET framework.

PS: Excellent library though, keep up the good work :-)