It seems like the main popular libraries for handling dates/times in OCaml are Calendar and Ptime, but having experimented with them, they don’t handle parsing/printing out UTC timestamps RFC5322 formatted times.
I was able to find a parser for UTC timestamps RFC5322 formatted times that I can vendor from the OCaml-webmachine repository, but not yet sure how to print them at the moment:
Does there exist an out-of-the-box library for this case?
If not, how can I pretty print UTC timestamps RFC5322 formatted times using Ptime or Calendar?
Thanks for the pointers to the functions -barring no out-of-the-box library, I did plan to pretty print them myself, so these references will likely cut down the time I spend on implementation.
I really don’t suppose it would be too difficult to print out the timestamps myself, it’s just that it would require reading and implementing the RFC, and then worrying about if I had handled all the edge cases myself, hence I was asking whether there was any existing library/prior project that had ran into this issue already.
Sorry to nitpick on your response - I wasn’t trying to pick on Ptime in particular or trying to make the claim that it should support conversions to this format, my reason for referencing Ptime was simply because it seemed to be a popular choice for encoding times in OCaml (hence why I also pointed to calendar).
From searching online, it seems many other programming languages have conversion functions to this format as part of their ecosystem, so I wanted to double check whether others had run into this problem before, because it could be very likely that there is some implementation of this function hiding in some existing OCaml codebase somewhere that I may have missed.
I’m parsing/consuming the output of external servers, so I’m hesitant to change the date format in case other things fail.
Okay, reading the MDN page I linked to, if the documentation is accurate, then I suppose it won’t be too much hassle to write my own printer, and I can just leech of the work of the OCaml-webmachine people (thx) for the parser.
I still don’t know what a “UTC timestamp” really is, but you might want to also consider timedesc, part of timere. It parses and prints ISO 8601, supports time zones, includes other representations such as Date and ISO_week, and can be extended with timere to add powerful functionality for reasoning about time.