7.8. Working with Leap Seconds: Don’t!

Ah, but my calculations, people say,

Reduced the year to better reckoning? Nay,

‘Twas only striking from the calendar

Unborn Tomorrow and dead Yesterday.

Omar Khayyam, The Rubaiyat (trans. Fitzgerald)

You want to work with leap seconds? Our advice is: Don’t.

Leap seconds are very real. One was added to the year 2005—its final minute had 61 seconds rather than the usual 60. Although the library routines have for years allowed for the possibility of a 61-second minute, our experience has been that most systems do not keep track of leap seconds. When we say “most,” we mean all the ones we’ve ever checked.

For example, a leap second is known to have been inserted at the end of the last day of 1998. Immediately ...

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.