[ale] Perl 5 (localtime) - Y2K issue
Mike Fletcher
fletch at phydeaux.org
Thu Sep 2 18:22:28 EDT 1999
>>>>> "Russell" == Russell Enderby <Russell.Enderby at arris-i.com> writes:
Russell> That is correct for the calculation but I don't think it
Russell> accurately describes the year correctly. I would expect
Russell> to get 2001 and not 101. I could understand 001 but not
Russell> 101. Since many programs like MySQL use the full date
Russell> 101 will throw it off.
Read `perldoc -f localtime':
[...]
Also, C<$year> is the number of years since 1900, that is, C<$year> is
C<123> in year 2023, and I<not> simply the last two digits of the year.
[...]
If you're passing (localtime())[5] to something that is
expecting a year rather than expecting the number of years since 1900
it's your problem for passing the wrong data, not perl's for providing
a different value.
Russell> I guess the bottom line is if the intention is to get me
Russell> just the last two digits it should be 01. If it is
Russell> supposed to give me the full date then 2001. But 101
Russell> seems a bit odd. Maybe I am the only one with this
Russell> impression.
The intention is not to give the last two digits of the year
(which just leads to things like the y2k problem) or the full year.
The intention is to give the number of years since 1900, just as the
underlying C POSIX localtime(3) call does:
[...]
tm_year
The number of years since 1900.
[...]
If you need the last two digits of the year, then use
POSIX::strftime()'s "%g" format (but then you're creating your own y2k
problem). If you need the actual year, perl provides a perfectly good
`+' operator. :)
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org | Vincent, you should cease askin' \ o.O'
678 443-6239(w) | scary questions." -- Jules =(___)=
| U
More information about the Ale
mailing list