4 ms·
Maybe I’m stating the obvious here, but there is actually a standard: ISO 8601. Vendors however don’t seem to follow this, either consistently or at all. As for
by temporallobe 6y ago
Maybe I’m stating the obvious here, but there is actually a standard: ISO 8601. Vendors however don’t seem to follow this, either consistently or at all. As for a standard library, Javascript doesn’t have one - everything is built into the core language. Also, fundamental differences between language syntaxes could have a huge impact on usage and implementation. So even if every existing and future language on the planet followed ISO 8601, there would always be that language barrier.
- sratner 6y agoISO8601 is a representation standard, not a standard for abstract concepts. https://news.ycombinator.com/item?id=23783603 https://news.ycombinator.com/item?id=23783603 called for Unicode but for Time, which I think is perfect. In that framing, ISO8601 is UTF-8, but it is Unicode that is needed for everyone to agree on what is "code point" and what is a "character" (equivalently, what is a "calendar date", what is an "absolute timestamp", etc).
- tzs 6y agoI don't expect that the usage and implementation would be the same in all languages. Just that they would at a high level have the same representations and provide the same operations. For example, if the standard was that a datetime would be represented as separate year, month, day, hour, minute, second, time zone some languages might implement that as a struct with names fields for each of those 7 elements. Some languages might implement it as an object with properties for each of those elements. Some might implement it as an array with one entry for each of those elements. If the standard called for a function add_seconds that adds a given number of seconds to a datetime, modifying that datetime in place, languages that use a datetime struct might provide a standalone function that takes a pointer to a datetime struct and the number of seconds to add. Languages that represent datetime as an object might have add_seconds as a member function. So if I'm a Perl programmer and know how this standard works in Perl that would not necessarily mean it is obvious to me how it works in Python or C. But it would mean I could think about time the same way in all of them. I could expect to have corresponding data structures in all of them, with the same core set of operations available in all of them. Names might be slightly different (e.g., what the standard calls add_seconds might become addSeconds in a language that by convention uses camel case for member function names), but the point is what these functions and data structures actually do would be standardized so once I know how to do all my date and time stuff following this standard it is easy to map that to the language specific implementations in JavaScript, Java, PHP, C, and the rest.