in reply to Re: Date conversion in perl?
in thread Date conversion in perl?

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^3: Date conversion in perl?
by almut (Canon) on Mar 03, 2010 at 08:15 UTC
    $ perl -le 'print scalar(localtime(20100302165019));' Mon Mar 22 05:03:39 638923 ^^ ^^^^^^

    (with a 64-bit Perl)

    The string '20100302165019' doesn't represent seconds since "the epoch", which is what localtime() would expect.

Re^3: Date conversion in perl?
by ikegami (Patriarch) on Mar 03, 2010 at 08:22 UTC

    No. That's not the what localtime takes for input. And even if it did, localtime does not produce the requested output.

    In fact, that number is so large that it doesn't fit in a 32-bit int, and thus my localtime can't handle it:

    >perl -wle"print scalar(localtime(20100302165019));" Use of uninitialized value in print at -e line 1.
      ww@GIG:~$ perl -wle 'print scalar(localtime(20100302165019));' Wed Dec 31 18:59:59 1969 ww@GIG:~$ perl -wle 'print scalar(localtime(20100302165219));' Wed Dec 31 18:59:59 1969 ^ ww@GIG:~$ perl -wle 'print scalar(localtime(20100305165219));' Wed Dec 31 18:59:59 1969 ^ ww@GIG:~$ perl -wle 'print scalar(localtime(23100305165219));' Wed Dec 31 18:59:59 1969 ^

      32bit 5.10 Linux

        FYI that date, 1 second before epoch, corresponds with a time value -1 (hex FFFFFFFF) which is commonly used as an overflow value for integer arithmetic.

        It's a different failure mode, but it's still failing by returning the date for -1 instead of returning undef.

        I imagine that some of the work in this area is done by the underlying C library, so you can expect differences between systems.

        I believe that might also be changed in 5.12 to avoid the year 2038 overflow.

        Update: Confirmed:

        $ /usr/bin/perl -le'print scalar localtime "201003031234"' Wed Dec 31 18:59:59 1969 $ ./perl -le'print scalar localtime "201003031234"' Fri Jul 14 19:20:34 8339
Re^3: Date conversion in perl?
by Utilitarian (Vicar) on Mar 03, 2010 at 08:58 UTC
    Not a unix epoch date
    $ perl -e '$time_array = ["2010", "03", "02", "16", "50", "19"]; print @{$time_array};' 20100302165019

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."