Live data from Hacker News

Some Notes About Time

unix4lyfe.org

21–30 of 118 posts

Re: Some Notes About Time

#21
post #9

Earlier quoted context omitted.

Things do indeed become much simpler when you reason in milliseconds since the epoch. So why is it so rare to do so? UNIX time is not milliseconds since the epoch. It's milliseconds since the epoch, plus the leap seconds that have accumulated over that period. The only widely used timebase that's pure milliseconds since the epoch that I'm aware of is GPS time, and basically everything adds in the leap seconds before…

I think you mean that unix time is seconds since the epoch minus leap seconds.

All depends on what sign you assign to the leap seconds!

Re: Some Notes About Time

#22
Also worth noting: there are many time zone variations beyond DST, and some are defined in terms of partial hours (30 or 15 minute variations).

True story: when I was at ITA Software, Orbitz ran hundreds of instances of QPX, our low fare search software, on their own servers. We had an ops fire drill one weekend because customers were complaining that the site was showing incorrect prices. The root cause? A single machine in their server farm had the time wrong, so advance purchase was computed incorrectly for any query sent to that particular machine. That was fun to debug.

Even the meaning of, say, a minium stay requirement is hard to precisely define. If you fly across the international date line and back on a Friday night, did you have a Saturday stay or not? There are so many flights going so many places, questions like this actually come up in practice.

Re: Some Notes About Time

#23

Also worth noting: there are many time zone variations beyond DST, and some are defined in terms of partial hours (30 or 15 minute variations). True story: when I was at ITA Software, Orbitz ran hundreds of instances of QPX, our low fare search software, on their own servers. We had an ops fire drill one weekend because customers were complaining that the site was showing incorrect prices. The root cause? A single ma…

For other - often difficult, and sometimes surprising - problems with time, see Peter-Paul Koch's excellent essay "Making safe for historians": http://www.quirksmode.org/blog/archives/2009/04/making_time_...

Re: Some Notes About Time

#24
> When storing time, store Unix time. It's a single number.

Don't do this in your database. Use your datetime types. Please. You might save some work with your timezone but you're not going to be able to use intervals etc in a smart way.

This would be even dumber with PostgreSQL, which has much more robust date/time functionality (being able to use the - operator with datetimes and intervals, for example) and completely sane timezone support.

Re: Some Notes About Time

#25
post #8

Funny I read the title and thought: TVM but then realized it was the age old quest for time keeping and dreaming of ways to track it with reasonable sanity.. :-) Bonus points for anyone who knows what I mean by TVM and can describe why every programmer should know about it..

You explaining it would be more useful than the bonus points.

Re: Some Notes About Time

#26
As the article hints, even though timezones are usually presentation-only, there are some cases where business logic really does have to deal with timezones.

If your software has business logic that cares about, say, what day a specific person perceived an event as happening, it needs to think about the timezone they have set.

So, in such cases, you'd better keep a history of all the timezones they've ever chosen, and the time (UTC) they changed them.

(Hopefully this lets someone else avoid my past mistakes.)

Re: Some Notes About Time

#27
I guess a related question is how do you synchronize a users perception of time with a program's perception of time -- a program that the user is interacting with. To effect this synchronization, you somehow need to know of the latencies involved in the user initiating actions that the program can sense and when those actions register with the program and in (latencies involved with) the program initiating actions that the user can sense and when the user senses those actions.

Re: Some Notes About Time

#28
This topic comes up again and again. But I mostly read only about the problems, not about the solutions.

This post advises to use Unix timestamps. That's already what I'm doing mostly everywhere. And it seems to me like most people do and like this is somewhat accepted as the best available option - but still not perfect.

Then I am wondering again: Isn't there really a perfect solution? Esp., the problems with Unix timestamps are the non-monotony and that e.g. two equal timestamps can actually represent two different times (seconds). This could be bad in cases where seconds matter (e.g. some log-files which need to be very precise about time).

Maybe TAI is and we all should store TAI timestamps instead of Unix timestamps? But is there an easy way to get TAI timestamps? Also, I haven't really seen other projects doing this - why? Maybe it is just too little gain over Unix timestamps and too less tools available to work with them... Btw., I just checked, there is http://cr.yp.to/libtai.html and http://pypi.python.org/pypi/tai64n, maybe I should just start using that.

This of course still doesn't solve anything about synchronization or inaccurate system clocks but it would be better than Unix times.

Edit: Getting the TAI timestamp is probably not easy or maybe even not possible... I just saw this: https://github.com/stoni/libtai/blob/master/tai_now.c ...

Re: Some Notes About Time

#29

Who was the genius who decided that unix time should handle leap seconds? It seems like such an obviously bad idea. The biggest advantage of unix time has always been that it is monotonically increasing and that it is precisely defined as seconds since the epoch, period. And then all of that is now broken because of this decision. Also, does the problem that the leap second solves actually warrant all of the problems…

Since Unix time does NOT count the leap seconds, it allows the computation of the human-readable time from the Unix time without knowing when the leap seconds occurred. If knowledge of when the leap seconds occurred is required, then those events would need to be available somehow and used, introducing i) more expensive computation ii) difficulty in future-proofing an app since a reliable and updated data source supplying the times of leap seconds is required.

Re: Some Notes About Time

#30
post #24

> When storing time, store Unix time. It's a single number. Don't do this in your database. Use your datetime types. Please. You might save some work with your timezone but you're not going to be able to use intervals etc in a smart way. This would be even dumber with PostgreSQL, which has much more robust date/time functionality (being able to use the - operator with datetimes and intervals, for example) and complet…

Why can't you use intervals in a smart way? Single number is the easiest and fastest method to use for intervals.

The only true problem with storing unix time is leap seconds and relativistic effects, which can both be safely ignored for most time keeping usages.

Post reply on HN