News for hackers. Stuff that matters.
Re:How to Design Better APIs by drdrey on Friday March 11, 2022 @08:18PM (#30648078)
Why would one prefer ISO 8601 dates over POSIX timestamps?
Re:How to Design Better APIs by inopinatus on Friday March 11, 2022 @08:55PM (#30648269)
* Human readable

* Supports birthdays for people older than 52

* Reliable after 2038

* Supports leap seconds

* HTML date/time spec is a subset

* String collation order matches temporal order

* Excel

Re:How to Design Better APIs by latch on Saturday March 12, 2022 @03:25AM (#30649913)
> * Human readable

Computers are the main consumers of APIs, and ISO 8601 is far from machine-readable.

For example, in Elixir, DateTime.from_iso8601/1 won't recognize "2022-03-12T07:36:08" even though it's valid. I had to rewrite a chunk of Python's radidjson wrapper to 1-9 digit fractional seconds (1).

I'm willing to bet 99% of ISO8601 will fail to handle all aspects of the spec. So when you say "ISO8601" what you're really saying is "our [probably undocumented, and possibly different depending on what system you're hitting] version of the ISO-86001 spec."

(1) https://github.com/python-rapidjson/python-rapidjson/pull/13...

Re:How to Design Better APIs by inopinatus on Saturday March 12, 2022 @02:51PM (#30654326)
> what you're really saying

No.

The specific profile of ISO8601 that should be used to express timestamps in an API is that defined in RFC3339.

Choosing to use a half-baked parser is a separate matter.

Re:How to Design Better APIs by djbusby on Friday March 11, 2022 @08:53PM (#30648261)
8601 has a large pattern space - RFC 3339 is a narrower subset of ISO. Somewhere I saw a diagram that convinced me. I link if I can find again.

Edit: a relevant link

https://news.ycombinator.com/item?id=28976526

Re:How to Design Better APIs by worik on Saturday March 12, 2022 @02:11AM (#30649577)
Re:How to Design Better APIs by djbusby on Saturday March 12, 2022 @10:57AM (#30652217)
That's the one! Thanks!
Re:How to Design Better APIs by hn_throwaway_99 on Friday March 11, 2022 @08:32PM (#30648151)
1. Human readability

2. The ISO date format is "big endian" by default, which makes it trivial to chunk and compare just specific date parts. Want all events that occurred on the same (UTC) date? Just do dateField.substring(0, 10). Everything in the same year? dateField.substring(0, 4).

Re:How to Design Better APIs by mulmboy on Friday March 11, 2022 @08:28PM (#30648134)
They can include a local timezone. Sometimes there's a big difference between 12am in UTC+0 and 3am in UTC+3 despite representing the same instant in time.
Re:How to Design Better APIs by inopinatus on Friday March 11, 2022 @09:03PM (#30648299)
True enough, but I would still recommend that API responses normalize to UTC (Z suffix) in the general case and document as much, and if actually returning a timestamp with a specific timezone, document the intended meaning.
Re:How to Design Better APIs by guhidalg on Friday March 11, 2022 @09:39PM (#30648503)
+1, if your application cares about time then you should just tell your users all dates will be normalized to UTC and they are responsible for displaying them in a preferred time zone.
Re:How to Design Better APIs by codebje on Friday March 11, 2022 @10:52PM (#30648850)
Time zone rules change relatively frequently - future dates may be better stored in the appropriate time zone, optionally along with the UTC offset at the time of recording, so you don't report incorrect information when the rules do change on you.

Past dates should always be in UTC, for the same reason - timezone rule changes are sometimes even retroactive.

Re:How to Design Better APIs by seelmobile on Friday March 11, 2022 @08:47PM (#30648232)
I prefer them because they're human readable and can preserve time zones if that's important
Re:How to Design Better APIs by paulryanrogers on Friday March 11, 2022 @08:26PM (#30648126)
Human readability most likely