View | Details | Raw Unified | Return to bug 7477
Collapse All | Expand All

(-)a/C4/Calendar.pm (-42 / +10 lines)
Lines 582-618 sub copy_to_branch { Link Here
582
    return 1;
582
    return 1;
583
}
583
}
584
584
585
=head2 daysBetween
586
587
    my $daysBetween = $calendar->daysBetween($startdate, $enddate)
588
589
C<$startdate> and C<$enddate> are C4::Dates objects that define the interval.
590
591
Returns the number of non-holiday days in the interval.
592
useDaysMode syspref has no effect here.
593
=cut
594
595
sub daysBetween ($$$) {
596
    my $self      = shift or return undef;
597
    my $startdate = shift or return undef;
598
    my $enddate   = shift or return undef;
599
	my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso'));
600
	my ($yearTo,  $monthTo,  $dayTo  ) = split("-",  $enddate->output('iso'));
601
	if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
602
		return 0;
603
		# we don't go backwards  ( FIXME - handle this error better )
604
	}
605
    my $count = 0;
606
    while (1) {
607
        ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
608
        unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) {
609
            $count++;
610
        }
611
        ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1);
612
    }
613
    return($count);
614
}
615
616
=head2 addDate
585
=head2 addDate
617
586
618
    my ($day, $month, $year) = $calendar->addDate($date, $offset)
587
    my ($day, $month, $year) = $calendar->addDate($date, $offset)
Lines 660-675 Returns the number of non-holiday days in the interval. Link Here
660
useDaysMode syspref has no effect here.
629
useDaysMode syspref has no effect here.
661
=cut
630
=cut
662
631
663
sub daysBetween ($$$) {
632
sub daysBetween {
664
    my $self      = shift or return undef;
633
    my $self      = shift or return;
665
    my $startdate = shift or return undef;
634
    my $startdate = shift or return;
666
    my $enddate   = shift or return undef;
635
    my $enddate   = shift or return;
667
	my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso'));
636
    my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso'));
668
	my ($yearTo,  $monthTo,  $dayTo  ) = split("-",  $enddate->output('iso'));
637
    my ($yearTo,  $monthTo,  $dayTo  ) = split("-",  $enddate->output('iso'));
669
	if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
638
    if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
670
		return 0;
639
        return 0;
671
		# we don't go backwards  ( FIXME - handle this error better )
640
        # we don't go backwards  ( FIXME - handle this error better )
672
	}
641
    }
673
    my $count = 0;
642
    my $count = 0;
674
    while (1) {
643
    while (1) {
675
        ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
644
        ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
676
- 

Return to bug 7477