DateTime::Format::Strptime is not able to parse what it has formatted
Hello, Consider this code : my $formatter = DateTime::Format::Strptime-new( pattern = %d-%b-%G, on_error = 'croak' ); my $date = DateTime-now(); my $formatted = $formatter-format_datetime($date); warn formatted=$formatted; # output e.g. 27-May-2009 my $parsed_date = $formatter-parse_datetime($formatted); = got There is no use providing a month name (May) without providing a year. at bug_datetime.pl line 8 So the formatting is ok, but the parsing fails, with an incorrect message. It seems to be a bug, but maybe I missed something. It's problematic because I reallny need to parse these types of dates (27-May-2009). P.S $DateTime::Format::Strptime::VERSION = '1.0901';
Re: DateTime::Format::Strptime is not able to parse what it has formatted
Ok I figured out that I was using %G (The year corresponding to the ISO week number) instead of %Y. But I still thinks this is weird that the format instance is not able to parse what it just has formatted. Thanks On Wed, May 27, 2009 at 1:10 PM, Karl Forner karl.for...@gmail.com wrote: Hello, Consider this code : my $formatter = DateTime::Format::Strptime-new( pattern = %d-%b-%G, on_error = 'croak' ); my $date = DateTime-now(); my $formatted = $formatter-format_datetime($date); warn formatted=$formatted; # output e.g. 27-May-2009 my $parsed_date = $formatter-parse_datetime($formatted); = got There is no use providing a month name (May) without providing a year. at bug_datetime.pl line 8 So the formatting is ok, but the parsing fails, with an incorrect message. It seems to be a bug, but maybe I missed something. It's problematic because I reallny need to parse these types of dates (27-May-2009). P.S $DateTime::Format::Strptime::VERSION = '1.0901';
Re: DateTime::Format::Strptime is not able to parse what it has formatted
Karl Forner wrote: Ok I figured out that I was using %G (The year corresponding to the ISO week number) instead of %Y. But I still thinks this is weird that the format instance is not able to parse what it just has formatted. Glad you worked it out. I haven't looked, and can't be certain, but I'm guessing %G got added to DateTime's strftime function after I created strptime. While I can add support for %G, it's a bit of a PITA and I doubt it's ever actually needed. %Y is the correct symbol for the format you're using. Cheers! Rick Measham -- Message protected for iSite by MailGuard: e-mail anti-virus, anti-spam and content filtering. http://www.mailguard.com.au
Re: DateTime::Format::Strptime is not able to parse what it has formatted
While I can add support for %G, it's a bit of a PITA and I doubt it's ever actually needed. %Y is the correct symbol for the format you're using. Might want to test out my DateTimeX::Format::POSIX::Strptime which adds the missing link for the native strptime() function from the POSIX.pm library by using the cpan package POSIX::strptime(). -- Evan Carroll System Lord of the Internets