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

(-)a/t/db_dependent/Circulation/CalcDateDue.t (-2 / +49 lines)
Lines 3-9 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::NoWarnings;
5
use Test::NoWarnings;
6
use Test::More tests => 24;
6
use Test::More tests => 25;
7
use Test::MockModule;
7
use Test::MockModule;
8
use DBI;
8
use DBI;
9
use DateTime;
9
use DateTime;
Lines 494-496 is( Link Here
494
494
495
$cache->clear_from_cache($key);
495
$cache->clear_from_cache($key);
496
$schema->storage->txn_rollback;
496
$schema->storage->txn_rollback;
497
- 
497
498
subtest 'CalcDateDue does not crash when loan period lands on DST transition (Bug 39748)' => sub {
499
    plan tests => 2;
500
501
    my $schema = Koha::Database->new->schema;
502
    $schema->storage->txn_begin;
503
504
    my $mock_context = Test::MockModule->new('C4::Context');
505
    $mock_context->mock( 'tz', sub { DateTime::TimeZone->new( name => 'America/New_York' ) } );
506
507
    my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store;
508
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { dateexpiry => '2099-01-01' } } )->store;
509
    my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } )->store->itemtype;
510
511
    Koha::CirculationRules->set_rules(
512
        {
513
            categorycode => undef,
514
            itemtype     => $itemtype,
515
            branchcode   => $library->branchcode,
516
            rules        => {
517
                issuelength   => 21,
518
                renewalperiod => 21,
519
                lengthunit    => 'days',
520
                daysmode      => 'Days',
521
            }
522
        }
523
    );
524
525
    # Feb 15 2026 at 02:31 America/New_York + 21 days = March 8 2026 at 02:31
526
    # March 8 is the DST spring-forward day in America/New_York - clocks jump from 02:00 to 03:00
527
    my $dst_start = DateTime->new(
528
        year      => 2026,
529
        month     => 2,
530
        day       => 15,
531
        hour      => 2,
532
        minute    => 31,
533
        time_zone => 'America/New_York',
534
    );
535
536
    my $dst_date;
537
    eval { $dst_date = C4::Circulation::CalcDateDue( $dst_start, $itemtype, $library->branchcode, $patron ); };
538
    ok( !$@, 'CalcDateDue does not crash when due date lands in DST gap' );
539
    is( $dst_date->ymd, '2026-03-08', 'Due date is correctly March 8 despite spring forward through DST' );
540
541
    $mock_context->unmock('tz');
542
    $schema->storage->txn_rollback;
543
};
544

Return to bug 39748