Bug 24161: Add the Koha::Acquisition::Order::Claim[s] classes
[koha.git] / t / lib / Dates.pm
blob66299d9eb12d60037923d92d4baac52866d45d7c
1 package t::lib::Dates;
3 use Modern::Perl;
4 use Koha::DateUtils;
5 use DateTime;
7 =head1 NAME
9 t::lib::Dates.pm - test helper module for working with dates
11 =head1 METHODS
13 =head2 compare
15 compare( $got_dt, $expected_dt );
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.
20 =cut
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;