How to represent datatypes? For example in a JSON output.
Don’t do things like:
Seriously. Do you have any idea how difficult and computationally intensive this is to parse? And I’m not even talking about the variants with timezones like GMT, PST, Z, +- offsets and so on.
Instead, do the following:
This is the number of milliseconds since the beginning of times, that is 1st January 1970 with an UTC time zone. It’s easy to parse and there’s no room for interpretation. Every library understands that format.
This uses floats. Not only it can give rounding errors but it’s slower than integers. Instead do:
which is the number of milliseconds. Again easy to parse and every timer related library understands integer milliseconds, not necessarily floats.
Keep it simple and efficient.
Author: David Gerber
CEO of Zapek Software Engineering