Bug 12177 - Remove HTML from authorities.pl
[koha.git] / C4 / Calendar.pm
blob1e687db7aa247c39decf1f304c5aa10315df21dd
1 package C4::Calendar;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
18 use strict;
19 use warnings;
20 use vars qw($VERSION @EXPORT);
22 use Carp;
23 use Date::Calc qw( Date_to_Days Today);
25 use C4::Context;
27 use constant ISO_DATE_FORMAT => "%04d-%02d-%02d";
28 =head1 NAME
30 C4::Calendar::Calendar - Koha module dealing with holidays.
32 =head1 SYNOPSIS
34 use C4::Calendar::Calendar;
36 =head1 DESCRIPTION
38 This package is used to deal with holidays. Through this package, you can set
39 all kind of holidays for the library.
41 =head1 FUNCTIONS
43 =head2 new
45 $calendar = C4::Calendar->new(branchcode => $branchcode);
47 Each library branch has its own Calendar.
48 C<$branchcode> specifies which Calendar you want.
50 =cut
52 sub new {
53 my $classname = shift @_;
54 my %options = @_;
55 my $self = bless({}, $classname);
56 foreach my $optionName (keys %options) {
57 $self->{lc($optionName)} = $options{$optionName};
59 defined($self->{branchcode}) or croak "No branchcode argument to new. Should be C4::Calendar->new(branchcode => \$branchcode)";
60 $self->_init($self->{branchcode});
61 return $self;
64 sub _init {
65 my $self = shift @_;
66 my $branch = shift;
67 defined($branch) or die "No branchcode sent to _init"; # must test for defined here and above to allow ""
68 my $dbh = C4::Context->dbh();
69 my $repeatable = $dbh->prepare( 'SELECT *
70 FROM repeatable_holidays
71 WHERE ( branchcode = ? )
72 AND (ISNULL(weekday) = ?)' );
73 $repeatable->execute($branch,0);
74 my %week_days_holidays;
75 while (my $row = $repeatable->fetchrow_hashref) {
76 my $key = $row->{weekday};
77 $week_days_holidays{$key}{title} = $row->{title};
78 $week_days_holidays{$key}{description} = $row->{description};
80 $self->{'week_days_holidays'} = \%week_days_holidays;
82 $repeatable->execute($branch,1);
83 my %day_month_holidays;
84 while (my $row = $repeatable->fetchrow_hashref) {
85 my $key = $row->{month} . "/" . $row->{day};
86 $day_month_holidays{$key}{title} = $row->{title};
87 $day_month_holidays{$key}{description} = $row->{description};
88 $day_month_holidays{$key}{day} = sprintf("%02d", $row->{day});
89 $day_month_holidays{$key}{month} = sprintf("%02d", $row->{month});
91 $self->{'day_month_holidays'} = \%day_month_holidays;
93 my $special = $dbh->prepare( 'SELECT day, month, year, title, description
94 FROM special_holidays
95 WHERE ( branchcode = ? )
96 AND (isexception = ?)' );
97 $special->execute($branch,1);
98 my %exception_holidays;
99 while (my ($day, $month, $year, $title, $description) = $special->fetchrow) {
100 $exception_holidays{"$year/$month/$day"}{title} = $title;
101 $exception_holidays{"$year/$month/$day"}{description} = $description;
102 $exception_holidays{"$year/$month/$day"}{date} =
103 sprintf(ISO_DATE_FORMAT, $year, $month, $day);
105 $self->{'exception_holidays'} = \%exception_holidays;
107 $special->execute($branch,0);
108 my %single_holidays;
109 while (my ($day, $month, $year, $title, $description) = $special->fetchrow) {
110 $single_holidays{"$year/$month/$day"}{title} = $title;
111 $single_holidays{"$year/$month/$day"}{description} = $description;
112 $single_holidays{"$year/$month/$day"}{date} =
113 sprintf(ISO_DATE_FORMAT, $year, $month, $day);
115 $self->{'single_holidays'} = \%single_holidays;
116 return $self;
119 =head2 get_week_days_holidays
121 $week_days_holidays = $calendar->get_week_days_holidays();
123 Returns a hash reference to week days holidays.
125 =cut
127 sub get_week_days_holidays {
128 my $self = shift @_;
129 my $week_days_holidays = $self->{'week_days_holidays'};
130 return $week_days_holidays;
133 =head2 get_day_month_holidays
135 $day_month_holidays = $calendar->get_day_month_holidays();
137 Returns a hash reference to day month holidays.
139 =cut
141 sub get_day_month_holidays {
142 my $self = shift @_;
143 my $day_month_holidays = $self->{'day_month_holidays'};
144 return $day_month_holidays;
147 =head2 get_exception_holidays
149 $exception_holidays = $calendar->exception_holidays();
151 Returns a hash reference to exception holidays. This kind of days are those
152 which stands for a holiday, but you wanted to make an exception for this particular
153 date.
155 =cut
157 sub get_exception_holidays {
158 my $self = shift @_;
159 my $exception_holidays = $self->{'exception_holidays'};
160 return $exception_holidays;
163 =head2 get_single_holidays
165 $single_holidays = $calendar->get_single_holidays();
167 Returns a hash reference to single holidays. This kind of holidays are those which
168 happend just one time.
170 =cut
172 sub get_single_holidays {
173 my $self = shift @_;
174 my $single_holidays = $self->{'single_holidays'};
175 return $single_holidays;
178 =head2 insert_week_day_holiday
180 insert_week_day_holiday(weekday => $weekday,
181 title => $title,
182 description => $description);
184 Inserts a new week day for $self->{branchcode}.
186 C<$day> Is the week day to make holiday.
188 C<$title> Is the title to store for the holiday formed by $year/$month/$day.
190 C<$description> Is the description to store for the holiday formed by $year/$month/$day.
192 =cut
194 sub insert_week_day_holiday {
195 my $self = shift @_;
196 my %options = @_;
198 my $weekday = $options{weekday};
199 croak "Invalid weekday $weekday" unless $weekday =~ m/^[0-6]$/;
201 my $dbh = C4::Context->dbh();
202 my $insertHoliday = $dbh->prepare("insert into repeatable_holidays (id,branchcode,weekday,day,month,title,description) values ( '',?,?,NULL,NULL,?,? )");
203 $insertHoliday->execute( $self->{branchcode}, $weekday, $options{title}, $options{description});
204 $self->{'week_days_holidays'}->{$weekday}{title} = $options{title};
205 $self->{'week_days_holidays'}->{$weekday}{description} = $options{description};
206 return $self;
209 =head2 insert_day_month_holiday
211 insert_day_month_holiday(day => $day,
212 month => $month,
213 title => $title,
214 description => $description);
216 Inserts a new day month holiday for $self->{branchcode}.
218 C<$day> Is the day month to make the date to insert.
220 C<$month> Is month to make the date to insert.
222 C<$title> Is the title to store for the holiday formed by $year/$month/$day.
224 C<$description> Is the description to store for the holiday formed by $year/$month/$day.
226 =cut
228 sub insert_day_month_holiday {
229 my $self = shift @_;
230 my %options = @_;
232 my $dbh = C4::Context->dbh();
233 my $insertHoliday = $dbh->prepare("insert into repeatable_holidays (id,branchcode,weekday,day,month,title,description) values ('', ?, NULL, ?, ?, ?,? )");
234 $insertHoliday->execute( $self->{branchcode}, $options{day},$options{month},$options{title}, $options{description});
235 $self->{'day_month_holidays'}->{"$options{month}/$options{day}"}{title} = $options{title};
236 $self->{'day_month_holidays'}->{"$options{month}/$options{day}"}{description} = $options{description};
237 return $self;
240 =head2 insert_single_holiday
242 insert_single_holiday(day => $day,
243 month => $month,
244 year => $year,
245 title => $title,
246 description => $description);
248 Inserts a new single holiday for $self->{branchcode}.
250 C<$day> Is the day month to make the date to insert.
252 C<$month> Is month to make the date to insert.
254 C<$year> Is year to make the date to insert.
256 C<$title> Is the title to store for the holiday formed by $year/$month/$day.
258 C<$description> Is the description to store for the holiday formed by $year/$month/$day.
260 =cut
262 sub insert_single_holiday {
263 my $self = shift @_;
264 my %options = @_;
266 @options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o )
267 if $options{date} && !$options{day};
269 my $dbh = C4::Context->dbh();
270 my $isexception = 0;
271 my $insertHoliday = $dbh->prepare("insert into special_holidays (id,branchcode,day,month,year,isexception,title,description) values ('', ?,?,?,?,?,?,?)");
272 $insertHoliday->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description});
273 $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
274 $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
275 return $self;
278 =head2 insert_exception_holiday
280 insert_exception_holiday(day => $day,
281 month => $month,
282 year => $year,
283 title => $title,
284 description => $description);
286 Inserts a new exception holiday for $self->{branchcode}.
288 C<$day> Is the day month to make the date to insert.
290 C<$month> Is month to make the date to insert.
292 C<$year> Is year to make the date to insert.
294 C<$title> Is the title to store for the holiday formed by $year/$month/$day.
296 C<$description> Is the description to store for the holiday formed by $year/$month/$day.
298 =cut
300 sub insert_exception_holiday {
301 my $self = shift @_;
302 my %options = @_;
304 @options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o )
305 if $options{date} && !$options{day};
307 my $dbh = C4::Context->dbh();
308 my $isexception = 1;
309 my $insertException = $dbh->prepare("insert into special_holidays (id,branchcode,day,month,year,isexception,title,description) values ('', ?,?,?,?,?,?,?)");
310 $insertException->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description});
311 $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
312 $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
313 return $self;
316 =head2 ModWeekdayholiday
318 ModWeekdayholiday(weekday =>$weekday,
319 title => $title,
320 description => $description)
322 Modifies the title and description of a weekday for $self->{branchcode}.
324 C<$weekday> Is the title to update for the holiday.
326 C<$description> Is the description to update for the holiday.
328 =cut
330 sub ModWeekdayholiday {
331 my $self = shift @_;
332 my %options = @_;
334 my $dbh = C4::Context->dbh();
335 my $updateHoliday = $dbh->prepare("UPDATE repeatable_holidays SET title = ?, description = ? WHERE branchcode = ? AND weekday = ?");
336 $updateHoliday->execute( $options{title},$options{description},$self->{branchcode},$options{weekday});
337 $self->{'week_days_holidays'}->{$options{weekday}}{title} = $options{title};
338 $self->{'week_days_holidays'}->{$options{weekday}}{description} = $options{description};
339 return $self;
342 =head2 ModDaymonthholiday
344 ModDaymonthholiday(day => $day,
345 month => $month,
346 title => $title,
347 description => $description);
349 Modifies the title and description for a day/month holiday for $self->{branchcode}.
351 C<$day> The day of the month for the update.
353 C<$month> The month to be used for the update.
355 C<$title> The title to be updated for the holiday.
357 C<$description> The description to be update for the holiday.
359 =cut
361 sub ModDaymonthholiday {
362 my $self = shift @_;
363 my %options = @_;
365 my $dbh = C4::Context->dbh();
366 my $updateHoliday = $dbh->prepare("UPDATE repeatable_holidays SET title = ?, description = ? WHERE month = ? AND day = ? AND branchcode = ?");
367 $updateHoliday->execute( $options{title},$options{description},$options{month},$options{day},$self->{branchcode});
368 $self->{'day_month_holidays'}->{"$options{month}/$options{day}"}{title} = $options{title};
369 $self->{'day_month_holidays'}->{"$options{month}/$options{day}"}{description} = $options{description};
370 return $self;
373 =head2 ModSingleholiday
375 ModSingleholiday(day => $day,
376 month => $month,
377 year => $year,
378 title => $title,
379 description => $description);
381 Modifies the title and description for a single holiday for $self->{branchcode}.
383 C<$day> Is the day of the month to make the update.
385 C<$month> Is the month to make the update.
387 C<$year> Is the year to make the update.
389 C<$title> Is the title to update for the holiday formed by $year/$month/$day.
391 C<$description> Is the description to update for the holiday formed by $year/$month/$day.
393 =cut
395 sub ModSingleholiday {
396 my $self = shift @_;
397 my %options = @_;
399 my $dbh = C4::Context->dbh();
400 my $isexception = 0;
401 my $updateHoliday = $dbh->prepare("UPDATE special_holidays SET title = ?, description = ? WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?");
402 $updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception);
403 $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
404 $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
405 return $self;
408 =head2 ModExceptionholiday
410 ModExceptionholiday(day => $day,
411 month => $month,
412 year => $year,
413 title => $title,
414 description => $description);
416 Modifies the title and description for an exception holiday for $self->{branchcode}.
418 C<$day> Is the day of the month for the holiday.
420 C<$month> Is the month for the holiday.
422 C<$year> Is the year for the holiday.
424 C<$title> Is the title to be modified for the holiday formed by $year/$month/$day.
426 C<$description> Is the description to be modified for the holiday formed by $year/$month/$day.
428 =cut
430 sub ModExceptionholiday {
431 my $self = shift @_;
432 my %options = @_;
434 my $dbh = C4::Context->dbh();
435 my $isexception = 1;
436 my $updateHoliday = $dbh->prepare("UPDATE special_holidays SET title = ?, description = ? WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?");
437 $updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception);
438 $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
439 $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
440 return $self;
443 =head2 delete_holiday
445 delete_holiday(weekday => $weekday
446 day => $day,
447 month => $month,
448 year => $year);
450 Delete a holiday for $self->{branchcode}.
452 C<$weekday> Is the week day to delete.
454 C<$day> Is the day month to make the date to delete.
456 C<$month> Is month to make the date to delete.
458 C<$year> Is year to make the date to delete.
460 =cut
462 sub delete_holiday {
463 my $self = shift @_;
464 my %options = @_;
466 # Verify what kind of holiday that day is. For example, if it is
467 # a repeatable holiday, this should check if there are some exception
468 # for that holiday rule. Otherwise, if it is a regular holiday, it´s
469 # ok just deleting it.
471 my $dbh = C4::Context->dbh();
472 my $isSingleHoliday = $dbh->prepare("SELECT id FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
473 $isSingleHoliday->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
474 if ($isSingleHoliday->rows) {
475 my $id = $isSingleHoliday->fetchrow;
476 $isSingleHoliday->finish; # Close the last query
478 my $deleteHoliday = $dbh->prepare("DELETE FROM special_holidays WHERE id = ?");
479 $deleteHoliday->execute($id);
480 delete($self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"});
481 } else {
482 $isSingleHoliday->finish; # Close the last query
484 my $isWeekdayHoliday = $dbh->prepare("SELECT id FROM repeatable_holidays WHERE branchcode = ? AND weekday = ?");
485 $isWeekdayHoliday->execute($self->{branchcode}, $options{weekday});
486 if ($isWeekdayHoliday->rows) {
487 my $id = $isWeekdayHoliday->fetchrow;
488 $isWeekdayHoliday->finish; # Close the last query
490 my $updateExceptions = $dbh->prepare("UPDATE special_holidays SET isexception = 0 WHERE (WEEKDAY(CONCAT(special_holidays.year,'-',special_holidays.month,'-',special_holidays.day)) = ?) AND (branchcode = ?)");
491 $updateExceptions->execute($options{weekday}, $self->{branchcode});
492 $updateExceptions->finish; # Close the last query
494 my $deleteHoliday = $dbh->prepare("DELETE FROM repeatable_holidays WHERE id = ?");
495 $deleteHoliday->execute($id);
496 delete($self->{'week_days_holidays'}->{$options{weekday}});
497 } else {
498 $isWeekdayHoliday->finish; # Close the last query
500 my $isDayMonthHoliday = $dbh->prepare("SELECT id FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)");
501 $isDayMonthHoliday->execute($self->{branchcode}, $options{day}, $options{month});
502 if ($isDayMonthHoliday->rows) {
503 my $id = $isDayMonthHoliday->fetchrow;
504 $isDayMonthHoliday->finish;
505 my $updateExceptions = $dbh->prepare("UPDATE special_holidays SET isexception = 0 WHERE (special_holidays.branchcode = ?) AND (special_holidays.day = ?) and (special_holidays.month = ?)");
506 $updateExceptions->execute($self->{branchcode}, $options{day}, $options{month});
507 $updateExceptions->finish; # Close the last query
509 my $deleteHoliday = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (id = ?)");
510 $deleteHoliday->execute($id);
511 delete($self->{'day_month_holidays'}->{"$options{month}/$options{day}"});
515 return $self;
517 =head2 delete_holiday_range
519 delete_holiday_range(day => $day,
520 month => $month,
521 year => $year);
523 Delete a holiday range of dates for $self->{branchcode}.
525 C<$day> Is the day month to make the date to delete.
527 C<$month> Is month to make the date to delete.
529 C<$year> Is year to make the date to delete.
531 =cut
533 sub delete_holiday_range {
534 my $self = shift;
535 my %options = @_;
537 my $dbh = C4::Context->dbh();
538 my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
539 $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
542 =head2 delete_holiday_range_repeatable
544 delete_holiday_range_repeatable(day => $day,
545 month => $month);
547 Delete a holiday for $self->{branchcode}.
549 C<$day> Is the day month to make the date to delete.
551 C<$month> Is month to make the date to delete.
553 =cut
555 sub delete_holiday_range_repeatable {
556 my $self = shift;
557 my %options = @_;
559 my $dbh = C4::Context->dbh();
560 my $sth = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)");
561 $sth->execute($self->{branchcode}, $options{day}, $options{month});
564 =head2 delete_exception_holiday_range
566 delete_exception_holiday_range(weekday => $weekday
567 day => $day,
568 month => $month,
569 year => $year);
571 Delete a holiday for $self->{branchcode}.
573 C<$day> Is the day month to make the date to delete.
575 C<$month> Is month to make the date to delete.
577 C<$year> Is year to make the date to delete.
579 =cut
581 sub delete_exception_holiday_range {
582 my $self = shift;
583 my %options = @_;
585 my $dbh = C4::Context->dbh();
586 my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)");
587 $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
590 =head2 isHoliday
592 $isHoliday = isHoliday($day, $month $year);
594 C<$day> Is the day to check whether if is a holiday or not.
596 C<$month> Is the month to check whether if is a holiday or not.
598 C<$year> Is the year to check whether if is a holiday or not.
600 =cut
602 sub isHoliday {
603 my ($self, $day, $month, $year) = @_;
604 # FIXME - date strings are stored in non-padded metric format. should change to iso.
605 # FIXME - should change arguments to accept C4::Dates object
606 $month=$month+0;
607 $year=$year+0;
608 $day=$day+0;
609 my $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7;
610 my $weekDays = $self->get_week_days_holidays();
611 my $dayMonths = $self->get_day_month_holidays();
612 my $exceptions = $self->get_exception_holidays();
613 my $singles = $self->get_single_holidays();
614 if (defined($exceptions->{"$year/$month/$day"})) {
615 return 0;
616 } else {
617 if ((exists($weekDays->{$weekday})) ||
618 (exists($dayMonths->{"$month/$day"})) ||
619 (exists($singles->{"$year/$month/$day"}))) {
620 return 1;
621 } else {
622 return 0;
628 =head2 copy_to_branch
630 $calendar->copy_to_branch($target_branch)
632 =cut
634 sub copy_to_branch {
635 my ($self, $target_branch) = @_;
637 croak "No target_branch" unless $target_branch;
639 my $target_calendar = C4::Calendar->new(branchcode => $target_branch);
641 my ($y, $m, $d) = Today();
642 my $today = sprintf ISO_DATE_FORMAT, $y,$m,$d;
644 my $wdh = $self->get_week_days_holidays;
645 $target_calendar->insert_week_day_holiday( weekday => $_, %{ $wdh->{$_} } )
646 foreach keys %$wdh;
647 $target_calendar->insert_day_month_holiday(%$_)
648 foreach values %{ $self->get_day_month_holidays };
649 $target_calendar->insert_exception_holiday(%$_)
650 foreach grep { $_->{date} gt $today } values %{ $self->get_exception_holidays };
651 $target_calendar->insert_single_holiday(%$_)
652 foreach grep { $_->{date} gt $today } values %{ $self->get_single_holidays };
654 return 1;
657 =head2 addDate
659 my ($day, $month, $year) = $calendar->addDate($date, $offset)
661 C<$date> is a C4::Dates object representing the starting date of the interval.
663 C<$offset> Is the number of days that this function has to count from $date.
665 =cut
667 sub addDate {
668 my ($self, $startdate, $offset) = @_;
669 my ($year,$month,$day) = split("-",$startdate->output('iso'));
670 my $daystep = 1;
671 if ($offset < 0) { # In case $offset is negative
672 # $offset = $offset*(-1);
673 $daystep = -1;
675 my $daysMode = C4::Context->preference('useDaysMode');
676 if ($daysMode eq 'Datedue') {
677 ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
678 while ($self->isHoliday($day, $month, $year)) {
679 ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $daystep);
681 } elsif($daysMode eq 'Calendar') {
682 while ($offset != 0) {
683 ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $daystep);
684 if (!($self->isHoliday($day, $month, $year))) {
685 $offset = $offset - $daystep;
688 } else { ## ($daysMode eq 'Days')
689 ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
691 return(C4::Dates->new( sprintf(ISO_DATE_FORMAT,$year,$month,$day),'iso'));
694 =head2 daysBetween
696 my $daysBetween = $calendar->daysBetween($startdate, $enddate)
698 C<$startdate> and C<$enddate> are C4::Dates objects that define the interval.
700 Returns the number of non-holiday days in the interval.
701 useDaysMode syspref has no effect here.
702 =cut
704 sub daysBetween {
705 my $self = shift or return;
706 my $startdate = shift or return;
707 my $enddate = shift or return;
708 my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso'));
709 my ($yearTo, $monthTo, $dayTo ) = split("-", $enddate->output('iso'));
710 if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
711 return 0;
712 # we don't go backwards ( FIXME - handle this error better )
714 my $count = 0;
715 while (1) {
716 ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
717 unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) {
718 $count++;
720 ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1);
722 return($count);
727 __END__
729 =head1 AUTHOR
731 Koha Physics Library UNLP <matias_veleda@hotmail.com>
733 =cut