On Thu, Nov 28, 2002 at 10:20:46AM +1100, simran wrote:
> Hi All, 
> 
> When i use the 'localtime' function in perl 5.6.1 if i pass it an epoch
> time of less than 0 then i always get the date of:
> 
>   * "Wed Dec 31 19:00:00 1969"
> 
> Is there a method someone knows of (other function, cpan module?,
> anything) that will let me convert epochs of less than 0 to valid
> date/time strings?
> 
> I am using Date::Parse::str2time and that produces epochs of less than
> zero. 

localtime() does indeed work with negative values:

        $ perl5.6.1 -e 'print scalar localtime (-1), "\n"'
        Wed Dec 31 18:59:59 1969

        $ perl5.6.1 -e 'print scalar localtime (-1_000_000), "\n"'
        Sat Dec 20 05:13:20 1969

        $ perl5.6.1 -e 'print scalar localtime (-1_000_000_000), "\n"'
        Sun Apr 24 18:13:20 1938

Maybe the bug is somewhere else in your code?  Sounds like you're
rounding negative values to zero before calling localtime().

Z.

Reply via email to