FSharp.Json icon indicating copy to clipboard operation
FSharp.Json copied to clipboard

Feature request - ISO8601 date transformer(s)

Open mfrawley opened this issue 4 years ago • 0 comments

Hey, I needed this for interop with another language (scala), there are possibly other betters ways to achieve this, but as every language implements ISO8601 (de-)serialization to/from JSON differently it would be nice to have a couple of the more popular string formats of the standard ready to help people whose goal is interop with other languages/libs. I did something like this but hardcoded the 'Z' as it is commonly used/expected as a shortcut for the 0 UTC offset, but it could be made more generic.

    type ISO8601UTCDate() =
        interface ITypeTransform with
            member x.targetType () = (fun _ -> typeof<string>) ()
            member x.toTargetType value = (fun (v: obj) -> (v :?> DateTime).ToString("yyyy-MM-ddTHH:mm:ssZ") :> obj) value
            member x.fromTargetType value = (fun (v: obj) -> DateTime.Parse(v :?> string) :> obj) value

mfrawley avatar Feb 09 '21 14:02 mfrawley