# New Ticket Created by Zefram # Please include the string: [perl #126119] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=126119 >
The Instant class supposedly represents times on the TAI time scale, with subtraction of Instants yielding counts of atomic seconds. The corresponding difference of POSIX time_t values yields a count of non-leap seconds. The difference between these two differences, for corresponding endpoints, therefore yields a count of leap seconds. Instant.from-posix() will conveniently perform the translation. So here's some code to count the leap seconds that occur in an interval specified by time_t values: $ ./perl6 -e 'sub leaps-between ($a, $b) { (Instant.from-posix($b) - Instant.from-posix($a)) - ($b - $a) }; say leaps-between(time - 1000000000, time); say leaps-between(time, time + 1000000000)' 14 0 The first of the time intervals on which I've tried that runs from January 1984 to today, and the count of 14 leap seconds is historically correct. The second interval runs from today to May 2047... and will almost certainly contain a non-zero number of leap seconds. The count of zero is bogus. In reality, we don't know how many leap seconds there will be in the next gigasecond. We can guess: anything from five to twenty is defensible. But there is no value that we can say is certainly correct. So Instant.from-posix(time + 1000000000) cannot produce any definitely-correct value. It really ought to signal an error. If it is really intended to guess, in cases where a definitive answer is available, then the guess that it is making is crap. To make a reasonable guess, use a quadratic formula based on the observed tidal braking, and quantise it to one-second leaps on appropriate month boundaries. A finer guess could be made for the next few decades by extrapolating from recent decades' measurements. Also, if it's a guessing function, it ought to be named in a way that clues in the user. "from-posix-best-guess" or so. It would also be sane to have both kinds of conversion function. -zefram