3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 6;
24 use t::lib::TestBuilder;
27 use DateTime::Duration;
31 use Koha::DateUtils qw( dt_from_string );
33 my $schema = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
35 $schema->storage->txn_begin;
37 my $today = dt_from_string();
38 my $holiday_dt = $today->clone;
39 $holiday_dt->add( days => 3 );
41 Koha::Caches->get_instance()->flush_all();
43 subtest 'Original tests from t' => sub {
45 # We need to mock the C4::Context->preference method for
46 # simplicity and re-usability of the session definition. Any
47 # syspref fits for syspref-agnostic tests.
48 my $module_context = Test::MockModule->new('C4::Context');
49 $module_context->mock(
56 my $mpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
57 my $cpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
58 my $rows = [ # add weekly holidays
59 { branchcode => $mpl, weekday => 0 }, # sundays
60 { branchcode => $mpl, weekday => 6 }, # saturdays
61 { branchcode => $mpl, day => 1, month => 1 }, # new year's day
62 { branchcode => $mpl, day => 25, month => 12 }, # chrismas
64 $schema->resultset('RepeatableHoliday')->delete_all;
65 $schema->resultset('RepeatableHoliday')->create( { %$_, description => q{} } ) for @$rows;
67 $rows = [ # exception holidays
68 { branchcode => $mpl, day => 11, month => 11, year => 2012, isexception => 1 }, # sunday exception
69 { branchcode => $mpl, day => 1, month => 6, year => 2011, isexception => 0 },
70 { branchcode => $mpl, day => 4, month => 7, year => 2012, isexception => 0 },
71 { branchcode => $cpl, day => 6, month => 8, year => 2012, isexception => 0 },
72 { branchcode => $mpl, day => 7, month => 7, year => 2012, isexception => 1 }, # holiday exception
73 { branchcode => $mpl, day => 7, month => 7, year => 2012, isexception => 0 }, # holiday
75 $schema->resultset('SpecialHoliday')->delete_all;
76 $schema->resultset('SpecialHoliday')->create( { %$_, description => q{} } ) for @$rows;
78 my $cache = Koha::Caches->get_instance();
79 $cache->clear_from_cache( $mpl . '_holidays' );
80 $cache->clear_from_cache( $cpl . '_holidays' );
82 # $mpl branch is arbitrary, is not used at all but is needed for initialization
83 my $cal = Koha::Calendar->new( branchcode => $mpl );
85 isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
87 my $saturday = DateTime->new(
93 my $sunday = DateTime->new(
99 my $monday = DateTime->new(
105 my $new_year = DateTime->new(
111 my $single_holiday = DateTime->new(
115 ); # should be a holiday
117 my $notspecial = DateTime->new(
121 ); # should NOT be a holiday
123 my $sunday_exception = DateTime->new(
129 my $day_after_christmas = DateTime->new(
133 ); # for testing negative addDuration
135 my $holiday_for_another_branch = DateTime->new(
138 day => 6, # This is a monday
141 my $holiday_excepted = DateTime->new(
144 day => 7, # Both a holiday and exception
147 { # Syspref-agnostic tests
148 is( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)' );
149 is( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)' );
150 is( $monday->day_of_week, 1, '\'$monday\' is actually a monday (1st day of week)' );
151 is( $cal->is_holiday($saturday), 1, 'Saturday is a closed day' );
152 is( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' );
153 is( $cal->is_holiday($monday), 0, 'Monday is not a closed day' );
154 is( $cal->is_holiday($new_year), 1, 'Month/Day closed day test (New year\'s day)' );
155 is( $cal->is_holiday($single_holiday), 1, 'Single holiday closed day test' );
156 is( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' );
157 is( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
159 $cal->is_holiday($holiday_for_another_branch), 0,
160 'Holiday defined for another branch should not be defined as an holiday'
162 is( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' );
165 { # Bugzilla #8966 - is_holiday truncates referenced date
166 my $later_dt = DateTime->new( # Monday
172 time_zone => 'Europe/London',
175 is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' );
176 cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
179 { # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
180 my $single_holiday_time = DateTime->new(
189 $cal->is_holiday($single_holiday_time),
190 $cal->is_holiday($single_holiday),
191 'bz-8800 is_holiday should truncate the date for holiday validation'
195 my $one_day_dur = DateTime::Duration->new( days => 1 );
196 my $two_day_dur = DateTime::Duration->new( days => 2 );
197 my $seven_day_dur = DateTime::Duration->new( days => 7 );
199 my $dt = dt_from_string( '2012-07-03', 'iso' ); #tuesday
201 my $test_dt = DateTime->new( # Monday
209 my $later_dt = DateTime->new( # Monday
215 time_zone => 'Europe/London',
220 $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Datedue' );
223 $cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
224 dt_from_string( '2012-07-05', 'iso' ),
225 'Single day add (Datedue, matches holiday, shift)'
229 $cal->addDuration( $dt, $two_day_dur, 'days' ),
230 dt_from_string( '2012-07-05', 'iso' ),
231 'Two days add, skips holiday (Datedue)'
235 $cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
236 '2012-07-30T11:53:00',
237 'Add 7 days (Datedue)'
241 $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
242 'addDuration skips closed Sunday (Datedue)'
246 $cal->addDuration( $day_after_christmas, -1, 'days' )->ymd(), '2012-12-24',
247 'Negative call to addDuration (Datedue)'
250 ## Note that the days_between API says closed days are not considered.
251 ## This tests are here as an API test.
253 $cal->days_between( $test_dt, $later_dt )->in_units('days'),
254 '==', 40, 'days_between calculates correctly (Days)'
258 $cal->days_between( $later_dt, $test_dt )->in_units('days'),
259 '==', 40, 'Test parameter order not relevant (Days)'
263 { ## 'Calendar' tests'
265 $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Calendar' );
267 $dt = dt_from_string( '2012-07-03', 'iso' );
270 $cal->addDuration( $dt, $one_day_dur, 'days' ),
271 dt_from_string( '2012-07-05', 'iso' ),
272 'Single day add (Calendar)'
276 $cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
277 '2012-08-01T11:53:00',
278 'Add 7 days (Calendar)'
282 $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
283 'addDuration skips closed Sunday (Calendar)'
287 $cal->addDuration( $day_after_christmas, -1, 'days' )->ymd(), '2012-12-24',
288 'Negative call to addDuration (Calendar)'
292 $cal->days_between( $test_dt, $later_dt )->in_units('days'),
293 '==', 40, 'days_between calculates correctly (Calendar)'
297 $cal->days_between( $later_dt, $test_dt )->in_units('days'),
298 '==', 40, 'Test parameter order not relevant (Calendar)'
304 $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Days' );
306 $dt = dt_from_string( '2012-07-03', 'iso' );
309 $cal->addDuration( $dt, $one_day_dur, 'days' ),
310 dt_from_string( '2012-07-04', 'iso' ),
311 'Single day add (Days)'
315 $cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
316 '2012-07-30T11:53:00',
321 $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
322 'addDuration doesn\'t skip closed Sunday (Days)'
326 $cal->addDuration( $day_after_christmas, -1, 'days' )->ymd(), '2012-12-25',
327 'Negative call to addDuration (Days)'
330 ## Note that the days_between API says closed days are not considered.
331 ## This tests are here as an API test.
333 $cal->days_between( $test_dt, $later_dt )->in_units('days'),
334 '==', 40, 'days_between calculates correctly (Days)'
338 $cal->days_between( $later_dt, $test_dt )->in_units('days'),
339 '==', 40, 'Test parameter order not relevant (Days)'
345 $cal = Koha::Calendar->new( branchcode => $cpl );
346 is( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
348 $cal->is_holiday($holiday_for_another_branch), 1,
349 'Holiday defined for CPL should be defined as an holiday'
353 subtest 'days_mode parameter' => sub {
356 t::lib::Mocks::mock_preference( 'useDaysMode', 'Days' );
358 $cal = Koha::Calendar->new( branchcode => $cpl, days_mode => 'Calendar' );
359 is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set| );
362 $cache->clear_from_cache( $mpl . '_holidays' );
363 $cache->clear_from_cache( $cpl . '_holidays' );
366 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
367 my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Calendar' );
368 my $holiday = $builder->build(
370 source => 'SpecialHoliday',
372 branchcode => $library->branchcode,
373 day => $holiday_dt->day,
374 month => $holiday_dt->month,
375 year => $holiday_dt->year,
376 title => 'My holiday',
382 subtest 'days_forward' => sub {
385 my $forwarded_dt = $calendar->days_forward( $today, 2 );
386 my $expected = $today->clone->add( days => 2 );
387 is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' );
389 $forwarded_dt = $calendar->days_forward( $today, 5 );
390 $expected = $today->clone->add( days => 6 );
392 $forwarded_dt->ymd, $expected->ymd,
393 'With holiday on the perioddays_forward should add 5 days + 1 day for holiday'
396 $forwarded_dt = $calendar->days_forward( $today, 0 );
397 is( $forwarded_dt->ymd, $today->ymd, '0 day should return start dt' );
399 $forwarded_dt = $calendar->days_forward( $today, -2 );
400 is( $forwarded_dt->ymd, $today->ymd, 'negative day should return start dt' );
403 subtest 'crossing_DST' => sub {
407 my $tz = DateTime::TimeZone->new( name => 'America/New_York' );
408 my $start_date = dt_from_string( "2016-03-09 02:29:00", undef, $tz );
409 my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz );
410 my $days_between = $calendar->days_between( $start_date, $end_date );
411 is( $days_between->delta_days, 298, "Days calculated correctly" );
412 $days_between = $calendar->days_between( $end_date, $start_date );
413 is( $days_between->delta_days, 298, "Swapping returns the same" );
414 my $hours_between = $calendar->hours_between( $start_date, $end_date );
416 $hours_between->delta_minutes,
418 "Hours (in minutes) calculated correctly"
422 subtest 'hours_between | days_between' => sub {
427 # Su Mo Tu We Th Fr Sa
430 # 10 11 12 13 14 15 16
431 # 17 18 19 20 21 22 23
432 # 24 25 26 27 28 29 30
434 my $now = dt_from_string('2019-11-05 12:34:56'); # Today is 2019 Nov 5th
435 my $nov_6 = dt_from_string('2019-11-06 12:34:56');
436 my $nov_7 = dt_from_string('2019-11-07 12:34:56');
437 my $nov_12 = dt_from_string('2019-11-12 12:34:56');
438 my $nov_13 = dt_from_string('2019-11-13 12:34:56');
439 my $nov_15 = dt_from_string('2019-11-15 12:34:56');
440 Time::Fake->offset( $now->epoch );
442 subtest 'No holiday' => sub {
446 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
447 my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
449 subtest 'Same hours' => sub {
453 # Between 5th and 6th
454 my $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours;
455 is( $diff_hours, 1 * 24, 'hours: 1 day, no holiday' );
456 my $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days;
457 is( $diff_days, 1, 'days: 1 day, no holiday' );
459 # Between 5th and 7th
460 $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
461 is( $diff_hours, 2 * 24, 'hours: 2 days, no holiday' );
462 $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days;
463 is( $diff_days, 2, 'days: 2 days, no holiday' );
465 # Between 5th and 12th
466 $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
467 is( $diff_hours, 7 * 24, 'hours: 7 days, no holiday' );
468 $diff_days = $calendar->days_between( $now, $nov_12 )->delta_days;
469 is( $diff_days, 7, 'days: 7 days, no holiday' );
471 # Between 5th and 15th
472 $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
473 is( $diff_hours, 10 * 24, 'hours: 10 days, no holiday' );
474 $diff_days = $calendar->days_between( $now, $nov_15 )->delta_days;
475 is( $diff_days, 10, 'days: 10 days, no holiday' );
478 subtest 'Different hours' => sub {
482 # Between 5th and 5th (Same day short hours loan)
483 my $diff_hours = $calendar->hours_between( $now, $now->clone->add( hours => 3 ) )->hours;
484 is( $diff_hours, 3, 'hours: 3 hours, no holidays' );
485 my $diff_days = $calendar->days_between( $now, $now->clone->add( hours => 3 ) )->delta_days;
486 is( $diff_days, 0, 'days: 3 hours, no holidays' );
488 # Between 5th and 6th
489 $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract( hours => 3 ) )->hours;
490 is( $diff_hours, 1 * 24 - 3, 'hours: 21 hours, no holidays' );
491 $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract( hours => 3 ) )->delta_days;
492 is( $diff_days, 1, 'days: 21 hours, no holidays' );
494 # Between 5th and 7th
495 $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract( hours => 3 ) )->hours;
496 is( $diff_hours, 2 * 24 - 3, 'hours: 45 hours, no holidays' );
497 $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract( hours => 3 ) )->delta_days;
498 is( $diff_days, 2, 'days: 45 hours, no holidays' );
500 # Between 5th and 12th
501 $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract( hours => 3 ) )->hours;
502 is( $diff_hours, 7 * 24 - 3, 'hours: 165 hours, no holidays' );
503 $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract( hours => 3 ) )->delta_days;
504 is( $diff_days, 7, 'days: 165 hours, no holidays' );
506 # Between 5th and 15th
507 $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract( hours => 3 ) )->hours;
508 is( $diff_hours, 10 * 24 - 3, 'hours: 237 hours, no holidays' );
509 $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract( hours => 3 ) )->delta_days;
510 is( $diff_days, 10, 'days: 237 hours, no holidays' );
514 subtest 'With holiday' => sub {
517 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
519 # Wednesdays are closed
520 my $dbh = C4::Context->dbh;
523 INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
524 VALUES ( ?, ?, NULL, NULL, ?, '' )
525 |, undef, $library->branchcode, 3, 'Closed on Wednesday'
528 my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
530 subtest 'Same hours' => sub {
533 my ( $diff_hours, $diff_days );
535 # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
536 $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours;
537 is( $diff_hours, 0 * 24, 'hours: 1 day, end_dt = holiday' ); # FIXME Is this really should be 0?
538 $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days;
539 is( $diff_days, 0, 'days: 1 day, end_dt = holiday' ); # FIXME Is this really should be 0?
541 # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
542 $diff_hours = $calendar->hours_between( $nov_6, $nov_7 )->hours;
543 is( $diff_hours, 0 * 24, 'hours: 1 day, start_dt = holiday' ); # FIXME Is this really should be 0?
544 $diff_days = $calendar->days_between( $nov_6, $nov_7 )->delta_days;
545 is( $diff_days, 0, 'days: 1 day, start_dt = holiday' ); # FIXME Is this really should be 0?
547 # Between 5th and 7th
548 $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
549 is( $diff_hours, 2 * 24 - 1 * 24, 'hours: 2 days, 1 holiday' );
550 $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days;
551 is( $diff_days, 2 - 1, 'days: 2 days, 1 holiday' );
553 # Between 5th and 12th
554 $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
555 is( $diff_hours, 7 * 24 - 1 * 24, 'hours: 7 days, 1 holiday' );
556 $diff_days = $calendar->days_between( $now, $nov_12 )->delta_days;
557 is( $diff_days, 7 - 1, 'day: 7 days, 1 holiday' );
559 # Between 5th and 13th
560 $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours;
561 is( $diff_hours, 8 * 24 - 2 * 24, 'hours: 8 days, 2 holidays' );
562 $diff_days = $calendar->days_between( $now, $nov_13 )->delta_days;
563 is( $diff_days, 8 - 2, 'days: 8 days, 2 holidays' );
565 # Between 5th and 15th
566 $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
567 is( $diff_hours, 10 * 24 - 2 * 24, 'hours: 10 days, 2 holidays' );
568 $diff_days = $calendar->days_between( $now, $nov_15 )->delta_days;
569 is( $diff_days, 10 - 2, 'days: 10 days, 2 holidays' );
572 subtest 'Different hours' => sub {
575 my ( $diff_hours, $diff_days );
577 # Between 5th and 5th (Same day short hours loan)
578 # No test - Tested above as 5th is an open day
580 # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
581 my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract( hours => 3 ) );
582 is( $duration->hours, abs( 0 * 24 - 3 ), 'hours: 21 hours, end_dt = holiday' )
583 ; # FIXME $duration->hours always return a abs
584 is( $duration->is_negative, 1, '? is negative ?' )
585 ; # FIXME Do really test for that case in our calls to hours_between?
586 $duration = $calendar->days_between( $now, $nov_6->clone->subtract( hours => 3 ) );
587 is( $duration->hours, abs(0), 'days: 21 hours, end_dt = holiday' ); # FIXME Is this correct?
589 # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
590 $duration = $calendar->hours_between( $nov_6, $nov_7->clone->subtract( hours => 3 ) );
591 is( $duration->hours, abs( 0 * 24 - 3 ), 'hours: 21 hours, start_dt = holiday' )
592 ; # FIXME $duration->hours always return a abs
593 is( $duration->is_negative, 1, '? is negative ?' )
594 ; # FIXME Do really test for that case in our calls to hours_between?
595 $duration = $calendar->days_between( $nov_6, $nov_7->clone->subtract( hours => 3 ) );
596 is( $duration->hours, abs(0), 'days: 21 hours, start_dt = holiday' ); # FIXME Is this correct?
598 # Between 5th and 7th
599 $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract( hours => 3 ) )->hours;
600 is( $diff_hours, 2 * 24 - 1 * 24 - 3, 'hours: 45 hours, 1 holiday' );
601 $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract( hours => 3 ) )->delta_days;
602 is( $diff_days, 2 - 1, 'days: 45 hours, 1 holiday' );
604 # Between 5th and 12th
605 $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract( hours => 3 ) )->hours;
606 is( $diff_hours, 7 * 24 - 1 * 24 - 3, 'hours: 165 hours, 1 holiday' );
607 $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract( hours => 3 ) )->delta_days;
608 is( $diff_days, 7 - 1, 'days: 165 hours, 1 holiday' );
610 # Between 5th and 13th
611 $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract( hours => 3 ) )->hours;
612 is( $diff_hours, 8 * 24 - 2 * 24 - 3, 'hours: 289 hours, 2 holidays ' );
613 $diff_days = $calendar->days_between( $now, $nov_13->clone->subtract( hours => 3 ) )->delta_days;
614 is( $diff_days, 8 - 1, 'days: 289 hours, 2 holidays' );
616 # Between 5th and 15th
617 $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract( hours => 3 ) )->hours;
618 is( $diff_hours, 10 * 24 - 2 * 24 - 3, 'hours: 237 hours, 2 holidays' );
619 $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract( hours => 3 ) )->delta_days;
620 is( $diff_days, 10 - 2, 'days: 237 hours, 2 holidays' );
628 subtest 'is_holiday' => sub {
631 subtest 'weekday holidays' => sub {
634 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
636 my $day = dt_from_string();
637 my $dow = scalar $day->day_of_week;
638 $dow = 0 if $dow == 7;
640 # Closed this day of the week
641 my $dbh = C4::Context->dbh;
644 INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
645 VALUES ( ?, ?, NULL, NULL, ?, '' )
646 |, undef, $library->branchcode, $dow, "TEST"
650 my $sth = $dbh->prepare("UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'");
651 for my $i ( 0 .. 6 ) {
652 my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
654 is( $calendar->is_holiday($day), 1, $day->day_name() . " works as a repeatable holiday" );
656 # Increment the date and holiday day
657 $day->add( days => 1 );
659 $dow = 0 if $dow == 7;
660 $sth->execute( $dow, $library->branchcode );
665 subtest 'get_push_amt' => sub {
668 t::lib::Mocks::mock_preference( 'useDaysMode', 'Dayweek' );
670 subtest 'weekday holidays' => sub {
673 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
675 my $day = dt_from_string();
676 my $dow = scalar $day->day_of_week;
677 $dow = 0 if $dow == 7;
679 # Closed this day of the week
680 my $dbh = C4::Context->dbh;
683 INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
684 VALUES ( ?, ?, NULL, NULL, ?, '' )
685 |, undef, $library->branchcode, $dow, "TEST"
689 my $sth = $dbh->prepare("UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'");
690 for my $i ( 0 .. 6 ) {
691 my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Dayweek' );
695 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
697 $npa = $calendar->next_open_days( $day, 0 );
701 die unless $@ eq "alarm\n"; # propagate unexpected errors
703 ok( 0, "next_push_amt succeeded for " . $day->day_name() . " weekday holiday" );
705 ok( $npa, "next_push_amt succeeded for " . $day->day_name() . " weekday holiday" );
708 # Increment the date and holiday day
709 $day->add( days => 1 );
711 $dow = 0 if $dow == 7;
712 $sth->execute( $dow, $library->branchcode );
717 $schema->storage->txn_rollback();