Bug 23177: (QA follow-up) Move rollback to the end
[koha.git] / t / lib / Dates.pm
1 package t::lib::Dates;
2
3 use Modern::Perl;
4 use Koha::DateUtils;
5 use DateTime;
6
7 =head1 NAME
8
9 t::lib::Dates.pm - test helper module for working with dates
10
11 =head1 METHODS
12
13 =head2 compare
14
15   compare( $got_dt, $expected_dt );
16
17 Will execute a test and compare the 2 dates given in parameters
18 The dates will be considered as identical if there are less than 5sec between them.
19
20 =cut
21
22 sub compare {
23     my ( $got, $expected ) = @_;
24     my $dt_got      = dt_from_string($got);
25     my $dt_expected = dt_from_string($expected);
26     my $diff = $dt_got->epoch - $dt_expected->epoch;
27     if ( abs($diff) <= 5 ) { return 0 }
28     return $diff > 0 ? 1 : -1;
29 }
30
31 1;