Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 60138
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: k.ponting [...] aurix.com
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 6.11
Fixed in: 5.54



Subject: "7pm last sunday." breaks code if passed as array, not as string
Hi there. Date::Manip is very good, but I fell over the following: Simplest form: #!/usr/bin/perl -w use warnings; use strict; use Date::Manip; our $TZ = "GMT"; # necessary for Vista with 5.54 but not with 6.11 print "Version: ",$Date::Manip::VERSION,"\n"; my $date = ParseDate("7pm last"); print $date || "failed to parse date","\n"; Producing the output (under the debugger): Version: 6.11 Can't use an undefined value as an ARRAY reference at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 1736. at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 1736 Date::Manip::Date::_parse_date_other('Date::Manip::Date=HASH(0x13f62b0)', ' last', 0, 'SCALAR(0x10483d0)') called at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 372 Date::Manip::Date::_parse_date('Date::Manip::Date=HASH(0x13f62b0)', ' last', 0, 'SCALAR(0x10483d0)') called at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 178 Date::Manip::Date::parse('Date::Manip::Date=HASH(0x13f62b0)', '7pm last') called at /home/ponting/public/perl/lib/perl5/Date/Manip.pm line 135 Date::Manip::ParseDate('7pm last') called at /home/ponting/Research/ponting/topics/spider/testdate.pl line 7 Versions: This is perl, v5.10.0 built for x86_64-linux-thread-multi Date::Manip version 6.11 Suse Linux, 64-bit - output of uname -a is: Linux titan75 2.6.27.7-9-default #1 SMP 2008-12-04 18:10:04 +0100 x86_64 x86_64 x86_64 GNU/Linux =========Further information which may be irrelevant =============== Originally I was trying to parse using the REF ARRAY interface in order to detect date sequences (such as the particular case "7pm last Sunday.") embedded in longer strings, which cut down to the following four variants, showing that Date::Manip is confused by the terminating ".": #!/usr/bin/perl -w use warnings; use strict; use Date::Manip; our $TZ = "GMT"; # necessary for Vista with Date::Manip 5.54 used below print "Version: ",$Date::Manip::VERSION,"\n"; foreach my $str ("7pm last Sunday", "7pm last Sunday.", [qw/7pm last Sunday/], [qw/7pm last Sunday./]){ print $str,"\n"; my $date = ParseDate($str); print $date,"\n"; } producing the following output: Version: 6.11 7pm last Sunday 2010080119:00:00 7pm last Sunday. ARRAY(0x796e88) 2010080119:00:00 ARRAY(0x7cb558) Can't use an undefined value as an ARRAY reference at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 1736. The last error, when the string is passed as REF ARRAY of three strings, terminates my program. The perl debugger gives more information - it appears to have rejected the "Sunday." and be parsing "7pm last". Date::Manip::Date::_parse_date_other('Date::Manip::Date=HASH(0x13f6aa0)', ' last', 0, 'SCALAR(0x1048590)') called at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 372 Date::Manip::Date::_parse_date('Date::Manip::Date=HASH(0x13f6aa0)', ' last', 0, 'SCALAR(0x1048590)') called at /home/ponting/public/perl/lib/perl5/Date/Manip/Date.pm line 178 Date::Manip::Date::parse('Date::Manip::Date=HASH(0x13f6aa0)', '7pm last') called at /home/ponting/public/perl/lib/perl5/Date/Manip.pm line 135 Date::Manip::ParseDate('ARRAY(0xa7ab10)') called at /home/Research/ponting/topics/spider/testdate.pl line 13 ======================== Windows Vista ============================= I also tried the simple and fourfold versions on my Windows Vista Business ("Vista x64" "build 6002, Service Pack 2") system, with Date::Manip 5.54. The simple version correctly decides that it cannot parse the date, producing the output: Version: 5.54 failed to parse date In the fourfold version the above crash does not happen - instead it parses only the first component. The following was the output: Version: 5.54 7pm last Sunday 2010080119:00:00 7pm last Sunday. ARRAY(0x330103c) 2010080119:00:00 ARRAY(0x330134c) 2010080619:00:00 (I had to use the manual $TZ method of setting the time zone for Date::Manip 5.54, but that seems to have been sorted for version 6.11 tried below.) Perl version. This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 9 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall Binary build 1005 [290470] provided by ActiveState http://www.ActiveState.com Built May 24 2009 12:17:36 The ActiveState Perl Package Manager does not yet seem to know about version 6 of Date::Manip, so I tried pointing at my Linux installation over the network, but my script then fell over at the first hurdle, producing the following output from the simplest script: Version: 6.11 Not an ARRAY reference at m:/public/perl/lib/perl5/Date/Manip/Date.pm line 1352. The debugger may reveal something more: Not an ARRAY reference at m:/public/perl/lib/perl5/Date/Manip/Date.pm line 1352. at m:/public/perl/lib/perl5/Date/Manip/Date.pm line 1352 Date::Manip::Date::_other_rx('Date::Manip::Date=HASH(0x3eb9d6c)', 'miscdatetime') called at m:/public/perl/lib/perl5/Date/Manip/Date.pm line 1631 Date::Manip::Date::_parse_datetime_other('Date::Manip::Date=HASH(0x3eb9d6c)', '7pm last', 'SCALAR(0x3c8815c)') called at m:/public/perl/lib/perl5/Date/Manip/Date.pm line 141 Date::Manip::Date::parse('Date::Manip::Date=HASH(0x3eb9d6c)', '7pm last') called at m:/public/perl/lib/perl5/Date/Manip.pm line 135 Date::Manip::ParseDate('7pm last') called at m:/Research/ponting/topics/spider/testdate.pl line 7 Thankyou!!
The date you passed in was "7pm last", NOT "7pm last sunday". If the correct date string is passed in, it is parsed find. However, I have fixed the bug that allowed "7pm last" to cause an error instead of simply returning an empty string due to an unparseable date. It'll be in the next release.