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

Re: [cobalt-users] Y2K bug with perl



Once upon a time, Douglas MacDougall <mac@xxxxxxxxx> said:
> Just found a bug.. probably many people already had a handle on it.. but
> just in case.. if you use perl "localtime(time)"
> the year value will return 100.
> 
> I had expected to get 00 and had implemented fixes for 00 but all my fixes
> failed because I got 100..  anyway.. only a few minor problems with that..
> but if you use it (I think good programmers actually suggest you DONT.. but
> anyway.. I am self taught :P) anyway.. if you use localtime fix it!

Read the documentation.  The localtime builtin in perl has always been
documented as returning the number of years since 1900.  So, 100 is the
proper value for the year 2000.

Now, there are some that did not read that and instead of adding 1900 to
the value returned for the year by localtime, they treated it like a
string and prefixed it with "19".  This is doubly bad because not only
does it give the wrong value for any year outside 1900-1999, it also
forces an unnecessary number to string conversion.
-- 
Chris Adams <cmadams@xxxxxxxxxx>
Systems and Network Administrator - HiWAAY Information Services
I don't speak for anybody but myself - that's enough trouble.