Skip to content

Configure default DateTimeKind when no timezone information given #1100

@2moveit

Description

@2moveit

All TypeProviders will convert the DateTime string"03.01.2016 00:00:00" automatically to DateTimeKind.Local.
https://github.com/fsharp/FSharp.Data/blob/b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547/src/CommonRuntime/TextConversions.fs#L103-L104

I think it's correct that it is set to DateTimeKind.Local as of ISO 8601 although the default of .NET DateTime() is Kind.Unspecified.
Although you're not doing it explicitly you usually want to use it that way and in 90% of the case it will be correct.

In my case I get a CSV file for price lists from different countries (timezones). The date has the mentioned form "03.01.2016 00:00:00".
So there is no information about the timezone. Although the other system should've used the ISO 8601 format there are many reasons that this might happen especially when using the .NET DateTime class and not being aware of timezones.

As mentioned there are edge cases where you have to do an additional manual convertion to set it to DateTimeKind.Unspecified. E.g by new DateTime(old.Year, old.Month, old.Day).
That is a little bit hacky and so I like to be able to configure the TypeProvider to use Kind.Unspecified as default if the there is no information of the timezone given.
So my suggestion is to make this configurable when initializing the TypeProvider.

Before trying to contribute (where I might need your help) I'd like to discuss this before starting it as it will effect all TypeProviders. Suggestions how to implement it are welcome.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions