4 ms·
Just use Unix time everywhere.
by cortesoft 7y ago
Just use Unix time everywhere.
- vbezhenar 7y agoI would just use ISO-8601 everywhere. I would happily use it for ordinary life! But it's not always me who builds API.
- saber6 7y agoYeah but what about relativity? ISO8601 won't scale to universe-level applications! :)
- deleted 7y ago[deleted]
- stickfigure 7y agoPresumably you mean unix time as a numeric scalar in the JSON. That is still not self-describing - is it time, or just a number? Which scalar data type should your parser use? And is it seconds since epoch or milliseconds since epoch?
- cortesoft 7y agoIt should be maintained as a numeric scalar until you are going to do something with the value... and if you are going to do something with the value, you should know if it is a date or not. JSON isn't meant to be self-describing format. There is JSON schema or the like if that is what you are after.
- stickfigure 7y agoJSON isn't meant to be self-describing format. And yet to a very large extent, it is. Strings, numbers, booleans, arrays, and associative maps made the cut. Timestamps would be a pretty reasonable addition. It would certainly cut out all the controversy here.
- yellowapple 7y ago> is it time, or just a number? Yes :) That's the beauty of it: time is just a number (of seconds since 1 January 1970). > Which scalar data type should your parser use? Integer, since it's an integer number of seconds. > And is it seconds since epoch or milliseconds since epoch? Unix time is always seconds.
- dragonwriter 7y ago> > That is still not self-describing - is it time, or just a number? > That's the beauty of it: time is just a number (of seconds since 1 January 1970). Having a bare number where the units and zero point rely on out-of-band information is not self-describing.
- yellowapple 7y agoJSON has never been self-describing. Literally every use of JSON is fundamentally dependent upon some degree of out-of-band information. If you want something self-describing, maybe look into XML?
- nitrogen 7y agoUnix time is always seconds. Wasn't there a BSD that used double instead of long for time_t for a while ages ago?
- stickfigure 7y ago> Unix time is always seconds. Javascript time (that 'JS' in JSON) is always milliseconds.
- eyelidlessness 7y ago> Unix time is always seconds. Then it is a complete non-starter for "just use ______". I work on software that requires millisecond precision (honestly it would benefit from even greater precision) at the transport layer. It's not even really doing anything spectacularly complex or unusual. Seconds simply aren't sufficient for tons and tons of use cases.
- 7y ago
- doubleunplussed 7y agoUnix time still has issues. It officially pauses for a second when leap seconds happen. You can't actually calculate a delta in seconds between two unix timestamps without a database of when the leap seconds were.
- zerocrates 7y agoOn calculating a delta, isn't there the exact same problem with UTC timestamps? Unless one of the ends of your delta is the exact 23:59:60 moment, there's no way to account for possible leap seconds in the middle of your range without just having a list of them.
- doubleunplussed 7y agoTotally! Just pointing out that unix timestamps don't solve everything (even before getting to relativity). International Atomic Time (TAI), which differs by UTC by 37 seconds since it doesn't count leap seconds, solves everything I know of. Although the clocks aren't in a single reference frame, the procedure for measuring their differences and averaging them to define TAI is well defined and so sets an objective standard for "what time is it on Earth".
- reciprocornous 7y agoThat'll cause problems in ~3e45 years.