Bug 19176: Compare the number of seconds when comparing dates in tests
[koha.git] / t / lib / Dates.pm
blob1ba4d223bf059745bea5c96fd1547f64e70e534d
1 package t::lib::Dates;
3 use Modern::Perl;
4 use Test::More;
5 use Koha::DateUtils;
6 use DateTime;
7 =head2 compare
9 compare( $got_dt, $expected_dt, $test_description );
11 Will execute a test and compare the 2 dates given in parameters
12 The date will be compared truncated to minutes
14 =cut
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) < 60 ) { return 0 }
24 return $diff > 0 ? 1 : -1;