use Modern::Perl;

use C4::Context;
use Koha::Calendar;
use Koha::DateUtils;

use DateTime::Duration;
use Time::HiRes qw( gettimeofday );
my $dbh = C4::Context->dbh;
#$dbh->do(q|DELETE FROM special_holidays|);
my ( $branchcode ) = $dbh->selectrow_array(q|
    SELECT branchcode from branches LIMIT 1|);
my $sth = $dbh->prepare(q|
    INSERT INTO special_holidays(branchcode, day, month, year, title)
    VALUES(?, ?, ?, ?, ?)
|);
for my $year ( 2000 .. 2020 ) {
    say "inserting $year";
    for my $i ( 1 .. 20 ) {
        my $month = int(rand(12))+1;
        my $day = int(rand(28))+1;
        $sth->execute($branchcode, $day, $month, $year, "special holiday for $year-$month-$day");
    }
}


my $tomorrow = dt_from_string() + DateTime::Duration->new( days => 1 );
my $now = gettimeofday();
Koha::Calendar->new(branchcode => $branchcode)->is_holiday($tomorrow);
say gettimeofday - $now;
