Implement timedeltas for to_json

Closes #9027
i can't really use that in a C library, it has to be in a header. i guess i'll move it