Live data from Hacker News

Time is an illusion, Unix time doubly so

netmeister.org

31–40 of 104 posts

Re: Time is an illusion, Unix time doubly so

#31
post #29
post #26

Earlier quoted context omitted.

That’s a very recent change - and it’s not like 9192631770 transitions/hz (which is hilariously self referential!) is some obvious, natural value that ISN’T based on the historic ‘typical’ length of the day based on our rotation around the sun. A second being 1/86400th of a day (24 hrs * 60 minutes * 60 seconds per minute) is still essentially true, and based, essentially still on the seasons and our movement around…

> it’s not like 9192631770 transitions/hz ... is some obvious, natural value No, but it is a phone number in the Raleigh area.

And would be awesome if it gave out the current time.

Re: Time is an illusion, Unix time doubly so

#32
post #24

Earlier quoted context omitted.

Unix time is not UTC-based. It counts the number of seconds passed since a certain point in time, which may be described as date and time expressed in any time zone you like. It just so happens that in UTC it is easiest to remember for a human what this point was, since you get a lot of zeroes at the end. Edit: I’m not entirely correct here, as aside from UTC the time zone, there is also UTC the time standard. See be…

Unix time is UTC-based, in that the leap second corrections applied to UTC are also simultaneously applied to Unix time (as people tend to use it).

I stand corrected. As I’ve double-checked now, unfortunately “UTC” is ambiguous in that it may refer both to the time standard and the time zone. In this case one can say that Unix time is based on UTC the time standard, but not the time zone. Although given that in Unix time every day has the same number of seconds and instead the clock is sometimes slowed down, while in UTC there is an additional 61st second, can we truly say that it’s UTC-based? I’d say it’s its own standard derived from UTC. Maybe that’s being too pedantic.

Re: Time is an illusion, Unix time doubly so

#33
I'm still of the opinion that handling leap seconds by ignoring them is a dumb idea.

Unix time should be a steady heartbeat counting up the number of seconds since midnight, January 1 1970. Nice, clean, simple. How you might convert this number into a human-readable date and time is out of scope/implementation-defined/an exercise for the reader/whichever variation of "not my problem" you prefer.

Re: Time is an illusion, Unix time doubly so

#34
post #22

Earlier quoted context omitted.

So anyone can bring down Mongo with a compromised ntp server? That's an inconvenient property to have.

Oh, if you own someone's clock, you can do all sorts of damage. Want to expire everyone's passwords? Blow up their credit card processing? Those are just the obvious attacks.

Yes but bringing down a database should not be among those things.

Surely we can agree on that.

Re: Time is an illusion, Unix time doubly so

#35
post #30

Earlier quoted context omitted.

> Timezones, leap seconds... all of that only matters when you're showing the user a date. For recording and calculations, it doesn't. You cannot, by definition, tell how many Unix seconds later "third of may, 2025, at noon, local time" is - there is no way to convert future, local times to Unix times, because that "conversion code" is not fixed. Sure, we can reasonably expect that definition of time flow relationshi…

That's true regardless of how you choose to encode time and is a problem of local time zones not unix time.

Not really. Generally, you can tell whether "fifth of November, at midnight, local time" is equal to `now` or not as long as you have reasonably accurate information what "local" means. This is a problem of time encoding, because we do define what midnight is, but keep relationship between it and seconds passed undefined as long as possible

Re: Time is an illusion, Unix time doubly so

#36

Maybe I am misunderstanding the post, but for me the beauty of Unix time is precisely that all the weirdness with dates is abstracted away to the "conversion code" so that you only deal with "seconds". Timezones, leap seconds... all of that only matters when you're showing the user a date. For recording and calculations, it doesn't.

> Timezones, leap seconds... all of that only matters when you're showing the user a date. For recording and calculations, it doesn't. You cannot, by definition, tell how many Unix seconds later "third of may, 2025, at noon, local time" is - there is no way to convert future, local times to Unix times, because that "conversion code" is not fixed. Sure, we can reasonably expect that definition of time flow relationshi…

Is there a system that does allow you do to do this? I can't think of one that would.

Local time requires a time zone, times zones are defined in relation to UTC, and there is an unknown number of leap seconds between now and 3 May, 2025.

Re: Time is an illusion, Unix time doubly so

#37
A long time ago -- late 1980s -- I worked in system software, VMS-based, at DEC.

Sometimes we used, for dev and testing, dedicated machines running with clocks set 20-25 years in the future. (They was a measurable investment of capital, power, and cooling back then.) This was smart: the remnants of DEC were able to sidestep the whole Y2K cluster**k.

Are our key tech vendors doing the same now? It's about a quarter century until the 2038 fin-de-siecle. I sure would like some assurance that the OSs, DBMSs, file systems, and other stuff we all adopt today will have some chance of surviving past 2038-01-19.

I know redefining time_t with 64 bits "solves" the problem. But only if it gets done everywhere. Anybody who's been writing programs for more than about 604 800 seconds has either thought through this problem or hasn't.

