sub isHoliday {
my ($self, $day, $month, $year) = @_;
# FIXME - date strings are stored in non-padded metric format. should change to iso.
- # FIXME - should change arguments to accept C4::Dates object
$month=$month+0;
$year=$year+0;
$day=$day+0;
my ($day, $month, $year) = $calendar->addDate($date, $offset)
-C<$date> is a C4::Dates object representing the starting date of the interval.
+C<$startdate> is the starting date of the interval.
C<$offset> Is the number of days that this function has to count from $date.
sub addDate {
my ($self, $startdate, $offset) = @_;
- my ($year,$month,$day) = split("-",$startdate->output('iso'));
+ $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
+ my ( $year, $month, $day) = split( "-", $startdate );
my $daystep = 1;
if ($offset < 0) { # In case $offset is negative
# $offset = $offset*(-1);
} else { ## ($daysMode eq 'Days')
($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
}
- return(C4::Dates->new( sprintf(ISO_DATE_FORMAT,$year,$month,$day),'iso'));
+ 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> are C4::Dates objects that define the interval.
+C<$startdate> and C<$enddate> define the interval.
Returns the number of non-holiday days in the interval.
useDaysMode syspref has no effect here.
my $self = shift or return;
my $startdate = shift or return;
my $enddate = shift or return;
- my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso'));
- my ($yearTo, $monthTo, $dayTo ) = split("-", $enddate->output('iso'));
+ $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 )
use DateTime;
use C4::Calendar;
+use Koha::DateUtils;
my $input = new CGI;
my $dbh = C4::Context->dbh();
my $day = $input->param('showDay');
my $month = $input->param('showMonth');
my $year = $input->param('showYear');
-my $day1;
-my $month1;
-my $year1;
my $title = $input->param('showTitle');
my $description = $input->param('showDescription');
my $holidaytype = $input->param('showHolidayType');
-my $datecancelrange = $input->param('datecancelrange');
+my $datecancelrange_dt = eval { dt_from_string( $input->param('datecancelrange') ) };
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
-my $isodate = C4::Dates->new($calendardate, 'iso');
-$calendardate = $isodate->output('syspref');
my $calendar = C4::Calendar->new(branchcode => $branchcode);
$description = '';
}
-# We format the date
-my @dateend = split(/[\/-]/, $datecancelrange);
-if (C4::Context->preference("dateformat") eq "metric") {
- $day1 = $dateend[0];
- $month1 = $dateend[1];
- $year1 = $dateend[2];
-}elsif (C4::Context->preference("dateformat") eq "us") {
- $month1 = $dateend[0];
- $day1 = $dateend[1];
- $year1 = $dateend[2];
-} else {
- $year1 = $dateend[0];
- $month1 = $dateend[1];
- $day1 = $dateend[2];
-}
-
# We make an array with holiday's days
my @holiday_list;
-if ($year1 && $month1 && $day1){
+if ($datecancelrange_dt){
my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
- my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
for (my $dt = $first_dt->clone();
- $dt <= $end_dt;
+ $dt <= $datecancelrange_dt;
$dt->add(days => 1) )
{
push @holiday_list, $dt->clone();
use C4::Branch; # GetBranches
use C4::Calendar;
+use Koha::DateUtils;
my $input = new CGI;
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'};
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;
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;
use Koha::Cache;
-use C4::Dates;
use C4::Calendar;
use DateTime;
+use Koha::DateUtils;
my $input = new CGI;
my $dbh = C4::Context->dbh();
our $day = $input->param('newDay');
our $month = $input->param('newMonth');
our $year = $input->param('newYear');
-my $day1;
-my $month1;
-my $year1;
my $dateofrange = $input->param('dateofrange');
our $title = $input->param('newTitle');
our $description = $input->param('newDescription');
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 @dateend = split(/[\/-]/, $dateofrange);
-if (C4::Context->preference("dateformat") eq "metric") {
- $day1 = $dateend[0];
- $month1 = $dateend[1];
- $year1 = $dateend[2];
-}elsif (C4::Context->preference("dateformat") eq "us") {
- $month1 = $dateend[0];
- $day1 = $dateend[1];
- $year1 = $dateend[2];
-} else {
- $year1 = $dateend[0];
- $month1 = $dateend[1];
- $day1 = $dateend[2];
-}
+
+my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
+my $end_dt = eval { dt_from_string( $dateofrange ); };
+
+my $calendardate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
+
$title || ($title = '');
if ($description) {
$description =~ s/\r/\\r/g;
# We make an array with holiday's days
our @holiday_list;
-if ($year1 && $month1 && $day1){
- my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
- my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
-
- for (my $dt = $first_dt->clone();
- $dt <= $end_dt;
- $dt->add(days => 1) )
- {
- push @holiday_list, $dt->clone();
- }
+if ($end_dt){
+ for (my $dt = $first_dt->clone();
+ $dt <= $end_dt;
+ $dt->add(days => 1) )
+ {
+ push @holiday_list, $dt->clone();
+ }
}
if($allbranches) {