|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Copyright 2016 Koha Development Team |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Benchmark; |
| 22 |
|
| 23 |
use DateTime; |
| 24 |
use DateTime::Set; |
| 25 |
use DateTime::Event::Random; |
| 26 |
|
| 27 |
my $start = DateTime->new( year => 2020, month => 3 ); |
| 28 |
my $end = DateTime->new( year => 2020, month => 5 ); |
| 29 |
my $set = DateTime::Event::Random->new_cached( |
| 30 |
days => 5, |
| 31 |
start => $start, |
| 32 |
end => $end |
| 33 |
); |
| 34 |
|
| 35 |
my $exception_holidays = {}; |
| 36 |
my $iter = $set->iterator; |
| 37 |
while ( my $dt = $iter->next ) { |
| 38 |
$exception_holidays->{ $dt->ymd('') } = 1; |
| 39 |
} |
| 40 |
|
| 41 |
my $test_datetime = |
| 42 |
DateTime::Event::Random->datetime( start => $start, end => $end ); |
| 43 |
my $test_datestring = $test_datetime->ymd(''); |
| 44 |
|
| 45 |
my $time_set = sub { |
| 46 |
return $set->contains($test_datetime); |
| 47 |
|
| 48 |
}; |
| 49 |
|
| 50 |
my $time_hash = sub { |
| 51 |
return 1 if ( $exception_holidays->{$test_datestring} ); |
| 52 |
return 0; |
| 53 |
|
| 54 |
}; |
| 55 |
|
| 56 |
Benchmark::cmpthese( |
| 57 |
-10, |
| 58 |
{ |
| 59 |
'DateTime::Set' => $time_set, |
| 60 |
'hashref' => $time_hash, |
| 61 |
} |
| 62 |
); |