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

cl-json:encode-json of local-time not useful #38

Open
erjoalgo opened this issue May 19, 2024 · 3 comments
Open

cl-json:encode-json of local-time not useful #38

erjoalgo opened this issue May 19, 2024 · 3 comments

Comments

@erjoalgo
Copy link

(cl-json:encode-json (local-time:now))
{"day":8845,"sec":63958,"nsec":58418000}

This encoding a Lisp timestamp is rarely useful outside of CL. Encoding as a unix timestamp would be more useful:

(defmethod cl-json:encode-json ((tstamp LOCAL-TIME:TIMESTAMP) &optional (stream t))
  "Encode timestamps as unix timestamps in json."
  (format stream "~A" (local-time:timestamp-to-unix tstamp)))
@rpgoldman
Copy link
Contributor

I just searched the GitHub repo for the string "local-time" and found nothing except this issue. So there's no code in cl-json specifically for handling local-time timestamps. So why is this a CL-JSON issue?

@erjoalgo
Copy link
Author

It's not necessarily a CL-JSON issue, nor is it necessarily a local-time issue. Since it's no one's issue, then becomes an issue for users of CL-JSON that happen to be encoding local-time objects. My opinion is that CL-JSON would be more generally useful if it could gracefully handle types that users may commonly encounter, like timestamps, out-of-the-box. But that's just my opinion.

@rpgoldman
Copy link
Contributor

OK, I could imagine that this would be the job of an additional library, we'd call it "cl-json/local-time", that would depend on both "cl-json" and "local-time" (or, one could also imaging a library "local-time/cl-json" that would be an add-on to local-time instead of cl-json), and that would have additional methods for serialization and deserialization, but I don't see an easy way to add a bunch of special purpose data structures to cl-json itself. Unless there's some way to get libraries to present things like timestamps, that are part of the JSON spec. Then it would just be a matter of making local-time spit out Unix timestamps, instead of working with its own data structures.

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

2 participants