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

guidance on making datetimeoffset usable from fable python

Open joprice opened this issue 1 year ago • 2 comments

I'm interested in fixing the issues with datetime wrt Python. I see the comment in the changelog regarding issues with the implementation, but is this still valid and if so, do you have any more details where perhaps I can try to do a pr to fable to fix it?

https://github.com/thoth-org/Thoth.Json/blob/41862681e794638586b0e2f7bd366909cf741514/packages/Thoth.Json.Core/Decode.fs#L403

joprice avatar Oct 30 '24 22:10 joprice

I don't think the issue has been solved in Fable so the first thing will be to fix fable-library-py/date_offset.py in Fable.

I am just not sure, if we need to just fix the ToString("O") method or if like for DateTime we need to fix the whole type support.

In order to write, date_to_string_with_custom_format (for DateTime) I adapted the original C# code and transformed it into Python. But for DateTimeOffset we don't need to do the same because we can probably transform DateTimeOffset in a DateTime or share the logic.

If you want to learn how to work with Fable code, I did a F# Amplifying session. Or you can ping me on discord or slack, and we can hope in a call to get you started.

MangelMaxime avatar Oct 31 '24 14:10 MangelMaxime

Great I'll watch that talk. I've written a Myriad plugin that I'm using to generate 10s of thousands of lines of encoders/decoders, and hit this when I started trying to use the shared models from fable python. For now, I might just make a newtype that wraps a unix timestamp represented in json as a string and avoid the problem altogether. Eventually, of course, it would be nice to have this supported universally.

joprice avatar Oct 31 '24 17:10 joprice