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

(-)a/C4/Calendar.pm (-35 / +1 lines)
Lines 707-713 C<$offset> Is the number of days that this function has to count from $date. Link Here
707
707
708
sub addDate {
708
sub addDate {
709
    my ($self, $startdate, $offset) = @_;
709
    my ($self, $startdate, $offset) = @_;
710
    $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
710
    $startdate = eval { output_pref( { dt => $startdate, dateonly => 1, dateformat => 'iso' } ); };
711
    my ( $year, $month, $day) = split( "-", $startdate );
711
    my ( $year, $month, $day) = split( "-", $startdate );
712
	my $daystep = 1;
712
	my $daystep = 1;
713
	if ($offset < 0) { # In case $offset is negative
713
	if ($offset < 0) { # In case $offset is negative
Lines 731-773 sub addDate { Link Here
731
        ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
731
        ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
732
    }
732
    }
733
    my $date_ret = sprintf(ISO_DATE_FORMAT,$year,$month,$day);
733
    my $date_ret = sprintf(ISO_DATE_FORMAT,$year,$month,$day);
734
    $date_ret =  eval { output_pref( { dt => dt_from_string( $date_ret), dateonly => 1, dateformat => 'iso' } ); };
735
    return($date_ret);
734
    return($date_ret);
736
}
735
}
737
736
738
=head2 daysBetween
739
740
    my $daysBetween = $calendar->daysBetween($startdate, $enddate)
741
742
C<$startdate> and C<$enddate> define the interval.
743
744
Returns the number of non-holiday days in the interval.
745
useDaysMode syspref has no effect here.
746
=cut
747
748
sub daysBetween {
749
    my $self      = shift or return;
750
    my $startdate = shift or return;
751
    my $enddate   = shift or return;
752
    $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
753
    $enddate = eval { output_pref( { dt => dt_from_string( $enddate ), dateonly => 1, dateformat => 'iso' } ); };
754
    my ( $yearFrom, $monthFrom, $dayFrom) = split( "-", $startdate);
755
    my ( $yearTo,  $monthTo,  $dayTo  ) = split( "-",  $enddate);
756
    if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
757
        return 0;
758
        # we don't go backwards  ( FIXME - handle this error better )
759
    }
760
    my $count = 0;
761
    while (1) {
762
        ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
763
        unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) {
764
            $count++;
765
        }
766
        ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1);
767
    }
768
    return($count);
769
}
770
771
1;
737
1;
772
738
773
__END__
739
__END__
(-)a/tools/holidays.pl (-9 / +7 lines)
Lines 41-54 my ($template, $loggedinuser, $cookie) Link Here
41
                             debug => 1,
41
                             debug => 1,
42
                           });
42
                           });
43
43
44
# keydate - date passed to calendar.js.  calendar.js does not process dashes within a date.
45
my $keydate;
46
# calendardate - date passed in url for human readability (syspref)
44
# calendardate - date passed in url for human readability (syspref)
47
my $calendardate;
48
my $calendarinput_dt = eval { dt_from_string( $input->param('calendardate') ); } || dt_from_string;
49
# if the url has an invalid date default to 'now.'
45
# if the url has an invalid date default to 'now.'
50
$calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } );
46
my $calendarinput_dt = eval { dt_from_string( $input->param('calendardate') ); } || dt_from_string;
51
$keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } );
47
my $calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } );
48
49
# keydate - date passed to calendar.js.  calendar.js does not process dashes within a date.
50
my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } );
52
$keydate =~ s/-/\//g;
51
$keydate =~ s/-/\//g;
53
52
54
my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
53
my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
Lines 132-142 foreach my $yearMonthDay (keys %$exception_holidays) { Link Here
132
my $single_holidays = $calendar->get_single_holidays();
131
my $single_holidays = $calendar->get_single_holidays();
133
my @holidays;
132
my @holidays;
134
foreach my $yearMonthDay (keys %$single_holidays) {
133
foreach my $yearMonthDay (keys %$single_holidays) {
135
    my $holidaydate = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) };
134
    my $holidaydate_dt = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) };
136
    my %holiday;
135
    my %holiday;
137
    %holiday = (KEY => $yearMonthDay,
136
    %holiday = (KEY => $yearMonthDay,
138
                DATE_SORT => $single_holidays->{$yearMonthDay}{date},
137
                DATE_SORT => $single_holidays->{$yearMonthDay}{date},
139
                DATE => output_pref( { dt => $holidaydate, dateonly => 1, dateformat => 'iso' } ),
138
                DATE => output_pref( { dt => $holidaydate_dt, dateonly => 1 } ),
140
                TITLE => $single_holidays->{$yearMonthDay}{title},
139
                TITLE => $single_holidays->{$yearMonthDay}{title},
141
                DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
140
                DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
142
    push @holidays, \%holiday;
141
    push @holidays, \%holiday;
143
- 

Return to bug 14954