Implement timedeltas for to_json

Closes #9027
see my implementation below