Handle serialization/deserialization of date, time and datetime instances#35
Conversation
…nces Serialize also date and time objects, and implement the complementary operation recognizing strings containing such values. A new option, “DATETIME_MODE_ISO8601_UTC”, shifts the values to UTC. This is basically an extended version of the datetime support implemented in https://github.com/lelit/nssjson.
|
Wow, thanks! Does this noticeably affect performance? I think it's okay if it does, but would be nice to note. |
|
I didn't really measure it, but it should not have much impact: the test to recognize the various formats is very light and the actual parse happens only on positive checks. It is surely much much faster than any alternative way, where the check and the conversion is done at the Python level. |
|
I added a specific benchmark: tests/test_benchmark.py::test_datetime_performance |
|
To fit my needs, I also implemented an equivalent support for UUIDs. Lemme know if you'd appreciate a PR for that too! |
Check also the range of the single values, following the rules implemented in the Python higher level of the datetime module.
|
These are the results of another benchmark, that measures the overhead of the datetime_mode I think I'm done for now, but I'm of course willing to do whatever tweak or further test you |
|
@lelit not a maintainer here (or even a contributor), but if these folks want to accept UUIDs PR, I'd appreciate it! :) |
|
Yup, me too! @kenrobbins, any chance for you to make it clear if/when this could be accepted? |
|
@kenrobbins Ping! |
|
@lelit I think my only complaint about this PR is the lack of documentation. Could you update the |
|
Yes, I can easily do that. But, given that the |
|
sorry for the delay. i have returned. thanks very much. uuids are fine with me if you want to submit that pr. |
|
Great, thank you! I'll probably rebase that branch on top of your current master and propose a PR. |
Serialize also date and time objects, and implement the complementary
operation recognizing strings containing such values.
A new option, “DATETIME_MODE_ISO8601_UTC”, shifts the values to UTC.
This is basically an extended version of the datetime support
implemented in https://github.com/lelit/nssjson.