From: | CARNIL [...] cpan.org |
Subject: | libdate-manip-perl: Date parsing: Fail to restore the previous values if we didn't get an entire date |
Hi
This bug has been forwarded from http://bugs.debian.org/805874
I'm full quoting it below. The code changed in meanwhile from version
6.47 a bit, but the behaviour is still present in 6.51. The reporter has
attached a small example to show the issue while parsing "-15 days".
-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->
Package: libdate-manip-perl
Version: 6.47-1
Severity: normal
Dear Maintainer,
*** Reporter, please consider answering these questions, where appropriate ***
* What led up to the situation?
Date parsing.
* What exactly did you do (or not do) that was effective (or
ineffective)?
Trying to parsing this string: "-15 days"
* What was the outcome of this action?
The "parse()" function in "Date.pm" fail.
* What outcome did you expect instead?
The date 15 days ago.
*** End of the template - remove these template lines ***
After a look in the wheezy source, the "$off" variable is not reset in
the jessie source.
I have copy/paste the "missing" line , and now its work:
# Restore the previous values if we didn't get an
# entire date.
$string = $string_bak;
($tzstring,$zone,$abb,$off) = ();
A small Perl source for reproduce this small bug:
#!/usr/bin/perl -w
use strict;
use warnings;
use Date::Manip;
use POSIX;
# From zoneminder source:
#
# More or less replicates the equivalent PHP function
#
sub strtotime
{
my $dt_str = shift;
return( UnixDate( $dt_str, '%s' ) );
}
# Formats a date into MySQL format
sub DateTimeToSQL
{
my $dt_str = shift;
my $dt_val = strtotime( $dt_str );
if ( !$dt_val )
{
warn( "Unable to parse date string '$dt_str'\n" );
return( undef );
}
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
}
my $date = '-15 days';
my $value;
$value = DateTimeToSQL( $date );
if ( !$value ) {
print "Error!\n";
}
else {
print "Value: " ,$value , "\n";
}
# ----------------
# EOF
-- System Information:
Debian Release: 8.2
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.16.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages libdate-manip-perl depends on:
ii perl 5.20.2-3+deb8u1
libdate-manip-perl recommends no packages.
libdate-manip-perl suggests no packages.
-- no debconf information
<--<--<--<--<--<--<--<--<--<--<--<--<--<--<--<--<--<--<--<--
Thanks in advance,
Salvatore Bonaccorso, Debian Perl Group