I am attempting to parse records with a DateTime field, but FileHelpers is not using the format I am providing. The following is an F# script that should parse the records but throws an error. I believe the problem is related to it being an F# Script because this code works when I use it in a .fsproj and run it with dotnet run.
#r "nuget: FileHelpers, 3.5.1"
open System
open FileHelpers
[<DelimitedRecord(","); IgnoreFirst; CLIMutable>]
type RateRecord =
{
[<FieldConverter(ConverterKind.Date, "yyyy-MM-dd hh:mm")>]
DateTime : DateTime
Value : float
}
let sampleData = """DateTime,Value
2020-02-01 00:00,259
2020-02-01 00:01,267
2020-02-01 00:02,270"""
let engine = FileHelperEngine<RateRecord>()
let values = engine.ReadString sampleData
The output of running the script. The error message is at the end. Notice that the error message says it attempted to use the 'ddMMyyyy' format, which is not what I specified.
> #r "nuget: FileHelpers, 3.5.1"
-
- open System
- open FileHelpers
-
- [<DelimitedRecord(","); IgnoreFirst; CLIMutable>]
- type RateRecord =
- {
- [<FieldConverter(ConverterKind.Date, "yyyy-MM-dd hh:mm")>]
- DateTime : DateTime
- Value : float
- }
-
-
- let sampleData = """DateTime,Value
- 2020-02-01 00:00,259
- 2020-02-01 00:01,267
- 2020-02-01 00:02,270"""
-
- let engine = FileHelperEngine<RateRecord>()
- let values = engine.ReadString sampleData
- ;;
[Loading C:\Users\mcrews\AppData\Local\Temp\22000--4251218c-2322-40be-9ae7-fce17ffe54c3\Project.fsproj.fsx]
namespace FSI_0012.Project
FileHelpers.ConvertException: Error Converting '2020-02-01 00:00' to type: 'DateTime'. There are more chars in the Input String than in the Format string: 'ddMMyyyy'
at FileHelpers.Converters.DateTimeConverter.StringToField(String from)
at FileHelpers.FieldBase.AssignFromString(ExtractedInfo fieldString, LineInfo line)
at FileHelpers.FieldBase.ExtractFieldValue(LineInfo line)
at FileHelpers.RecordOperations.StringToRecord(Object record, LineInfo line, Object[] values)
at FileHelpers.FileHelperEngine`1.ReadStreamAsList(TextReader reader, Int32 maxRecords, DataTable dt)
at FileHelpers.FileHelperEngine`1.ReadStream(TextReader reader, Int32 maxRecords)
at FileHelpers.FileHelperEngine`1.ReadString(String source, Int32 maxRecords)
at FileHelpers.FileHelperEngine`1.ReadString(String source)
at <StartupCode$FSI_0013>.$FSI_0013.main@() in d:\Documents\GitHub\Scratchpad\FileHelpers\Test.fsx:line 158
Stopped due to error
>
