News for hackers. Stuff that matters.
Re:Text Editing Hates You Too by dvt on Tuesday October 29, 2019 @12:55AM (#21384337)
This post reminds me of one of Jon Skeet's seminal SO answers[1] on subtracting dates. Things we take for granted are hard. Dates are hard, text is hard, graphics are even harder. We stand on the shoulders of giants. It's important to stop and smell the roses every now and then.

[1] https://stackoverflow.com/questions/6841333/why-is-subtracti...

Re:Text Editing Hates You Too by gambler on Tuesday October 29, 2019 @12:37PM (#21389098)
> Things we take for granted are hard. Dates are hard, text is hard, graphics are even harder. We stand on the shoulders of giants.

More like we stand on piles of broken shit. A lot of "hard" things in programming have very little fundamental complexity. They are hard because at some point in time someone made a compromise that no longer is relevant or makes any sense. It is possible to redesign those things to be simple, but modern developers are conditioned to fight this at every step. The idea that the first thing you should try to do when faced with extraordinary complexity is to bypass it is completely alien to people whose daily jobs consist of continuously banging their heads against convoluted frameworks and deficient APIs.

Time handling is a great example. Until you get into general relativity, time itself is extremely simple and uniform. But human representations of time are extremely convoluted, because historically they are based on astronomy. Here is the kicker: 99.99% of all software has nothing to do with astronomy, and yet people chose to inject those complexities in core structures that track time. (For example, Unix timestamps have leap seconds, which is a source of innumerable bugs and ridiculous convolutions in code to prevent those bugs.)

Re:Text Editing Hates You Too by rovolo on Tuesday October 29, 2019 @07:22PM (#21393153)
If by 'based on astronomy' you mean 'based on the sun' because the sun is a star, then I agree. But, plenty of software has lots to do with the sun because they have to interact with people, and people like to be synchronized with the sun.

If you don't want software to interact with humans, or you only care about duration rather than human datetime, then go ahead and use UT1. However, as long as your interacting with people, you're going to need to fix people first. You should start with these primers if you're going to fix how humans interact with time:

- https://qntm.org/abolish - https://qntm.org/continuous

Re:Text Editing Hates You Too by stnmtn on Tuesday October 29, 2019 @01:32PM (#21389798)
Are you arguing for trying to create a new method of tracking time instead of just including moment.js?
Re:Text Editing Hates You Too by hrktb on Tuesday October 29, 2019 @01:45PM (#21389961)
I read parent’s comment as a plea to be simple where it’s allowed.

For instance use straight timestamps where there is no need for calendar manipulations.

I am sympathic to this argument and I’d also totally join a movement to ignore DST or uncouple years from earth rotation

Re:Text Editing Hates You Too by m45t3r on Thursday October 31, 2019 @08:27AM (#21407952)
This post sounds kinda like a satire: "we have problem X, did you try something.js to fix it?"
Re:Text Editing Hates You Too by jblwps on Wednesday October 30, 2019 @12:05PM (#21399185)
> Until you get into general relativity, time itself is extremely simple and uniform.

Just a little niggle, but I think you meant to say special relativity; special relativity is about the relationship between space and time, whereas general relativity (I believe) is more about gravitation and other things that I definitely don't understand.

Re:Text Editing Hates You Too by AmericanChopper on Tuesday October 29, 2019 @01:07AM (#21384377)
I remember trying to debug this exact “issue” in a java project years ago. I poked around the library to figure out what was going on, which only raised more questions, before I eventually stumbled upon that exact SO thread. Turns out dates have an enormous amount of complexity.
Re:Text Editing Hates You Too by Joeri on Tuesday October 29, 2019 @09:28AM (#21386847)
Date and time are complex because they are social and historical constructs. Everything about them is arbitrary and exists because of arcane historical reasons. No regular system of organizing time maps cleanly onto the movement of heavenly bodies because those movements are not regular (hence: leap seconds). You can describe time in a way that is precise, or in a way that is intuitive, but not both, and woe to anyone trying to convert between the representations.

Time zones are the worst because they are political tools, changed for political reasons, often with very little lead time. I think of them as a one way function mapping universal time onto the local political reality.

Re:Text Editing Hates You Too by ggm on Tuesday October 29, 2019 @01:11AM (#21384389)
I know its not the answer, but I always convert time into time in seconds since the epoch and perform the arithmetic.

epoch time understands negative numbers:

% date -ur -28501440617 Mon Oct 29 05:09:43 UTC 1066 %

Re:Text Editing Hates You Too by eesmith on Tuesday October 29, 2019 @03:00AM (#21384770)
It's easy for me to write something in Russian, I just hire a Russian translator for me.

That is, "convert time into time in seconds since the epoch" is the hard part. All you've done is make it someone else's problem, while the question Skeet answered asked specifically about the time difference between 1927-12-31 23:54:08 and 1927-12-31 23:54:09 in Singapore.

Re:Text Editing Hates You Too by ggm on Tuesday October 29, 2019 @03:14AM (#21384813)
Yes. This is beautifully expressed. And 'hiring a russian interpreter' is almost always the right way to fix this kind of problem. POSIX would seem to me to be the russian interpreter of choice here. Is java a language which has no word for the colour green? in the sense where the eponymous russian interpreter has to say: "concept which cannot adequately be expressed in russian" or something

The POSIX spec exists for this reason. This feels like a variation of "omg utf-8 is hard" which is why people embed utf handling in the language python2 -> python3

Re:Text Editing Hates You Too by eesmith on Tuesday October 29, 2019 @03:44AM (#21384917)
It seems less than graceful to respond to articles which point out the existence and difficulty of problems by saying it's fixed. The entire point is to show how it's more difficult than many think, not elide the issues.

What does POSIX have to do with anything? Eg, the tz database isn't POSIX.

Re:Text Editing Hates You Too by ggm on Tuesday October 29, 2019 @04:11AM (#21385036)
The POSIX spec of date time specified conversions into a neutral form. Maybe it's C centric thinking but it felt like a problem which has existed and been solved by writing a 'russian interpreter' solution: convert the values on the edge to a canonical form and use functions which manipulate the canonical form. The TZ files i only mention because within the limit of modern epoch Times and dates they do a pretty good job of handling the minutia of what a local time means in any given period.

I'm sorry if I came across as churlish. Do you feel this is a problem of concept in abstract, or in java, or in java implementation or what? I feel it's a problem which I solve, by standing on the shoulders of smarter people and using the code they wrote. I don't reimplement the wheel because I distrust my own wheelmaking skills.

I'm sure there are heaps of non-trivial corner cases I don't have to deal with and I do not mean to minimise work done to explain a problem.

Re:Text Editing Hates You Too by ptx on Tuesday October 29, 2019 @05:14AM (#21385272)
The problem would be, I think, when your business logic is concerned with some subtle aspect of Russian, you translate into canonical English and the detail you're interested in disappears.

When it comes to timestamps, how do you handle midnight for example? 24:00 today represents the same instant as 00:00 tomorrow. The difference might matter to the user but disappears when converted to Unix timestamps.

Re:Text Editing Hates You Too by eesmith on Tuesday October 29, 2019 @05:42AM (#21385403)
dvt's top-level comment was "Things we take for granted are hard."

Your response took things for granted.

dvt originally wrote "We stand on the shoulders of giants."

You commented "I feel it's a problem which I solve, by standing on the shoulders of smarter people and using the code they wrote."

It came across as totally missing dvt's point.

I picked Russian because I was thinking of an essay by Douglas Hofstadter. Quoting myself at https://news.ycombinator.com/item?id=16289783 :

> I think it was in Godel, Escher, Bach where he talks about the problem of translating a line from Russian, along the line of "He lived on B____ street." It's possible from the story, which takes place in a real city, to figure out which street that was. Let's say it was "Main Street". Does the English translation keep the original Russian word and initial? Does it translate to "Main Street" and replace the "B" with an "M"?

You can use a Russian-English translator to get a translation into English. But that doesn't help understand the hard problems involved, which was the point of Hofstadter's essay. (See, for example, his "The Shallowness of Google Translate" in The Atlantic; HN comments at https://news.ycombinator.com/item?id=16267363 and in dupes.)

Re:Text Editing Hates You Too by chrisweekly on Tuesday October 29, 2019 @08:28AM (#21386347)
This reminds me of Milan Kundera's "Testaments Betrayed", which expresses the profound challenge (near impossibility) of translations doing justice to original works.
Re:Text Editing Hates You Too by Loranubi on Tuesday October 29, 2019 @09:53PM (#21393944)
Popular instance of that example is R.A.B. from Harry Potter.
Re:Text Editing Hates You Too by demurgos on Tuesday October 29, 2019 @10:42AM (#21387678)
> I always convert time into time in seconds since the epoch

You should still be careful how you define a _second_. A POSIX second is not the same as an SI second. A POSIX second corresponds to 1/(24 * 60 * 60) of a day. An SI second is defined using atomic time measurement. It means that the duration of a POSIX second depends on the length of the day, and some days are longer than others due to leap seconds.

The worst part is that most tools rely on POSIX timestamps instead of TAI timestamps (based on the SI definition). One of the consequences of using POSIX timestamps is that taking the difference between two timestamp does not safely return the number of elapsed seconds.

Re:Text Editing Hates You Too by haberman on Tuesday October 29, 2019 @12:15PM (#21388827)
> A POSIX second corresponds to 1/(24 * 60 * 60) of a day. An SI second is defined using atomic time measurement.

I don't think that is quite accurate. Traditionally Unix Time seconds are SI seconds, that tick in sync with UTC and atomic clocks (modulo clock error). To account for leap seconds, Unix Time has traditionally been discontinuous when a leap second occurs. Each second that ticks is still an SI second, but the sequence of Unix Time around a leap second will be X-2, X-1, X, X, X+1, X+2, etc.

This discontinuity means that every Unix Time day has exactly 86,400 seconds cumulatively, even though some days tick 86,401 elapsed SI seconds. So it is true that computing a difference between two Unix Time values does not give you a reliable measure of how many SI seconds have elapsed, as you say. But the individual seconds are still all SI seconds.

More recently it has become popular to smear the leap second instead. Google pioneered this approach in 2008 (https://googleblog.blogspot.com/2011/09/time-technology-and-...) and now advocates making it standard (https://developers.google.com/time/smear). This approach does vary the actual length of a second during the 24 hours surrounding a leap second. But this doesn't come from POSIX, it's a departure from previous practice that is designed to avoid a discontinuity.

Re:Text Editing Hates You Too by demurgos on Tuesday October 29, 2019 @07:51PM (#21393335)
Yes, I definitely agree that the reality is even more complicated and there are different implementations. The recent time-smearing approach is closer to the POSIX standard [0]:

> How any changes to the value of seconds since the Epoch are made to align to a desired relationship with the current actual time is implementation-defined. As represented in seconds since the Epoch, each and every day shall be accounted for by exactly 86400 seconds.

Another fact that I find interesting is that the use of discontinuities or time-smearing of the leap days are actually modern approaches. Nowadays, POSIX and TAI differ by an integer amount of seconds on regular days, and a fractional amount when smearing the leap-second day. At the beginning, the leap second duration between POSIX and TAI was smeared over years from one leap second to the other. So the difference between both timestamps would change continually other these periods!

My main takeaway is that POSIX timestamps are based on calendar days while TAI timestamps are based on physics constants. POSIX timestamps are a tradeoff: they're not suitable for time computations (durations, or even uniquely identifying an instant when discontinuities are involved) but they don't require a leap seconds lookup-table to display time for humans... in UTC... Which means you still need lookup tables for timezones, countries, DST, calendar changes, etc. Basically my opinion is that POSIX time is neither the best to precisely keep track of time nor to format it for humans. It just sits in between these two use cases because it was good enough at the time and then too hard to change.

[0]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...

Re:Text Editing Hates You Too by haberman on Tuesday October 29, 2019 @08:40PM (#21393581)
> At the beginning, the leap second duration between POSIX and TAI was smeared over years from one leap second to the other. So the difference between both timestamps would change continually other these periods!

Do you have any reference to a system that was implemented this way? I have never heard of such a thing and I don't see how it could be implemented.

The insertion of leap seconds is unpredictable and occurs when the International Earth Rotation and Reference Systems Service determines that the difference between UTC and UT1 are approaching 0.9 seconds. Leap seconds are generally only decided six months or so before they occur. So you don't know at the beginning of the year how many leap seconds the year will have. So it doesn't seem possible to smear over a year.

Re:Text Editing Hates You Too by demurgos on Wednesday October 30, 2019 @05:20AM (#21395827)
I remember reading it from Wikipedia some times ago. I looked it up again and I was wrong: this was not applied for POSIX but UTC itself. The arrival of international networks seems to actually be the reason why they stopped smearing it continually and switched to a linear version with discontinuities. [0]

> UTC is a discontinuous time scale. From its beginning in 1961 through December 1971 the adjustments were made regularly in fractional leap seconds so that UTC approximated UT2. Afterwards these adjustments were made only in whole seconds to approximate UT1. This was a compromise arrangement in order to enable a publicly broadcast time scale; the post-1971 more linear transformation of the BIH's atomic time meant that the time scale would be more stable and easier to synchronize internationally.

Wikipedia sources it to a book [1].

[0]: https://en.wikipedia.org/wiki/International_Atomic_Time#Rela...

[1]: McCarthy, Dennis D.; Seidelmann, Kenneth P. (2009). Time: From Earth Rotation to Atomic Physics. Weinheim: Wiley-VCH Verlag GmbH & Co. KGaA. ISBN 978-3-527-40780-4.

Re:Text Editing Hates You Too by bouke on Tuesday October 29, 2019 @03:01AM (#21384771)
That’s not taking time zones into consideration, so might be off by an arbitrary amount of hours/minutes.
Re:Text Editing Hates You Too by ggm on Tuesday October 29, 2019 @03:20AM (#21384833)
Obviously you would set TZ before up-converting. I spoke in UTC about an input time I specified in UTC. POSIX date time models understand timezones and on well configured systems understand prior states of time zone behaviours at boundaries like summertime into historical past states. The 1990s USENET discussions did at one point veer off into rotational speed of the earth MYA ago, I'm not sure many people cared but astronomers maybe have to. (I don't think dinosoars used summertime)
Re:Text Editing Hates You Too by bouke on Saturday November 02, 2019 @05:53AM (#21426753)
Historically correct timezone handling is one thing, but you also have to consider future timezone changes unknown at this time. For example some EU countries might decide to cancel daylight savings. Now your conversion from UTC is off by an hour.
Re:Text Editing Hates You Too by coldtea on Tuesday October 29, 2019 @08:05AM (#21386170)
That has its own tons of cans of worms...

See: https://infiniteundo.com/post/25326999628/falsehoods-program...

Re:Text Editing Hates You Too by quickthrower2 on Tuesday October 29, 2019 @05:46AM (#21385427)
One does not simply ... convert time