← Back to context

Comment by dredmorbius

4 years ago

Clock rollovers can be interesting.

Some time back I did work at a devices startup processing data collected from trial runs. For some reason an earlier developer had chosen to use time-of-day, in seconds, rather than elapsed time, as the index for data recording. I'd registered this as a poor design decision, though it was difficult to articulate why.

That argument became far easier after a field trial spanned midnight, and the data series iterated from 86,400 to 0.

On the other hand, I've never had trouble remembering just how many seconds (or minutes) there are in a day, since.

> On the other hand, I've never had trouble remembering just how many seconds (or minutes) there are in a day, since.

Not everyone is so fortunate: https://news.ycombinator.com/item?id=7717414

  • This is why it’s better to express time in seconds using multiplication. Easier to write, easier to review, and easier to change.

        (60 * 60 * 24) // 1 day
        (60 * 60 * 12) // 12 hours
        (60 * 5)       // 5 minutes

    • It's better yet to use a specific time or callendrical function if what you're accounting for is a specific clock or calendar interval.

      Not all days have precisely 86,400 seconds.

      For longer intervals, not all months have 28, 29, 30, 31, 30.43685, whatever, days. Not all years have 365 or 366 days, etc.

      Pull out your copy of "Myths Programmers Believe About Time" and read it, hard. It will bite.

  • Huh, that's an old thread. Was quite confused when the "upcoming PHP 5.6 release" was mentioned!

The term ‘clock rollover’ reminds me of the 2007 incident where 6 F-22’s crossed the date line:

> “…At the international date line, whoops, all systems dumped and when I say all systems, I mean all systems, their navigation, part of their communications, their fuel systems.”

https://www.defenseindustrydaily.com/f22-squadron-shot-down-...