Re: Time is an illusion, Unix time doubly so

#38

Maybe I am misunderstanding the post, but for me the beauty of Unix time is precisely that all the weirdness with dates is abstracted away to the "conversion code" so that you only deal with "seconds". Timezones, leap seconds... all of that only matters when you're showing the user a date. For recording and calculations, it doesn't.

> leap seconds Unix time is UTC based, so it ignores leap seconds and deviates from how many seconds actually passed since the start of the epoch. The actual number of seconds passed corresponds to TAI, but you can't convert future timestamps from TAI to UTC since you can't predict leap seconds, so you can't display future TAI timestamps using typical date notation. > For recording and calculations, it doesn't. Depen…

You can easily "display future TAI timestamps using typical date notation".

Both past timestamps and future timestamps are not exact numbers, but approximate numbers, affected by errors.

The only difference between past timestamps and future timestamps that are converted from TAI to UTC is in the magnitude of the errors.

If the past timestamps have been acquired on a computer whose clock had been synchronized by NTP, then the errors are likely to be less than 10 millisecond.

If the past timestamps have been acquired on a computer whose clock had not been synchronized with a precise source, then the errors are likely to be greater than a second and they may be as large as of several minutes.

For future timestamps, the uncertainty of the value of the difference between TAI and UTC makes the likely value of the errors to be of several seconds, and increasing with the distance of the timestamp in the future.

In conclusion, one must be aware of the probable magnitude of the errors affecting an UTC timestamp, but that does not prevent conversions between TAI and UTC, whenever that is desired.

One of the greatest mistakes when dealing with time values is handling them like they were exact values, which they are not.

To handle future timestamps with minimal errors, it is necessary to have 2 distinct data types, a TAI time expressed as a number of some time units, e.g. nanoseconds, and an UTC time that is a structure containing date and time of the day. An UTC time must never be expressed as a number of seconds from some past date. That is the huge mistake made by the "UNIX time".

Future timestamps must be stored using the appropriate data type, e.g. UTC time for a future scheduled meeting.

The hardware clocks and the low-level clock synchronization and handling programs should always use TAI time.

When the current time approaches a future UTC timestamp, the error of the estimation of the corresponding TAI time diminishes. The leap seconds are announced with many months in advance, so the correct TAI time for a future UTC timestamp will also be know with at least a few months in advance. There is no risk that you computer will fail to notify you about the right time of the meeting, except when a naive programmer handles the timestamps wrongly, which is unfortunately quite frequent.

Re: Time is an illusion, Unix time doubly so

#39

Very interesting detail about linux and setting the time back to a value such that the boot time is before the epoch, with monotonic clocks. Shamelessly I'll here remind people to never use gettimeofday() to measure time. E.g. setting the time backwards used to cause any currently running "ping" command to hang. (they fixed it about 10 years after I sent them a patch) More fun examples of bugs like that at https://bl…

I have made that same mistake a few times myself.

It comes from a natural inclination of I want something to expire some period from now.

The natural way is to say what time is it now. Figure out what time you want to expire with a date add. Then busy wait until that time expires using some form of gettime. The very big assumption you make is that the gettime methods always move forward. They dont.

This bug is easy to make thinking you are treating a wait item as a calendar event. Its not. You need to find something to busy wait on, that always counts up. Do not use the system clock. Also pick something that counts at a known fixed rate. Not all counters are equal. Some can skew by large margins after an hour and triggering when you do not expect. Which makes people want to reach for the system clock again. If you somehow decide 'i will use the clock' be prepared for some pain of the dozens of different ways that fails.

Re: Time is an illusion, Unix time doubly so

#40

I'm still of the opinion that handling leap seconds by ignoring them is a dumb idea. Unix time should be a steady heartbeat counting up the number of seconds since midnight, January 1 1970. Nice, clean, simple. How you might convert this number into a human-readable date and time is out of scope/implementation-defined/an exercise for the reader/whichever variation of "not my problem" you prefer.

> Unix time should be a steady heartbeat counting up the number of seconds since ...

This is nice and clean, so long as you have exactly one computer. The second there are more than one, and they are talking to each other, their clocks can go out of sync with each other. And they will, because they are physical systems that are imperfect and in general much less precise than you'd expect them to be.

This means that there has to be a way to correct for errors. The best method, that almost everyone who manages a lot of computers converges onto, is to "smear out" any errors, by never discretely changing the time on any machine, but just shortening or lengthening seconds slightly to bring any outliers back to the correct values. And once you have this system, dealing with a leap second using it is the easiest, simplest and least errorprone method.

I do think that there are purposes where local "machine time", which is just a monotonic clock counting upwards from bootup, would make sense. Especially when subsecond accuracy is important. But it should always be clear that there is no way to reliably convert between that and wallclock or calendar time. There are *no* intervals of calendar/wallclock time that reliably convert to any interval of machine time. It is not guaranteed that any wallclock minute contains exactly 60 machine seconds.

Post reply on HN