10 ms·
I'd like to see the JavaScript people, the Java people, the PHP people, the Perl people, the Python people, the C people, the C++ people, and the people for eve
by tzs 6y ago
I'd like to see the JavaScript people, the Java people, the PHP people, the Perl people, the Python people, the C people, the C++ people, and the people for every other significant language that supports functions (either directly or as methods on objects) to get together and once and for all agree on how the heck we are supposed to deal with times and dates.
Then all of them should implement that in their standard library, so that going forward we've got one sane conceptual time handling system everywhere.
I tire of dealing with the quirks of everyone having their own approach.
- G4BB3R 6y agoCommunity driven libraries APIs are a mess, look at React Native or Js in general. I'd rather a (group of) specialist to develop the API.
- tzs 6y agoSorry for not being clearer. By "JavaScript people", "Java People", etc., I didn't mean the communities. I meant the people who make the standards for those languages.
- mattwad 6y agoIt's not just that. Timezones are the real bugger. Microsoft has their own list of names separate from the standard IANA timezones, for example. If it weren't for timezones, IMO dates are pretty damn trivial. It's just a matter of storing and transferring them properly (in UTC, always!)
- frenchyatwork 6y agoTimestamps are damn trivial. When people use dates, that's all they want 90% of the time. The remaining 10% is where all the hard problems are. For example, lets say I have a store that opens from 8:00-17:00 every day, and it's currently 22:00. How long is it till it opens next?
- noja 6y agoThree days and an hour more than you think, because it's the weekend, and an extra day because the public holiday for tomorrow may or not be a working day. Oh and there was a timezone change.
- bonedangle 6y agoAnd it's December 31st.. Still shocked by how many times I see a year rollover go bad.
- unilynx 6y agoEven before the rollover it get's bad. I had a CI failure on 31 December 2018 for code which worked fine on 31 December 2017, because it was the first time for that code to have Dec 31 in week 1 of the next year. And last year someone else's code failed on 30 December 2019, so I had a pretty good idea where to look. Still need to fix a bug in code written only yesteryear because the 1st of July wasn't on a Monday this year, but I decided to snooze that test failure ... it'll work fine again in 9 years.
- aarong11 6y agoThere was a leap second too, you forgot that one!
- timgilbert 6y ago...oh, and I hope you know whether your customer is Israeli or Palestinian! https://www.972mag.com/the-worlds-only-ethnic-time-zone/ https://www.972mag.com/the-worlds-only-ethnic-time-zone/
- reggieband 6y agoPeople joke, but I worked on a calendar application (well, it was a time series graph) where a leap second caused a rendering bug.
- 6y ago
- 1-more 6y agoThere is a case to not store a time in UTC: you schedule a meeting in the future and the local authorities change when they start DST in that location. Now your user gets the alert an hour too early or late for their meeting. The scenario is more fleshed out in the link below but I don't want to just copy and paste the article into the comment. http://www.creativedeletion.com/2015/03/19/persisting_future_datetimes.html http://www.creativedeletion.com/2015/03/19/persisting_future...
- deathanatos 6y ago> in UTC, always! … which the proposal doesn't use. (It uses POSIX.)
- tigershark 6y agoNo they are absolutely not. Ask Jon Skeet for example: https://codeblog.jonskeet.uk/2010/12/01/the-joys-of-date-time-arithmetic/amp/ https://codeblog.jonskeet.uk/2010/12/01/the-joys-of-date-tim... https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a-silver-bullet/amp/ https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a... Or look at the usual falsehood list: https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b... Some interesting ones: A week (or a month) always begins and ends in the same year. Months have either 28, 29, 30, or 31 days. There is a leap year every year divisible by 4. The day before Saturday is always Friday.
- hart_russell 6y agoI have worked on a DoD program that dealt with time precision. It is not a trivial task let me assure you.
- lmkg 6y agoBasically we need Unicode But For Time. These are similar problems: getting a computer-amenable model of something that's fundamentally a human phenomenon, and carries multiple centuries and multiple continents of accumulated context, ambiguity, and edge-cases. This is an extremely difficult class of problems, but in the case of text & characters, we managed to finally get a pretty well-functioning and broadly-supported solution after a few decades of gratuitously-incompatible half-solutions. There's hope.
- WorldMaker 6y agoAlmost everything should be capable of parsing and outputting ISO 8601 dates [1] today. About the biggest recommendation that still seems to lacking in documentation is that you should probably consider offsets (Z or -0500 etc) required rather than "optional", and that you have to remember that offsets are not timezones (and that generally you should store offsets as presented rather than convert between offsets; makes it easier to adjust offsets based on timezones). [1] https://en.wikipedia.org/wiki/ISO_8601 https://en.wikipedia.org/wiki/ISO_8601
- riquito 6y agoNot every point in time refers to a timezone. If I write that 1 january 1970 was an eventful date, I can't/dont want to add a timezone to it. Then you may want to store/format times without dates, etc...
- sratner 6y ago> consider offsets (Z or -0500 etc) required rather than "optional" ISO8601 without an offset is semantically different to one with an offset, it represents a time in local timezone (context-dependent). It isn't an "optional" offset in the sense that you can just omit it, it is a fundamentally different data type. Without this distinction, there is no way to specify a local time in ISO8601, which would be highly inconvenient for certain applications. For example, how do you represent an event that occurs at 9am every day regardless of location? After all, dates and times are used for more than just storing absolute timestamps. You are absolutely correct that offsets are also not timezones, which makes the ability to specify local "floating" times even more important (i.e. you can't just denormalize the above concept into a list of timestamps with offsets for each timezone you care about, as the offsets will change over time [edit: and tz->offset conversion is lossy and not reversible]).
- pjmlp 6y agoThey are yet to agree how to deal with strings, how do you expect them to agree with time and dates?
- hyperpape 6y agoI'm not sure strings are easier. When to use mutable vs. immutable strings has a significant performance impact, how do you manage memory for them (including when do you copy strings vs work with a slice) are all questions where there's at least 3-4 distinct designs that you might want (a C like language, a C++-like language, a Rust-like language, and a GC'd language). In contrast, for dates and times, everyone really could have used the same design. Maybe you'd need a slightly different design for dynamic languages, but I'm not even sure about that.
- ProZsolt 6y agoTom Scott has a great video about time and timezones on Computerphile: https://youtu.be/-5wpm-gesOY https://youtu.be/-5wpm-gesOY
- cactus2093 6y agoI don't think it's actually that important that every language deals with them the exact same way. I interpret that to mean they all translate the APIs as literally as possible between them, using the same method names, same types of arguments, etc. Different languages all have their own quirks and patterns and it's also useful that the library be idiomatic within the language. Most of the problems I have seen in dealing with time, across various languages, arise from allowing types to be way too ambiguous. A lot of code uses interchangeably things like "UTC -0700" and "America/Los_Angeles" which are actually very different (one incorporates daylight savings and one doesn't). The important fix is that languages start using reasonable abstractions and are stricter about requiring explicit conversions between types rather than trying to implicitly guess an interpretation. The first library I've seen get this right was Joda in Java, and it later got included into the standard library for Java. It's been copied other languages, and I've used it on the frontend a bit as JSJoda, but the literal translation makes it a bit awkward in JS and I found it was hard to get other JS developers to prefer it over the more popular moment or date-fns. Temporal looks great, it actually seems to borrow heavily from Joda but doesn't literally copy all of the names or methods so hopefully it will be the best of both worlds.
- temporallobe 6y agoMaybe 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.
- russellbeattie 6y agoYour proposal might seem crazy, but we've actually been able to do this before. While learning WebXR not long ago and looking for examples, I discovered it was based on OpenXR (1) and literally every big tech company has APIs that were similar - I ended up reading docs and sample code from Android, C#, and even Apple to get a better idea of how things were wired together. It was a very pleasant surprise!! 1) https://en.m.wikipedia.org/wiki/OpenXR https://en.m.wikipedia.org/wiki/OpenXR
- niftich 6y agoThis basically exists, and it's called ISO 8601. But the scope of ISO 8601 isn't programming languages and APIs, but data models and their representations. A subset of ISO 8601 forms the basis of RFC 3339. Official copies of ISO 8601 are available for a fee from ISO. For the purposes of this discussion thread, consult this file hosted by the US Library of Congress for reference [1]. ISO 8601 defines a number of terms of art to represent a thorough mental model of the problem space, and then goes on to define string representations on how to express them. But it's paywalled, so people reach for RFC 3339 and the Wikipedia article instead. These focus on representations, and the definition of the concepts isn't captured clearly, so sometimes they're rediscovered independently. Other times, they're not. Serious attempts to figure this out usually coalesce to something that looks and behaves like Java 8 time. Java 8 time may be verbose, but its concepts are clearly mapped out, and the API bears some marks of a misuse-resistant design. Compared to that, there's efforts like the standard libs for Python, Ruby, Go, or most third-party libs for JS, Rust, that don't bring clarity to the table, and don't present any solution for dealing with calendrical or clock-face objects, and do little to discourage misuse of their point-in-time objects in abstract contexts. This proposal falls much, much closer to the Java 8 way than to the "everything is an instant, go make your own classes" way. One shortcoming of ISO 8601 is that it has no provisions for abstract timezones. Instead, people go outside of the standard to represent ISO datetimes alongside IANA timezones. But the most glaring problem with ISO 8601 is that it doesn't define partials where a more-significant term is unknown or missing: there's no valid, unambiguous way to refer to the 15th day of March, while leaving the year deliberately unspecified. This means that anniversary dates (e.g birthdays, holidays) aren't possible to represent in the abstract. Likewise, there's no valid, unambiguous way to refer to the 29th second of the fourth minute of every hour. This is much less important than the birthday shortcoming. The Library of Congress has a standard which extends ISO 8601 with a number of useful constructs for their purposes [2], like uncertainty qualifiers, but even that standard has no mechanism to represent a month+day partial in the abstract. [1] https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_iso_wd_8601-1_2016-02-16.pdf https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_i... [2] https://www.loc.gov/standards/datetime/ https://www.loc.gov/standards/datetime/
- simon04 6y ago
- mrlala 6y agoI can't speak for every language you listed, but C# has great and clear datetime builtin. Probably the only thing perhaps not the most standard are the names they use for actual time zones? So perhaps that could be improved. But seriously I don't know how the fuck javascript people can work with dates. It's ATROCIOUS. I think my favorite one is 0 indexes on months? like if you do date(2020,07,09).. is that July 9th 2020? nope, fucking June! Not June 8th.. but June 9th. I don't know what monster did that but there should be a special place in coding hell for him/her!
- dmurray 6y agoHow does that work? Do you really mean it's August 9?
- tzs 6y agoI believe that the logic behind 0 based months in many languages that use them, although I don’t know if this is true for JavaScript, is that month numbers are often used as an index into a table of month names so numbering months from 0 is convenient.
- mrlala 6y agoWell sure, I get the reason behind.. but the reality is it's just a horrible convention, especially when you pass multiple inputs (year, month, day, hour, minute, second) and "month" is based on 0 index but the rest are not.
- galvin 6y agoRegarding JavaScript, either you avoid manipulating dates and just pass them to the server in ISO format, or you use a library like Moment.js. The native API's are a disaster and using them is just asking for trouble!
- balfirevic 6y ago> I can't speak for every language you listed, but C# has great and clear datetime builtin. If you think built-in .NET DateTime is any good, give NodaTime a try. Standard DateTime is barely usable, compared to it. For JavaScript, there is excellent js-joda library (same design as NodaTime and Joda-Time), but it's 43 kB minified and compressed, which is... not terrible but also not great, really depends on your use case if it's worth it.
- duxup 6y agoYeah I don't care what the solution is.... if everyone just does it, that would be great. Then I'll care / complain about the solution ;)
- ryzokuken 6y agoTemporal does in fact conform to standards like ISO 8601 for serialization/parsing etc.
- ralmidani 6y agoI agree in principle, but achieving that kind of harmony between languages is analogous to the world‘s governments agreeing to “save succeeding generations from the scourge of war”. That sounds like an exaggeration, but even if language maintainers are all enlightened enough to compromise, the communities are not necessarily going to comply. The minute a language changes how it deals with dates and times, it’s more than likely someone will, very loudly, announce their intent to fork it in order to preserve the old way of doing things.
- beached_whale 6y agoThe C++ model is very nice to work with. C++20 will be even better as Howard Hinnant's Date library has been incorporated.
- smichel17 6y agoLater: https://xkcd.com/927/ https://xkcd.com/927/
- faitswulff 6y agoRandom question, but how does time work if your box is on, say, Mars?
- techdragon 6y agoThere’s a history of using local Martian solar time in the past, driven by the need to operate in the Martian daytime for rover safety. They even made special watches that ran “slow” compared to earth times so that they kept correct Martian solar time for some of the missions. However for “absolute” chronological records you would be looking at using Barycentric Coordinate Time, which is what we get when we do a bunch of corrections to subtract the effects of the sun and earth’s (and the other planets) mass and motion, leaving us with a virtual “clock” that is suitably common for anything in the solar system. To quote one definition of Barycentric Coordinate Time - ”It is equivalent to the proper time experienced by a clock at rest in a coordinate frame co-moving with the barycentre of the Solar System: that is, a clock that performs exactly the same movements as the Solar system but is outside the system’s gravity well.” The ELI5 I normally use is roughly: It’s what we get if we take the Solar System in its normal orbit around the Milky Way, with some fancy magic we subtract away all the stuff, sun, planets, moons and all the asteroids and comets we can count, and then with a little more fancy magic, we put a super accurate clock that doesn’t weigh anything at all back at the center of where all the solar system stuff used to be.”
- lucaspiller 6y agoIn reality: Even if in a few hundred years we have the capability to travel at FTL to other solar systems, we will still be using GMT as "ship's time".
- Balgair 6y agoTwo fun asides: 1) Latitude on another planet is straightforward: take the rotational equator, divide into 90 degrees north and south, done. But what about Longitude? Here on Earth, the prime meridian is Greenwich, because reasons. On Mars, it's indexed to a certain crater. But on the gas giants? Yeah, we still don't have a good plan about that. 2) Paul Krugman's thesis (yes, that Paul Krugman) is on relativistic economies. As in, my planet is in a deep gravity well, your's isn't. My clocks pas a lot slower. Now, how do I calculate interest? What about letters of credit for ships traveling between places to ship goods? His conclusion: let's hope there isn't money by then, because interest can't work between relativistic time frames.
- lowwave 6y agoTechnically, Javascript is a standard. By Ecma International: https://www.ecma-international.org https://www.ecma-international.org
- d0mine 6y agoThere is no approach that works for all use-cases when you are dealing with time (there are only various trade-offs). There is the tz database that is correct for many use cases. It should be available in all languages that you listed https://en.wikipedia.org/wiki/Tz_database https://en.wikipedia.org/wiki/Tz_database
- nerf0 6y agoSo much this. Not to mention that even within the same language, the implementation can differ (e.g. Firefox vs Chrome). I recently had to parse a bunch of dates in python, writing them to postgres, and then handle the same dates in javascript. And boy was it a PITA. The worst problem was the handling of "BC" dates. I had to hack my way around the boundary between python and sql. Javascript is no better, it simply doesn't compute BC dates without heavy hackery.