in reply to Error parsing using Time::Piece

Updating Time::Piece to 1.29 is not the problem. I get the same error under 1.27.

$ perl -MTime::Piece -E 'say $Time::Piece::VERSION' 1.27 $ perl -MPOSIX=strftime -MTime::Piece -E ' say strftime q{%FT%T}, loca +ltime; Time::Piece->strptime( strftime(q{%FT%T}, localtime), q{%FT%T} +);' 2015-04-29T04:18:23 Error parsing time at /Users/ken/perl5/perlbrew/perls/perl-5.20.2t/lib +/5.20.2/darwin-thread-multi-2level/Time/Piece.pm line 469.

The error message includes a pathname to the file and a line number. Had you viewed that file and gone to line 469, you would have seen that line is in sub strptime and, just a few lines above, you see sub strftime (sound familiar?).

Looking at the Time::Piece documentation, you'll see that Time::Piece::strftime is the "same as POSIX::strftime (without the overhead of the full POSIX extension)".

To fix, the easiest would be to remove the POSIX references. If, for some reason, that's not possible (I've no idea what your real code looks like), you'll need to be specific about which strftime you mean, i.e. POSIX::strftime or Time::Piece::strftime.

-- Ken

Replies are listed 'Best First'.
Re^2: Error parsing using Time::Piece
by Anonymous Monk on Apr 28, 2015 at 18:48 UTC
    This is the line the gives me the error:
    ... my $date = Time::Piece->strptime("32015", "%m%Y");

      You will need to add a leading zero to that:

      my $date = Time::Piece->strptime("032015", "%m%Y");

      Maybe you could use sprintf?

      perl -MTime::Piece -le'print Time::Piece->strptime( sprintf( "%06d", " +32015"), "%m%Y" )'

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        It seems that if I convert this line in my code from:
        my $last_month_num = $t->add_months(-1)->mon;

        to:
        my $last_month_num = sprintf("%02d",$t->add_months(-1)->mon);

        It should take care of the problem!