Bug 19176: followup - fix POD in t/lib/Dates.pm
[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
8 =head1 NAME
9
10 t::lib::Dates.pm - test helper module for working with dates
11
12 =head1 METHODS
13
14 =head2 compare
15
16   compare( $got_dt, $expected_dt, $test_description );
17
18 Will execute a test and compare the 2 dates given in parameters
19 The date will be compared truncated to minutes
20
21 =cut
22
23 sub compare {
24     my ( $got, $expected, $description ) = @_;
25     my $dt_got      = dt_from_string($got);
26     my $dt_expected = dt_from_string($expected);
27     $dt_got->set_time_zone('floating');
28     $dt_expected->set_time_zone('floating');
29     my $diff = $dt_got->epoch - $dt_expected->epoch;
30     if ( abs($diff) < 6 ) { return 0 }
31     return $diff > 0 ? 1 : -1;
32 }
33
34 1;