From 857fea04ae6cb806b0e4eeaf1d175b7ef1c0071a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20V=C3=A9ron?= Date: Wed, 28 Oct 2015 23:51:45 +0100 Subject: [PATCH] Bug 14954: (followup) Remove C4::Dates from holiday related files 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 Signed-off-by: Mirko Tietgen Signed-off-by: Jonathan Druart Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com Signed-off-by: Tomas Cohen Arazi --- C4/Calendar.pm | 36 +----------------------------------- tools/holidays.pl | 15 +++++++-------- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/C4/Calendar.pm b/C4/Calendar.pm index bf3b96f28b..92eb6b3833 100644 --- a/C4/Calendar.pm +++ b/C4/Calendar.pm @@ -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__ diff --git a/tools/holidays.pl b/tools/holidays.pl index bec897dc3c..f1739bd77f 100755 --- a/tools/holidays.pl +++ b/tools/holidays.pl @@ -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; -- 2.39.5