Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DateTimeOffset for Csv Schema Inference #1304

Merged
merged 9 commits into from
Oct 4, 2020
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ paket-files
TestResults
*.log
.vscode
.idea
.idea
.ionide
3 changes: 3 additions & 0 deletions docs/content/library/CsvProvider.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ specify the units of measure. This will override both `AssumeMissingValues` and
* `date`
* `date?`
* `date option`
* `datetimeoffset`
* `datetimeoffset?`
* `datetimeoffset option`
* `guid`
* `guid?`
* `guid option`
Expand Down
2 changes: 1 addition & 1 deletion docs/content/library/XmlProvider.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ When the file includes other schema files, the `ResolutionFolder` parameter can
The uri may also refer to online resources:
*)

type RssXsd = XmlProvider<Schema = "http://europa.eu/rapid/conf/RSS20.xsd">
type RssXsd = XmlProvider<Schema = "https://www.w3schools.com/xml/note.xsd">

(**

Expand Down
5 changes: 4 additions & 1 deletion src/CommonRuntime/StructuralTypes.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FSharp.Data.Runtime.StructuralTypes
namespace FSharp.Data.Runtime.StructuralTypes

open System
open FSharp.Data.Runtime
Expand Down Expand Up @@ -33,6 +33,7 @@ and [<RequireQualifiedAccess>] InferedTypeTag =
| Json
| DateTime
| TimeSpan
| DateTimeOffset
| Guid
// Collections and sum types
| Collection
Expand Down Expand Up @@ -123,6 +124,7 @@ type InferedTypeTag with
| String -> "String"
| DateTime -> "DateTime"
| TimeSpan -> "TimeSpan"
| DateTimeOffset -> "DateTimeOffset"
| Guid -> "Guid"
| Collection -> "Array"
| Heterogeneous -> "Choice"
Expand All @@ -147,6 +149,7 @@ type InferedTypeTag with
| "String" -> String
| "DateTime" -> DateTime
| "TimeSpan" -> TimeSpan
| "DateTimeOffset" -> DateTimeOffset
| "Guid" -> Guid
| "Array" -> Collection
| "Choice" -> Heterogeneous
Expand Down
55 changes: 29 additions & 26 deletions src/Csv/CsvInference.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@ open FSharp.Data.Runtime.StructuralInference
/// The schema may be set explicitly. This table specifies the mapping
/// from the names that users can use to the types used.
let private nameToType =
["int" , (typeof<int> , TypeWrapper.None )
"int64", (typeof<int64> , TypeWrapper.None )
"bool", (typeof<bool> , TypeWrapper.None )
"float", (typeof<float> , TypeWrapper.None )
"decimal", (typeof<decimal> , TypeWrapper.None )
"date", (typeof<DateTime>, TypeWrapper.None )
"timespan", (typeof<TimeSpan>, TypeWrapper.None )
"guid", (typeof<Guid> , TypeWrapper.None )
"string", (typeof<String> , TypeWrapper.None )
"int?", (typeof<int> , TypeWrapper.Nullable)
"int64?", (typeof<int64> , TypeWrapper.Nullable)
"bool?", (typeof<bool> , TypeWrapper.Nullable)
"float?", (typeof<float> , TypeWrapper.Nullable)
"decimal?", (typeof<decimal> , TypeWrapper.Nullable)
"date?", (typeof<DateTime>, TypeWrapper.Nullable)
"timespan?", (typeof<TimeSpan>, TypeWrapper.Nullable)
"guid?", (typeof<Guid> , TypeWrapper.Nullable)
"int option", (typeof<int> , TypeWrapper.Option )
"int64 option", (typeof<int64> , TypeWrapper.Option )
"bool option", (typeof<bool> , TypeWrapper.Option )
"float option", (typeof<float> , TypeWrapper.Option )
"decimal option", (typeof<decimal> , TypeWrapper.Option )
"date option", (typeof<DateTime>, TypeWrapper.Option )
"timespan option",(typeof<TimeSpan>, TypeWrapper.Option )
"guid option", (typeof<Guid> , TypeWrapper.Option )
"string option", (typeof<string> , TypeWrapper.Option )]
["int" , (typeof<int> , TypeWrapper.None )
"int64", (typeof<int64> , TypeWrapper.None )
"bool", (typeof<bool> , TypeWrapper.None )
"float", (typeof<float> , TypeWrapper.None )
"decimal", (typeof<decimal> , TypeWrapper.None )
"date", (typeof<DateTime> , TypeWrapper.None )
"datetimeoffset", (typeof<DateTimeOffset>, TypeWrapper.None )
"timespan", (typeof<TimeSpan> , TypeWrapper.None )
"guid", (typeof<Guid> , TypeWrapper.None )
"string", (typeof<String> , TypeWrapper.None )
"int?", (typeof<int> , TypeWrapper.Nullable)
"int64?", (typeof<int64> , TypeWrapper.Nullable)
"bool?", (typeof<bool> , TypeWrapper.Nullable)
"float?", (typeof<float> , TypeWrapper.Nullable)
"decimal?", (typeof<decimal> , TypeWrapper.Nullable)
"date?", (typeof<DateTime> , TypeWrapper.Nullable)
"datetimeoffset?", (typeof<DateTimeOffset>, TypeWrapper.Nullable)
"timespan?", (typeof<TimeSpan> , TypeWrapper.Nullable)
"guid?", (typeof<Guid> , TypeWrapper.Nullable)
"int option", (typeof<int> , TypeWrapper.Option )
"int64 option", (typeof<int64> , TypeWrapper.Option )
"bool option", (typeof<bool> , TypeWrapper.Option )
"float option", (typeof<float> , TypeWrapper.Option )
"decimal option", (typeof<decimal> , TypeWrapper.Option )
"date option", (typeof<DateTime> , TypeWrapper.Option )
"datetimeoffset option",(typeof<DateTimeOffset>, TypeWrapper.Option )
"timespan option", (typeof<TimeSpan> , TypeWrapper.Option )
"guid option", (typeof<Guid> , TypeWrapper.Option )
"string option", (typeof<string> , TypeWrapper.Option )]
|> dict

let private nameAndTypeRegex = lazy Regex(@"^(?<name>.+)\((?<type>.+)\)$", RegexOptions.Compiled ||| RegexOptions.RightToLeft)
Expand Down
3 changes: 3 additions & 0 deletions src/Json/JsonRuntime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ type JsonRuntime =
let cultureInfo = TextRuntime.GetCulture cultureStr
fun json -> (JsonConversions.AsDateTimeOffset cultureInfo json).IsSome ||
(JsonConversions.AsDateTime cultureInfo json).IsSome
| InferedTypeTag.DateTimeOffset ->
let cultureInfo = TextRuntime.GetCulture cultureStr
fun json -> (JsonConversions.AsDateTimeOffset cultureInfo json).IsSome
| InferedTypeTag.TimeSpan ->
JsonConversions.AsTimeSpan (TextRuntime.GetCulture cultureStr)
>> Option.isSome
Expand Down
2 changes: 1 addition & 1 deletion src/WorldBank/WorldBankProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type public WorldBankProvider(cfg:TypeProviderConfig) as this =
let asm = System.Reflection.Assembly.GetExecutingAssembly()
let ns = "FSharp.Data"

let defaultServiceUrl = "http://api.worldbank.org"
let defaultServiceUrl = "http://api.worldbank.org/v2"
let cacheDuration = TimeSpan.FromDays 30.0
let restCache = createInternetFileCache "WorldBankSchema" cacheDuration

Expand Down
4 changes: 2 additions & 2 deletions src/WorldBank/WorldBankRuntime.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
// WorldBank type provider - runtime components
// --------------------------------------------------------------------------------------

Expand Down Expand Up @@ -184,7 +184,7 @@ module Implementation =
countryOrRegionCode
"indicators"
indicatorCode ]
[ "date", "1900:2050" ]
[ "date", "" ]
"date"
return
seq { for k, v in data do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Xml,TypeInference.xml,false,false,,false,
Xml,SampleAzureServiceManagement.xml,false,false,,true,
Xml,TimeSpans.xml,false,false,,true,
Xml,,false,false,,false,po.xsd
Xml,,false,false,,false,http://europa.eu/rapid/conf/RSS20.xsd
Xml,,false,false,,false,homonim.xsd
Xml,,false,false,,false,IncludeFromWeb.xsd
Json,WorldBank.json,false,WorldBank,,true
Expand Down
Loading