mperdeck / LINQtoCSV

Popular, easy to use library to read and write CSV files.
199 stars 112 forks source link

Add InputFormat and InputCulture attributes to have more fine grained control of Reading #40

Open Tamayi opened 9 years ago

Tamayi commented 9 years ago

I am receiving some CSV files where I receive dates in the format yyyyMMddHHmmss and sometimes, yyyyMMdd. I would like to be able to desrialise these into proper DateTime objects.

06|T|1|NHRPL|57999|Minor Theatre|M|12000|T|20080414105034|20080414125034||AC||0|1|0|0|0|0|P||

The .NET framework allows parsing these values as:

string value = "20080414105034";
DateTime.Parse(value); 'FAILURE
DateTime.ParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); 'SUCCESS

If we could optionally pass in those through settings, then it would really help to deal with these non-standard formats. Sometimes, the data does not follow standard formats for the FileCultureName property. This would then allow this sort of configuration:

[CsvColumn(FieldIndex = 9, InputFormat="yyyyMMddHHmmss", InputCulture="", OutputFormat="yyyyMMddHHmmss")]
public DateTime TransactionDate { get; set; }