From 64316be30533f69136f3f386c236c9a974a3ffa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Sun, 4 Oct 2015 22:31:40 +0200 Subject: [PATCH] Bug 14954 - Remove C4::Dates from holiday related files in folder tools This patch removes C4::Dates from: Remove C4::Dates from: - tools/exceptionHolidays.pl - tools/holidays.pl - tools/newHolidays.pl To test: - Go to Home > Tools > Calendar - Add, edit, delete the different types of hilidays and exceptions --- tools/exceptionHolidays.pl | 5 +++-- tools/holidays.pl | 20 ++++++++------------ tools/newHolidays.pl | 6 +++--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl index 45e2208..325eee3 100755 --- a/tools/exceptionHolidays.pl +++ b/tools/exceptionHolidays.pl @@ -10,6 +10,7 @@ use C4::Output; use DateTime; use C4::Calendar; +use Koha::DateUtils; my $input = new CGI; my $dbh = C4::Context->dbh(); @@ -27,8 +28,8 @@ my $description = $input->param('showDescription'); my $holidaytype = $input->param('showHolidayType'); my $datecancelrange = $input->param('datecancelrange'); my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); -my $isodate = C4::Dates->new($calendardate, 'iso'); -$calendardate = $isodate->output('syspref'); +my $isodate = eval{ dt_from_string( $calendardate ); }; +$calendardate = output_pref( { dt => $isodate, dateonly => 1 } ); my $calendar = C4::Calendar->new(branchcode => $branchcode); diff --git a/tools/holidays.pl b/tools/holidays.pl index 4b0579a..bec897d 100755 --- a/tools/holidays.pl +++ b/tools/holidays.pl @@ -26,6 +26,7 @@ use C4::Output; use C4::Branch; # GetBranches use C4::Calendar; +use Koha::DateUtils; my $input = new CGI; @@ -44,15 +45,10 @@ my ($template, $loggedinuser, $cookie) my $keydate; # calendardate - date passed in url for human readability (syspref) my $calendardate; -my $today = C4::Dates->new(); -my $calendarinput = C4::Dates->new($input->param('calendardate')) || $today; +my $calendarinput_dt = eval { dt_from_string( $input->param('calendardate') ); } || dt_from_string; # if the url has an invalid date default to 'now.' -unless($calendardate = $calendarinput->output('syspref')) { - $calendardate = $today->output('syspref'); -} -unless($keydate = $calendarinput->output('iso')) { - $keydate = $today->output('iso'); -} +$calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } ); +$keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } ); $keydate =~ s/-/\//g; my $branch= $input->param('branch') || C4::Context->userenv->{'branch'}; @@ -123,11 +119,11 @@ foreach my $monthDay (keys %$day_month_holidays) { my $exception_holidays = $calendar->get_exception_holidays(); my @exception_holidays; foreach my $yearMonthDay (keys %$exception_holidays) { - my $exceptiondate = C4::Dates->new($exception_holidays->{$yearMonthDay}{date}, "iso"); + my $exceptiondate = eval { dt_from_string( $exception_holidays->{$yearMonthDay}{date} ) }; my %exception_holiday; %exception_holiday = (KEY => $yearMonthDay, DATE_SORT => $exception_holidays->{$yearMonthDay}{date}, - DATE => $exceptiondate->output("syspref"), + DATE => output_pref( { dt => $exceptiondate, dateonly => 1, dateformat => 'iso' } ), TITLE => $exception_holidays->{$yearMonthDay}{title}, DESCRIPTION => $exception_holidays->{$yearMonthDay}{description}); push @exception_holidays, \%exception_holiday; @@ -136,11 +132,11 @@ foreach my $yearMonthDay (keys %$exception_holidays) { my $single_holidays = $calendar->get_single_holidays(); my @holidays; foreach my $yearMonthDay (keys %$single_holidays) { - my $holidaydate = C4::Dates->new($single_holidays->{$yearMonthDay}{date}, "iso"); + my $holidaydate = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) }; my %holiday; %holiday = (KEY => $yearMonthDay, DATE_SORT => $single_holidays->{$yearMonthDay}{date}, - DATE => $holidaydate->output("syspref"), + DATE => output_pref( { dt => $holidaydate, dateonly => 1, dateformat => 'iso' } ), TITLE => $single_holidays->{$yearMonthDay}{title}, DESCRIPTION => $single_holidays->{$yearMonthDay}{description}); push @holidays, \%holiday; diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl index dec4b3b..883cb26 100755 --- a/tools/newHolidays.pl +++ b/tools/newHolidays.pl @@ -12,9 +12,9 @@ use C4::Output; use Koha::Cache; -use C4::Dates; use C4::Calendar; use DateTime; +use Koha::DateUtils; my $input = new CGI; my $dbh = C4::Context->dbh(); @@ -35,8 +35,8 @@ our $newoperation = $input->param('newOperation'); my $allbranches = $input->param('allBranches'); my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); -my $isodate = C4::Dates->new($calendardate, 'iso'); -$calendardate = $isodate->output('syspref'); +my $isodate = eval{ dt_from_string( $calendardate ); }; +$calendardate = output_pref( { dt => $isodate, dateonly => 1 } ); my @dateend = split(/[\/-]/, $dateofrange); if (C4::Context->preference("dateformat") eq "metric") { -- 1.7.10.4