|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 6; |
20 |
use Test::More tests => 3; |
| 21 |
use t::lib::TestBuilder; |
21 |
use t::lib::TestBuilder; |
| 22 |
|
22 |
|
| 23 |
use DateTime; |
23 |
use DateTime; |
|
Lines 31-85
$schema->storage->txn_begin;
Link Here
|
| 31 |
|
31 |
|
| 32 |
my $today = dt_from_string(); |
32 |
my $today = dt_from_string(); |
| 33 |
my $holiday_dt = $today->clone; |
33 |
my $holiday_dt = $today->clone; |
| 34 |
$holiday_dt->add(days => 15); |
34 |
$holiday_dt->add(days => 3); |
| 35 |
|
35 |
|
| 36 |
Koha::Caches->get_instance()->flush_all(); |
36 |
Koha::Caches->get_instance()->flush_all(); |
| 37 |
|
37 |
|
| 38 |
my $builder = t::lib::TestBuilder->new(); |
38 |
my $builder = t::lib::TestBuilder->new(); |
| 39 |
my $holiday = $builder->build({ |
39 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
| 40 |
source => 'SpecialHoliday', |
40 |
my $holiday = $builder->build( |
| 41 |
value => { |
41 |
{ |
| 42 |
branchcode => 'LIB1', |
42 |
source => 'SpecialHoliday', |
| 43 |
day => $holiday_dt->day, |
43 |
value => { |
| 44 |
month => $holiday_dt->month, |
44 |
branchcode => $library->branchcode, |
| 45 |
year => $holiday_dt->year, |
45 |
day => $holiday_dt->day, |
| 46 |
title => 'My holiday', |
46 |
month => $holiday_dt->month, |
| 47 |
isexception => 0 |
47 |
year => $holiday_dt->year, |
| 48 |
}, |
48 |
title => 'My holiday', |
| 49 |
}); |
49 |
isexception => 0 |
| 50 |
|
50 |
}, |
| 51 |
my $calendar = Koha::Calendar->new( branchcode => 'LIB1'); |
51 |
} |
| 52 |
my $forwarded_dt = $calendar->days_forward($today, 10); |
52 |
); |
| 53 |
|
53 |
|
| 54 |
my $expected = $today->clone; |
54 |
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); |
| 55 |
$expected->add(days => 10); |
55 |
|
| 56 |
is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days'); |
56 |
subtest 'days_forward' => sub { |
| 57 |
|
57 |
|
| 58 |
$forwarded_dt = $calendar->days_forward($today, 20); |
58 |
plan tests => 4; |
| 59 |
|
59 |
my $forwarded_dt = $calendar->days_forward( $today, 2 ); |
| 60 |
$expected->add(days => 11); |
60 |
my $expected = $today->clone->add( days => 2 ); |
| 61 |
is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday'); |
61 |
is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' ); |
| 62 |
|
62 |
|
| 63 |
$forwarded_dt = $calendar->days_forward($today, 0); |
63 |
$forwarded_dt = $calendar->days_forward( $today, 5 ); |
| 64 |
is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt'); |
64 |
$expected = $today->clone->add( days => 6 ); |
| 65 |
|
65 |
is( $forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 5 days + 1 day for holiday' |
| 66 |
$forwarded_dt = $calendar->days_forward($today, -2); |
66 |
); |
| 67 |
is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt'); |
67 |
|
|
|
68 |
$forwarded_dt = $calendar->days_forward( $today, 0 ); |
| 69 |
is( $forwarded_dt->ymd, $today->ymd, '0 day should return start dt' ); |
| 70 |
|
| 71 |
$forwarded_dt = $calendar->days_forward( $today, -2 ); |
| 72 |
is( $forwarded_dt->ymd, $today->ymd, 'negative day should return start dt' ); |
| 73 |
}; |
| 68 |
|
74 |
|
| 69 |
subtest 'crossing_DST' => sub { |
75 |
subtest 'crossing_DST' => sub { |
| 70 |
|
76 |
|
| 71 |
plan tests => 3; |
77 |
plan tests => 3; |
| 72 |
|
78 |
|
| 73 |
my $tz = DateTime::TimeZone->new( name => 'America/New_York' ); |
79 |
my $tz = DateTime::TimeZone->new( name => 'America/New_York' ); |
| 74 |
my $start_date = dt_from_string( "2016-03-09 02:29:00",undef,$tz ); |
80 |
my $start_date = dt_from_string( "2016-03-09 02:29:00", undef, $tz ); |
| 75 |
my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz ); |
81 |
my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz ); |
| 76 |
my $days_between = $calendar->days_between($start_date,$end_date); |
82 |
my $days_between = $calendar->days_between( $start_date, $end_date ); |
| 77 |
is( $days_between->delta_days, 298, "Days calculated correctly" ); |
83 |
is( $days_between->delta_days, 298, "Days calculated correctly" ); |
| 78 |
$days_between = $calendar->days_between($end_date,$start_date); |
84 |
$days_between = $calendar->days_between( $end_date, $start_date ); |
| 79 |
is( $days_between->delta_days, 298, "Swapping returns the same" ); |
85 |
is( $days_between->delta_days, 298, "Swapping returns the same" ); |
| 80 |
my $hours_between = $calendar->hours_between($start_date,$end_date); |
86 |
my $hours_between = $calendar->hours_between( $start_date, $end_date ); |
| 81 |
is( $hours_between->delta_minutes, 298 * 24 * 60 - 149, "Hours (in minutes) calculated correctly" ); |
87 |
is( |
| 82 |
|
88 |
$hours_between->delta_minutes, |
|
|
89 |
298 * 24 * 60 - 149, |
| 90 |
"Hours (in minutes) calculated correctly" |
| 91 |
); |
| 83 |
}; |
92 |
}; |
| 84 |
|
93 |
|
| 85 |
$schema->storage->txn_rollback(); |
94 |
$schema->storage->txn_rollback(); |
| 86 |
- |
|
|