Bug 14954: (followup) Remove C4::Dates from holiday related files
authorMarc Véron <veron@veron.ch>
Wed, 28 Oct 2015 22:51:45 +0000 (23:51 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 18 Nov 2015 02:44:48 +0000 (23:44 -0300)
Followup for comment #10

To test:
- Go to Home > Tools > Calendar
- Add, edit, delete the different types of holidays and exceptions
- git grep 'C4::Calendar' and test such files
- git grep daysBetween to make sure that this sub is not used
- prove t/Calendar.t

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Calendar.pm
tools/holidays.pl

index bf3b96f..92eb6b3 100644 (file)
@@ -707,7 +707,7 @@ C<$offset> Is the number of days that this function has to count from $date.
 
 sub addDate {
     my ($self, $startdate, $offset) = @_;
-    $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
+    $startdate = eval { output_pref( { dt => $startdate, dateonly => 1, dateformat => 'iso' } ); };
     my ( $year, $month, $day) = split( "-", $startdate );
        my $daystep = 1;
        if ($offset < 0) { # In case $offset is negative
@@ -731,43 +731,9 @@ sub addDate {
         ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
     }
     my $date_ret = sprintf(ISO_DATE_FORMAT,$year,$month,$day);
-    $date_ret =  eval { output_pref( { dt => dt_from_string( $date_ret), dateonly => 1, dateformat => 'iso' } ); };
     return($date_ret);
 }
 
-=head2 daysBetween
-
-    my $daysBetween = $calendar->daysBetween($startdate, $enddate)
-
-C<$startdate> and C<$enddate> define the interval.
-
-Returns the number of non-holiday days in the interval.
-useDaysMode syspref has no effect here.
-=cut
-
-sub daysBetween {
-    my $self      = shift or return;
-    my $startdate = shift or return;
-    my $enddate   = shift or return;
-    $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
-    $enddate = eval { output_pref( { dt => dt_from_string( $enddate ), dateonly => 1, dateformat => 'iso' } ); };
-    my ( $yearFrom, $monthFrom, $dayFrom) = split( "-", $startdate);
-    my ( $yearTo,  $monthTo,  $dayTo  ) = split( "-",  $enddate);
-    if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
-        return 0;
-        # we don't go backwards  ( FIXME - handle this error better )
-    }
-    my $count = 0;
-    while (1) {
-        ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
-        unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) {
-            $count++;
-        }
-        ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1);
-    }
-    return($count);
-}
-
 1;
 
 __END__
index bec897d..f1739bd 100755 (executable)
@@ -41,14 +41,13 @@ my ($template, $loggedinuser, $cookie)
                              debug => 1,
                            });
 
-# keydate - date passed to calendar.js.  calendar.js does not process dashes within a date.
-my $keydate;
 # calendardate - date passed in url for human readability (syspref)
-my $calendardate;
-my $calendarinput_dt = eval { dt_from_string( $input->param('calendardate') ); } || dt_from_string;
 # if the url has an invalid date default to 'now.'
-$calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } );
-$keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } );
+my $calendarinput_dt = eval { dt_from_string( $input->param('calendardate') ); } || dt_from_string;
+my $calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } );
+
+# keydate - date passed to calendar.js.  calendar.js does not process dashes within a date.
+my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } );
 $keydate =~ s/-/\//g;
 
 my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
@@ -132,11 +131,11 @@ foreach my $yearMonthDay (keys %$exception_holidays) {
 my $single_holidays = $calendar->get_single_holidays();
 my @holidays;
 foreach my $yearMonthDay (keys %$single_holidays) {
-    my $holidaydate = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) };
+    my $holidaydate_dt = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) };
     my %holiday;
     %holiday = (KEY => $yearMonthDay,
                 DATE_SORT => $single_holidays->{$yearMonthDay}{date},
-                DATE => output_pref( { dt => $holidaydate, dateonly => 1, dateformat => 'iso' } ),
+                DATE => output_pref( { dt => $holidaydate_dt, dateonly => 1 } ),
                 TITLE => $single_holidays->{$yearMonthDay}{title},
                 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
     push @holidays, \%holiday;