Live data from Hacker News

Unix time is bad and needs replacement, not UTC

z.vandillen.dev

11–20 of 96 posts

Re: Unix time is bad and needs replacement, not UTC

#11
post #3
post #2

Is it not irrelevant for most use cases? Leap seconds or whatever. Think of the time of this post. It is stored but how important is the accuracy?

Timestamps are used for a lot of scheduling tasks that need to be reasonably precise. So an event happening one second earlier than expected, or even twice, could be a problem I suppose. Not exactly impossible to deal with, but I guess lots of people screw it up? Haven't really worked on systems where this _truly_ matters.

Synchronization between computers is hard. https://www.gnu.org/software/coreutils/manual/coreutils.html...

Re: Unix time is bad and needs replacement, not UTC

#12
post #3
post #2

Is it not irrelevant for most use cases? Leap seconds or whatever. Think of the time of this post. It is stored but how important is the accuracy?

Timestamps are used for a lot of scheduling tasks that need to be reasonably precise. So an event happening one second earlier than expected, or even twice, could be a problem I suppose. Not exactly impossible to deal with, but I guess lots of people screw it up? Haven't really worked on systems where this _truly_ matters.

Could it matter for high-frequency trading? Since these trades occur in milliseconds, I presume trading being off by a second would be considered very damaging.

Re: Unix time is bad and needs replacement, not UTC

#13
Clocks are out of sync all the time, so any code that relies on precise timestamps needs some way to account for out-of-sync clocks anyway.

So if you store two timestamps, you can't rely that the actual time that has passed between storing the two timestamps is equal to their difference, since the clock might have been slow, fast, or might have been synchronised with another clock between the recording of the two timestamps.

I think dealing with leap seconds should work in a similar way as working with other clock synchronisation issues, so I really don't see the point of adding new types of clocks in unix.

Re: Unix time is bad and needs replacement, not UTC

#14
post #9

>The exact way Unix time handles leap seconds* is complex and an unnecessary detail for this article, but it will suffice to say that (i) whenever a positive leap second occurs, a timestamp is used twice, and (ii) if a negative leap second were to occur, a timestamp is skipped. Huh, I always assumed that Unix time just ignores them and ticks forward. I get why e.g. UTC needs them but why would it make sense for Unix…

If Unix time ignored them, the conversion between timestamps and UTC would no longer be possible with just arithmetic operations. You'd need a list of leap seconds and take them into account. Now one can argue if this is better or worse than the current solution, but it's not without its tradeoffs.

Re: Unix time is bad and needs replacement, not UTC

#15
post #2

Is it not irrelevant for most use cases? Leap seconds or whatever. Think of the time of this post. It is stored but how important is the accuracy?

I agree that for many use cases the exact second is irrelevant, like submission times and things likes that. That being said, programmers do seem to expect, for example, that code like `(int)time(NULL) - previous_time` works and accurately gives the difference in time between now and whenever `previous_time` was given its value. This does work, but only 99.99% of the time. Then it breaks 0.01% of the time. For bug-free code it's important that the expectations of the programmer are in line with reality, and the problem with Unix time is that programmers' expectations of the mathematical properties of Unix time and the real mathematical properties of Unix time do not line up. This is what leads to the countless bugs involving leap seconds.

The fact that accuracy is often not important is also crucial to my proposal of legacy Unix time, because legacy Unix time would eventually go out of sync with the rotation of the Earth just like TAI. In almost all cases this would practically be an aesthetic bug where dates in old user interfaces would be a few seconds off from the real date, and therefore not particularly harmful.

Re: Unix time is bad and needs replacement, not UTC

#16
I think the article should not have left out the observation that in case you want to get to local time from UTC, you can only do so with certainty for the past, the present and the near future, because there could always be a change in daylight savings time (DST) regulations for a given locale. In my eyes that makes UTC a tiny little less useful for some purposes. OTOH human schedules should not be affected. Even for a country like [Egypt] which apparently has no issues with changing DST regulations with a mere few days of notice, meeting at 1:00pm in Cairo on some given day in the future will always mean whatever the local time stipulates it to be, come the day.

OTOH I believe that for computers, adopting something like TAI for all timestamps would probably a good thing. Re-adjusting display dates for the past where needed is much less complex wrt leap seconds than it is for time zones and DST. The conceptual simplicity of TAI and the invariants afforded by it come with the slight disadvantage that "the future can not be predicted", but we already cannot predict the future of countries changing time zones and DST dates, so we'd not be any worse off in that regard.

[Egypt](https://en.wikipedia.org/wiki/Daylight_saving_time_in_Egypt)

Re: Unix time is bad and needs replacement, not UTC

#17
EDIT: This comment was corrected by numerous replies below and the original comment contained incorrect information. Thanks to all posters for the corrections.

Original comment:

> The simplified definition of Unix time is that Unix time counts the amount of seconds that have passed since the first of January 1970 (which is referred to as “the epoch”, similar to the first of January of 1 AD being the epoch of the Gregorian calendar). This is of course not the complete definition, since it does not take leap seconds into consideration.

I disagree with the statement that UNIX time is not the amount of seconds since the Epoch. Leap seconds never happened, they were added to UTC and UTC only in order to correct it for sunrise and sunset.

If we started an experiment on 23:00 and ended it on 01:00 the next day, but a leap second occured in the mean time, the experiment wasn't running for 7200 seconds, but for 7199 seconds. The leap second had nothing to do with time counting, a stopwatch would not add a second to the reading.

If we started an experiment on Epoch, the UNIX time tells us the amount of seconds this experiment has been running. If we added 86400 leap seconds in between, the experiment would count real time, not our made up time. One day wouldn't be added to the count.

As far as I understand it, that's what UNIX time is, and there's nothing wrong with that. It's a feature.

Please add your opinion.

Re: Unix time is bad and needs replacement, not UTC

#18
post #14
post #9

>The exact way Unix time handles leap seconds* is complex and an unnecessary detail for this article, but it will suffice to say that (i) whenever a positive leap second occurs, a timestamp is used twice, and (ii) if a negative leap second were to occur, a timestamp is skipped. Huh, I always assumed that Unix time just ignores them and ticks forward. I get why e.g. UTC needs them but why would it make sense for Unix…

If Unix time ignored them, the conversion between timestamps and UTC would no longer be possible with just arithmetic operations. You'd need a list of leap seconds and take them into account. Now one can argue if this is better or worse than the current solution, but it's not without its tradeoffs.

Edit: My original comment is incorrect. Please read child comments.

Original comment:

Yes, to convert from UNIX time to UTC, you do need a list of leap seconds.

Re: Unix time is bad and needs replacement, not UTC

#19
The author is right. I couldn't believe it when I first learnt the difference between UTC and TAI that Unix time based on UTC. It makes no sense. And now they are talking about "correcting" UTC to make Unix time work? Thus defeating the entire point of UTC?

There's something about time that people seem to find very difficult to reason with. It reminds me of the arguments between whether we should use standard time all year or daylight savings time all year.

Re: Unix time is bad and needs replacement, not UTC

#20
Sorry, no. UNIX time is easy, works fine for most of cases and can be extended easily to the rest of the cases, and a single well-defined compromise approach. Replacing it with three different time representations is dangerous overengineering.

We should all re-read "the rise of worse is better" until enlightenment (https://dreamsongs.com/RiseOfWorseIsBetter.html).

Post reply on HN