2 ms·
From the document: > The following timestamp encoded as a JSON string requires 26 bytes > ... > This timestamp requires just 11 bytes when encoded in Ion bin
by bob1029 6y ago
From the document:
> The following timestamp encoded as a JSON string requires 26 bytes
> ...
> This timestamp requires just 11 bytes when encoded in Ion binary
So, we just use JSON, and our solution to this problem has been to pass 64 bit unix timestamps around. It doesn't provide arbitrary precision, but for most use cases it is more than enough practical range & precision to get the job done. And of course we store & transmit everything as UTC, so there is no weirdness around needing to store additional timezone information. To give you an idea, our database columns are named things like CreatedUnixTimestamp.
It is also trivial to compare 64-bit timestamps without conversion, so any SQL storage of these as integers should yield massive speedups to queries against these types - Assuming you are coming from some more complex datatype like a string or byte array.
- rumanator 6y ago> So, we just use JSON, and our solution to this problem has been to pass 64 bit unix timestamps around. Passing an integer does not have the same semantics as passing a timestamp. Relying on out-of-band info to parse a document is a problem in the making. > but for most use cases it is more than enough practical range & precision to get the job done. Parsing s-expressions would also get the job done, even if it's a primitive s-expression that only supports cons cells and a string data type. However, people find value in enabling the parser to validate booleans, arrays, and objects. ION is just a logical next step. Timestamps are quite naturally a fundamental data type in comm between web services, particularly in binary form.
- xyzzy_plugh 6y agoPass 64-bit Unix timestamps around as JSON numbers? That's a bad idea, seeing as they're 64-bit floats. You're better off formatting your 64-bit integers as strings.
- bob1029 6y ago53 bits of usable range is plenty for our purposes. Our serializer & database are not hobbled by the limitations of javascript, so the representation is only compromised as it is processed at the end client. This is not a concern for us. For reference, MAX_SAFE_INTEGER can represent something around the year 285428751.
- monadic2 6y agoI'm rather attached to things like time zones.
- bob1029 6y agoYou can have whatever timezone you want if you store/transmit things as UTC. The final client device javascript should be the point at which the conversion to local time occurs, because the browser is best aware of the correct timezone. Everything on the server is just done in terms of UTC. I actually cannot think of a reason I would want to process a timestamp in terms of local time on the server.
- monadic2 6y agoWell, one example is a notification that fires on the client’s timezone rather than UTC.