3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test
::More tests
=> 5;
21 use t
::lib
::TestBuilder
;
27 use_ok
('Koha::Calendar');
29 my $schema = Koha
::Database
->new->schema;
30 $schema->storage->txn_begin;
32 my $today = dt_from_string
();
33 my $holiday_dt = $today->clone;
34 $holiday_dt->add(days
=> 15);
36 Koha
::Caches
->get_instance()->flush_all();
38 my $builder = t
::lib
::TestBuilder
->new();
39 my $holiday = $builder->build({
40 source
=> 'SpecialHoliday',
43 day
=> $holiday_dt->day,
44 month
=> $holiday_dt->month,
45 year
=> $holiday_dt->year,
46 title
=> 'My holiday',
51 my $calendar = Koha
::Calendar
->new( branchcode
=> 'LIB1');
52 my $forwarded_dt = $calendar->days_forward($today, 10);
54 my $expected = $today->clone;
55 $expected->add(days
=> 10);
56 is
($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days');
58 $forwarded_dt = $calendar->days_forward($today, 20);
60 $expected->add(days
=> 11);
61 is
($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday');
63 $forwarded_dt = $calendar->days_forward($today, 0);
64 is
($forwarded_dt->ymd, $today->ymd, '0 day should return start dt');
66 $forwarded_dt = $calendar->days_forward($today, -2);
67 is
($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt');
69 $schema->storage->txn_rollback();