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

Feature request - ISO8601 date transformer(s) #46

Open
mfrawley opened this issue Feb 9, 2021 · 0 comments
Open

Feature request - ISO8601 date transformer(s) #46

mfrawley opened this issue Feb 9, 2021 · 0 comments

Comments

@mfrawley
Copy link

mfrawley commented Feb 9, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant