MLUG: Re: [UUG/MLUG] perl and y2k
Re: [UUG/MLUG] perl and y2k
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
>From http://www.perl.com/pub/1999/01/y2k.html, written by Tom
Christiansen:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The date and time functions supplied with Perl are the gmtime() and
localtime()  functions, which are derived from their namesakes from the C
programming language. These supply adequate information to determine the
year well beyond 2000. 2038 is when trouble strikes, but only for those of
us still stuck on 32-bit machines, a somewhat unlikely albeit admittedly
not entirely unthinkable situation.

                    The year returned by these functions (when used in
list context) is, contrary to popular misconception, not by definition a
two-digit year. Rather, it merely happens to be such right now.  What it
actually is, is the current year minus one thousand nine hundred. For
years between 1900 and 1999 this happens to be a 2-digit decimal number,
but that's not going to last long. To avoid the year 2000 problem, simply
do not treat the year as a 2-digit number. Easy to say, and easy to break.
Imagine that you want find out what the year appears to be in five years,
so you write code like this.

                        
use Time::localtime;
$then = time() + ( 60 * 60 * 24 * 365 * 5 );  # 5 years from now
$that_year = localtime($then) -> year;

printf("It shall be 19%d\n", $that_year); # WRONG! 19103
printf("It shall be %d\n", 1900 + $that_year); # right:  2003