Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: dam+cpan [...] ktnx.net
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 6.07
Fixed in: (no value)



Subject: [patch] bad check for passing workday start in __calc_date_delta
Hi, The attached test.pl tries to calculate 2 business days after 2010-04-15 17:12 given a workday of 09:00-17:30. It fails because of what seems to be an unfinished copy&paste in workday boundary checks in __calc_date_delta. Because of this, the resulting date object has invalid hours and is ignored when an attempt is made to convert it into string. The attached patch fixes the check and adds a test about it. Please consider applying it in a later release. Thanks!
Subject: fix-Date-__calc_date_delta-cmp-day-beg.patch
# Description: fix bad comparison in Date::Mainp::Date::__calc_date_delta # the check whether we have passed before the working day start seems to have been copied from the check for overflowing the day end and variable names weren't changed. # Author: Damyan Ivanov <dmn@debian.org> # Bug-Debian: 577950 --- a/lib/Date/Manip/Date.pm +++ b/lib/Date/Manip/Date.pm @@ -2923,8 +2923,8 @@ sub __calc_date_delta { ($h,$mn,$s) = @{ $dmb->calc_time_time([$hbeg,$mbeg,$sbeg],$t2) }; } elsif ($h < $hbeg || - ($h == $hend && $mn < $mend) || - ($h == $hend && $mn == $mend && $s < $send)) { + ($h == $hbeg && $mn < $mbeg) || + ($h == $hbeg && $mn == $mbeg && $s < $sbeg)) { # We've gone back past the start of the business day. --- /dev/null +++ b/t/date.calc.date_delta_business.2.t @@ -0,0 +1,75 @@ +#!/usr/bin/perl -w + +require 5.010000; + +$runtests=shift(@ARGV); +if ( -f "t/test.pl" ) { + require "t/test.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "test.pl" ) { + require "test.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find test.pl\n"; +} + +unshift(@INC,$dir); +use Date::Manip::Date; + +sub test { + (@test)=@_; + + $err = $obj1->parse(shift(@test)); + return $$obj1{"err"} if ($err); + $err = $obj2->parse(shift(@test)); + return $$obj2{"err"} if ($err); + + my $obj3 = $obj1->calc($obj2,@test); + return if (! defined $obj3); + $ret = $obj3->value(); + return $ret; +} + +$obj1 = new Date::Manip::Date; +$obj1->config("forcedate","now,America/New_York"); +$obj1->config(qw(workdaybeg 09:00:00)); +$obj1->config(qw(workdayend 17:30:00)); +$obj2 = $obj1->new_delta(); + +$tests=" + +Wed Nov 20 1996 noon +business +0:5:0:0 + 1996112017:00:00 + +Wed Nov 20 1996 noon +business +3:7:0:0 + 1996112610:30:00 + +Mar 31 1997 16:59:59 +business + 1 sec + 1997033117:00:00 + +Apr 15 2010 17:12:00 +business + 2 days + 2010041917:12:00 + +"; + +print "calc (date,delta,business 09:00-17:30)...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: +
Subject: test.pl
#!/usr/bin/perl use strict; use warnings; use Date::Manip; Date_Init( "DateFormat=non-US", 'WorkDayBeg=09:00', 'WorkDayEnd=17:30', ); my $err; my $d = DateCalc( '15.04.2010 17:12', '+ 2 days', \$err, 2 ); print "($err)\n" if $err; print $d ? UnixDate($d, '%d.%m.%Y %T') : "Calculation failed\n";
Your analysis was correct, and I've applied the patch. It'll be fixed in the next release.