View | Details | Raw Unified | Return to bug 17015
Collapse All | Expand All

(-)a/Koha/DiscreteCalendar.pm (+22 lines)
Lines 525-530 sub get_week_days_holidays { Link Here
525
    return @week_days;
525
    return @week_days;
526
}
526
}
527
527
528
sub has_business_days_between {
529
    my ( $self, $start_dt, $end_dt ) = @_;
530
531
    # Clone dates to avoid modifying originals
532
    my $current_date = $start_dt->clone->set_time_zone('floating');
533
    my $end_date     = $end_dt->clone->set_time_zone('floating');
534
535
    # Ensure start is before end
536
    if ( $current_date->compare($end_date) >= 0 ) {
537
        return 0;    # Same date or start after end
538
    }
539
540
    # Check each day between start and end (exclusive)
541
    $current_date->add( days => 1 );
542
    while ( $current_date->compare($end_date) < 0 ) {
543
        return 1 unless $self->is_holiday($current_date);
544
        $current_date->add( days => 1 );
545
    }
546
547
    return 0;    # No business days found
548
}
549
528
=head2 edit_holiday
550
=head2 edit_holiday
529
551
530
Modifies a date or a range of dates
552
Modifies a date or a range of dates
(-)a/t/db_dependent/DiscreteCalendar.t (-2 / +76 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 50;
21
use Test::More tests => 56;
22
use Test::MockModule;
22
use Test::MockModule;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
Lines 459-464 $calendar->copy_to_branch($branch2); Link Here
459
#Check if branch2 is also closed tomorrow after copying from branch1
459
#Check if branch2 is also closed tomorrow after copying from branch1
460
is($calendar2->is_opened($tomorrow), 0, "$branch2 close tomorrow after copying from $branch1");
460
is($calendar2->is_opened($tomorrow), 0, "$branch2 close tomorrow after copying from $branch1");
461
461
462
my $calendar3 = Koha::DiscreteCalendar->new( { branchcode => $branch1 } );
463
464
# Base date
465
my $monday    = dt_from_string('2026-06-01');    # Monday
466
my $tuesday   = dt_from_string('2026-06-02');    # Tuesday
467
my $wednesday = dt_from_string('2026-06-03');    # Wednesday
468
my $thursday  = dt_from_string('2026-06-04');    # Thursday
469
my $friday    = dt_from_string('2026-06-05');    # Friday
470
my $saturday  = dt_from_string('2026-06-06');    # Saturday
471
$sunday = dt_from_string('2026-06-07');          # Sunday
472
473
# Add holidays (exceptions = closed days)
474
$calendar3->edit_holiday(
475
    {
476
        title        => "Holiday",
477
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
478
        start_date   => $wednesday,
479
        end_date     => $wednesday,
480
    }
481
);
482
483
$calendar3->edit_holiday(
484
    {
485
        title        => "Holiday",
486
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
487
        start_date   => $saturday,
488
        end_date     => $saturday,
489
    }
490
);
491
492
$calendar3->edit_holiday(
493
    {
494
        title        => "Holiday ",
495
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
496
        start_date   => $sunday,
497
        end_date     => $sunday,
498
    }
499
);
500
501
# Test 1: Business day between two business days
502
is(
503
    $calendar->has_business_days_between( $monday, $wednesday ), 1,
504
    'Should find business day (Tuesday) between Monday and Wednesday'
505
);
506
507
# Test 2: No business days between consecutive business days
508
is(
509
    $calendar->has_business_days_between( $monday, $tuesday ), 0,
510
    'Should find no business days between consecutive days'
511
);
512
513
# Test 3: Holiday between two business days
514
is(
515
    $calendar->has_business_days_between( $tuesday, $thursday ), 0,
516
    'Should find no business days when only holiday (Wednesday) is between'
517
);
518
519
# Test 4: Multiple days with business days
520
is(
521
    $calendar->has_business_days_between( $monday, $friday ), 1,
522
    'Should find business days between Monday and Friday'
523
);
524
525
# Test 5: Only holidays between dates
526
is(
527
    $calendar->has_business_days_between( $friday, $sunday ), 0,
528
    'Should find no business days between Friday and Sunday (Saturday is holiday)'
529
);
530
531
# Test 6: Same date
532
is(
533
    $calendar->has_business_days_between( $monday, $monday ), 0,
534
    'Should find no business days between same date'
535
);
536
462
$schema->storage->txn_rollback;
537
$schema->storage->txn_rollback;
463
538
464
1;
539
1;
465
- 

Return to bug 17015