Subject: | Problem with deltas dates with relative inline mode |
DateManip-5.44
perl v5.8.7
Linux 2.4.26-1-686-smp #1 SMP Sat May 1 19:17:11 EST 2004 i686 GNU/Linux
Problem: DateCalc function permit to use two formats of delta times:
$date = DateCalc("today","+ 2 business days",\$err);
or
$date = DateCalc("today","+ 2 days",\$err,2);
But the inline mode don't work:
-----------------------------------------------------------
$ perl -MDate::Manip -le '$x = DateCalc("09/29/2005","+ 6 days",\$err,2); print $x,"\n",$err'
2005100708:00:00
$ perl -MDate::Manip -le '$x = DateCalc("09/29/2005","+ 6 business days",\$err); print $x,"\n",$err'
2005100500:00:00
-----------------------------------------------------------
Even in localised enviroment:
-----------------------------------------------------------
$ perl -MDate::Manip -le 'Date_Init( "Language=Spanish", "DateFormat=non-US"); $x = DateCalc("29/09/2005", "+ 6 dias",\$err,2); print $x,"\n",$err'
2005100708:00:00
$ perl -MDate::Manip -le 'Date_Init( "Language=Spanish", "DateFormat=non-US"); $x = DateCalc("29/09/2005","+ 6 dias laborales",\$err); print $x,"\n",$err'
2005100500:00:00
-----------------------------------------------------------
The problem, I suspect, is into DateCalc routine.
It use $mode variable to indicate the mode (exact, business, etc) to calculate the offset of date.
The lines 1576-1583 call the correct subroutine to make the calc, but $mode is only changed if it is passed via argument to the DateCalc function, at lines 1527-1531.
If the user pass the mode into the delta time, $mode is not changed.
------------------------------------------------
Solution: (not tested with all combinations!)
Insert
$mode = $Curr{"Mode"};
after the line
} elsif ($tmp=&ParseDateDelta($D2)) {
because ParseDateDelta change $Curr{"Mode"}.