From 0b92b75ff8720129006b05b278813300a3045625 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Mon, 12 May 2008 05:29:31 -0500 Subject: [PATCH] Alter C4::Calendar::daysBetween() to take C4::Dates objects. Signed-off-by: Joshua Ferraro --- C4/Calendar.pm | 54 ++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/C4/Calendar.pm b/C4/Calendar.pm index 8c22884007..f5ae57a23f 100644 --- a/C4/Calendar.pm +++ b/C4/Calendar.pm @@ -495,49 +495,33 @@ sub addDate { =item daysBetween - my $daysBetween = $calendar->daysBetween($dayFrom, $monthFrom, $yearFrom, - $dayTo, $monthTo, $yearTo) + my $daysBetween = $calendar->daysBetween($startdate, $enddate ) -C<$dayFrom> Is the starting day of the interval. - -C<$monthFrom> Is the starting month of the interval. - -C<$yearFrom> Is the starting year of the interval. - -C<$dayTo> Is the ending day of the interval. - -C<$monthTo> Is the ending month of the interval. - -C<$yearTo> Is the ending year of the interval. +C<$startdate> and C<$enddate> are C4::Dates objects that define the interval. +Returns the number of non-holiday days in the interval. +useDaysMode syspref has no effect here. =cut sub daysBetween { - my ($self, $dayFrom, $monthFrom, $yearFrom, $dayTo, $monthTo, $yearTo) = @_; - - my $daysMode = C4::Context->preference('useDaysMode'); -#FIXME : useDaysMode == 'Datedue' is not implemented here, but neither is this fcn used anywhere. - my $count = 1; + # my ($self, $dayFrom, $monthFrom, $yearFrom, $dayTo, $monthTo, $yearTo) = @_; + my ( $self, $startdate, $enddate ) = @_ ; + my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso')); + my ($yearTo,$monthTo,$dayTo) = split("-",$enddate->output('iso')); + if (($yearFrom >= $yearTo) && ($monthFrom >= $monthTo) && ($dayFrom >= $dayTo)) { + return 0; + # we don't go backwards ( FIXME - handle this error better ) + } + my $count = 0; my $continue = 1; - if ($daysMode eq 'Days') { - while ($continue) { - if (($yearFrom != $yearTo) || ($monthFrom != $monthTo) || ($dayFrom != $dayTo)) { - ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1); + while ($continue) { + if (($yearFrom != $yearTo) || ($monthFrom != $monthTo) || ($dayFrom != $dayTo)) { + if (!($self->isHoliday($dayFrom, $monthFrom, $yearFrom))) { $count++; - } else { - $continue = 0; - } - } - } else { - while ($continue) { - if (($yearFrom != $yearTo) || ($monthFrom != $monthTo) || ($dayFrom != $dayTo)) { - if (!($self->isHoliday($dayFrom, $monthFrom, $yearFrom))) { - $count++; - } - ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1); - } else { - $continue = 0; } + ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1); + } else { + $continue = 0; } } return($count); -- 2.39.5