[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: *ping*



Sabrina Downard <viv@ziggurat.org> writes:

> We had a "y2k bug."  Yep, a very important one.  The date on our main
> web site, generated by a perl script from Matt's Script Archive, rolled
> over to the year 19100.  :-)

Most experienced Perl programmers have a very dim view of the general
quality of scripts in Matt's Script Archive.  Many of them have precisely
this bug and have for a long time, and I believe the author has even been
informed of this in the past and hasn't bothered to fix it.

> Of course, the $Year variable was being set by saying "if ($Year > 95) 
> { print '19$Year' };", and for whatever reason it was rolling 99 to
> 100.

It's the documented behavior of localtime, in both the system C libraries
and inherited by Perl.  The correct way of deriving a four-digit date from
the return of localtime in both Perl and C is to add 1900.  The most
common Y2K bug in Perl scripts is caused by programmers being more subtle
than they should be and not reading the localtime documentation.  They
assume that localtime is returning a two digit year when it's explicitly
documented as returning the number of years since 1900.

(It would have been much better and less confusing for the world had the C
library functions always just returned four-digit dates.  Ah well.)

-- 
Russ Allbery (rra@stanford.edu)         <URL:http://www.eyrie.org/~eagle/>