Section 7.9. Finding the Day of the Year


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 2005its 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 following 23:59:59 came that rare event 23:59:60. But the underlying C libraries on which Ruby is built are ignorant of this.

t0 = Time.gm(1998, 12, 31, 23, 59, 59) t1 = t0 + 1 puts t1      # Fri Jan 01 00:00:00 GMT 1999


It is (barely) conceivable that Ruby could add a layer of intelligence to correct for this. At the time of this writing, however, there are no plans to add such functionality.




The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net