Bug 19176: Reduce the number of seconds to 5
[koha.git] / t / lib / Dates.pm
1 package t::lib::Dates;
2
3 use Modern::Perl;
4 use Test::More;
5 use Koha::DateUtils;
6 use DateTime;
7 =head2 compare
8
9   compare( $got_dt, $expected_dt, $test_description );
10
11 Will execute a test and compare the 2 dates given in parameters
12 The date will be compared truncated to minutes
13
14 =cut
15
16 sub compare {
17     my ( $got, $expected, $description ) = @_;
18     my $dt_got      = dt_from_string($got);
19     my $dt_expected = dt_from_string($expected);
20     $dt_got->set_time_zone('floating');
21     $dt_expected->set_time_zone('floating');
22     my $diff = $dt_got->epoch - $dt_expected->epoch;
23     if ( abs($diff) < 6 ) { return 0 }
24     return $diff > 0 ? 1 : -1;
25 }
26
27 1;