Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

While using timelocal() function from TIME::LOCAL module its not interpreting years correctly if I pass $Rdate = timelocal(0,0,0,12,12,55); it gives error same is for year > 138 or year between 50-58 suggest some solution

Replies are listed 'Best First'.
Re: Year Value Interpretation
by moritz (Cardinal) on Apr 18, 2008 at 11:33 UTC
    A first step is to use a correct value for the month, which should be in the range from 0 to 11.

    The problem with years > 138 is that timestamps for the year 2038 don't fit into a 32 bit integer anymore.

    This is fixed in current bleadperl. Maybe also some CPAN modules do correct date manipulation beyond 2038, maybe you should try some of them.

    Update: I'm a bit curious - what do you need post-2038 dates for?

    Second update: If you want to play with it a bit more I recommend POSIX::mktime:

    # start of epoch $ perl -MPOSIX=mktime -wle 'print mktime(0,0,1,1,0,70);' 0 but true # before epoch $ perl -MPOSIX=mktime -wle 'print mktime(0,0,1,1,0,60);' -315619200 # "normal" dates: perl -MPOSIX=mktime -wle 'print mktime(0,0,1,1,0,100);' 946684800 # how close do we get to 2**32-1 ? $ perl -MPOSIX=mktime -wle 'print mktime(7,14,4,19,0,138);' 2147483647 $ perl -MPOSIX=mktime -wle 'print mktime(8,14,4,19,0,138);' Use of uninitialized value in print at -e line 1.
      oops I misstyped that one while writing here I am paasing these from variables and these are valid as month 0..11 date 1..31
        also the year between 50-58 ..its taking it as 150-158 so gives error again as can't handle timelocal(0,0,0,11,11,15x) x:0..8 but its works with 59 I am quite confused abt this
Re: Year Value Interpretation
by Not_a_Number (Prior) on Apr 18, 2008 at 12:39 UTC

    rtfm:

    Years in the range 0..99 are interpreted as shorthand for years in the rolling "current century," defined as 50 years on either side of the current year. Thus, today, in 1999, 0 would refer to 2000, and 45 to 2045, but 55 would refer to 1955. Twenty years from now, 55 would instead refer to 2055. This is messy, but matches the way people currently think about two digit dates. Whenever possible, use an absolute four digit year instead.
      ok so what to do for year between 38..58 or year> 138
        use DateTime