-my $daycount = $cal->days_between( $test_dt, $later_dt );
-cmp_ok( $daycount->in_units('days'),
- '==', 48, 'days_between calculates correctly' );
-
-my $ret = $cal->addDate( $test_dt, 1, 'days' );
-
-cmp_ok( $ret->ymd(), 'eq', '2012-07-24', 'Simple Single Day Add (Calendar)' );
-
-$ret = $cal->addDate( $test_dt, 7, 'days' );
-cmp_ok( $ret->ymd(), 'eq', '2012-07-31', 'Add 7 days Calendar mode' );
-$cal->set_daysmode('Datedue');
-$ret = $cal->addDate( $test_dt, 7, 'days' );
-cmp_ok( $ret->ymd(), 'eq', '2012-07-30', 'Add 7 days Datedue mode' );
-$cal->set_daysmode('Days');
-$ret = $cal->addDate( $test_dt, 7, 'days' );
-cmp_ok( $ret->ymd(), 'eq', '2012-07-30', 'Add 7 days Days mode' );
-$cal->set_daysmode('Calendar');
-
-# example tests for bug report
-$cal->clear_weekly_closed_days();
-
-$daycount = $cal->days_between( dt_from_string('2012-01-10','iso'),
- dt_from_string("2012-05-05",'iso') )->in_units('days');
-cmp_ok( $daycount, '==', 116, 'test larger intervals' );
-$daycount = $cal->days_between( dt_from_string("2012-01-01",'iso'),
- dt_from_string("2012-05-05",'iso') )->in_units('days');
-cmp_ok( $daycount, '==', 125, 'test positive intervals' );
-my $daycount2 = $cal->days_between( dt_from_string("2012-05-05",'iso'),
- dt_from_string("2012-01-01",'iso') )->in_units('days');
-cmp_ok( $daycount2, '==', $daycount, 'test parameter order not relevant' );
-$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
- dt_from_string("2012-07-15",'iso') )->in_units('days');
-cmp_ok( $daycount, '==', 14, 'days_between calculates correctly' );
-$cal->add_holiday( dt_from_string('2012-07-06','iso') );
-$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
- dt_from_string("2012-07-15",'iso') )->in_units('days');
-cmp_ok( $daycount, '==', 13, 'holiday correctly recognized' );
-
-$cal->add_holiday( dt_from_string('2012-07-07','iso') );
-$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
- dt_from_string("2012-07-15",'iso') )->in_units('days');
-cmp_ok( $daycount, '==', 12, 'multiple holidays correctly recognized' );
+{ # Bugzilla #8966 - is_holiday truncates referenced date
+ my $later_dt = DateTime->new( # Monday
+ year => 2012,
+ month => 9,
+ day => 17,
+ hour => 17,
+ minute => 30,
+ time_zone => 'Europe/London',
+ );
+
+
+ is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' );
+ cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
+}
+
+
+{ # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
+ my $single_holiday_time = DateTime->new(
+ year => 2011,
+ month => 6,
+ day => 1,
+ hour => 11,
+ minute => 2
+ );
+
+ is( $cal->is_holiday($single_holiday_time),
+ $cal->is_holiday($single_holiday) ,
+ 'bz-8800 is_holiday should truncate the date for holiday validation' );
+}
+
+
+ my $one_day_dur = DateTime::Duration->new( days => 1 );
+ my $two_day_dur = DateTime::Duration->new( days => 2 );
+ my $seven_day_dur = DateTime::Duration->new( days => 7 );
+
+ my $dt = dt_from_string( '2012-07-03','iso' );
+ my $test_dt = DateTime->new( # Monday
+ year => 2012,
+ month => 7,
+ day => 23,
+ hour => 11,
+ minute => 53,
+ );
+
+ my $later_dt = DateTime->new( # Monday
+ year => 2012,
+ month => 9,
+ day => 17,
+ hour => 17,
+ minute => 30,
+ time_zone => 'Europe/London',
+ );
+
+
+{ ## 'Datedue' tests
+
+ $module_context->unmock('preference');
+ $module_context->mock(
+ 'preference',
+ sub {
+ return 'Datedue';
+ }
+ );
+ # rewind dbh session
+ $holidays_session->reset;
+
+
+ $cal = Koha::Calendar->new( branchcode => 'MPL' );
+
+ is($cal->addDate( $dt, $one_day_dur, 'days' ),
+ dt_from_string('2012-07-05','iso'),
+ 'Single day add (Datedue, matches holiday, shift)' );
+
+ is($cal->addDate( $dt, $two_day_dur, 'days' ),
+ dt_from_string('2012-07-05','iso'),
+ 'Two days add, skips holiday (Datedue)' );
+
+ cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
+ '2012-07-30T11:53:00',
+ 'Add 7 days (Datedue)' );
+
+ is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
+ 'addDate skips closed Sunday (Datedue)' );
+
+ is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
+ 'Negative call to addDate (Datedue)' );
+
+ ## Note that the days_between API says closed days are not considered.
+ ## This tests are here as an API test.
+ cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
+ '==', 40, 'days_between calculates correctly (Days)' );
+
+ cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
+ '==', 40, 'Test parameter order not relevant (Days)' );
+
+
+}
+
+
+{ ## 'Calendar' tests'
+
+ $module_context->unmock('preference');
+ $module_context->mock(
+ 'preference',
+ sub {
+ return 'Calendar';
+ }
+ );
+ # rewind dbh session
+ $holidays_session->reset;
+
+ $cal = Koha::Calendar->new( branchcode => 'MPL' );
+
+ $dt = dt_from_string('2012-07-03','iso');
+
+ is($cal->addDate( $dt, $one_day_dur, 'days' ),
+ dt_from_string('2012-07-05','iso'),
+ 'Single day add (Calendar)' );
+
+ cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
+ '2012-08-01T11:53:00',
+ 'Add 7 days (Calendar)' );
+
+ is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
+ 'addDate skips closed Sunday (Calendar)' );
+
+ is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
+ 'Negative call to addDate (Calendar)' );
+
+ cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
+ '==', 40, 'days_between calculates correctly (Calendar)' );
+
+ cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
+ '==', 40, 'Test parameter order not relevant (Calendar)' );
+}
+
+
+{ ## 'Days' tests
+ $module_context->unmock('preference');
+ $module_context->mock(
+ 'preference',
+ sub {
+ return 'Days';
+ }
+ );
+ # rewind dbh session
+ $holidays_session->reset;
+
+ $cal = Koha::Calendar->new( branchcode => 'MPL' );
+
+ $dt = dt_from_string('2012-07-03','iso');
+
+ is($cal->addDate( $dt, $one_day_dur, 'days' ),
+ dt_from_string('2012-07-04','iso'),
+ 'Single day add (Days)' );
+
+ cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ),'eq',
+ '2012-07-30T11:53:00',
+ 'Add 7 days (Days)' );
+
+ is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
+ 'addDate doesn\'t skip closed Sunday (Days)' );
+
+ is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
+ 'Negative call to addDate (Days)' );
+
+ ## Note that the days_between API says closed days are not considered.
+ ## This tests are here as an API test.
+ cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
+ '==', 40, 'days_between calculates correctly (Days)' );
+
+ cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
+ '==', 40, 'Test parameter order not relevant (Days)' );
+
+}
+
+} # End SKIP block