Koha/t/lib/Dates.pm
Jonathan Druart ff82c9aadc Bug 19176: (QA follow-up) few cosmetic changes
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-11-03 13:50:27 -03:00

31 lines
647 B
Perl

package t::lib::Dates;
use Modern::Perl;
use Koha::DateUtils;
use DateTime;
=head1 NAME
t::lib::Dates.pm - test helper module for working with dates
=head1 METHODS
=head2 compare
compare( $got_dt, $expected_dt );
Will execute a test and compare the 2 dates given in parameters
The dates will be considered as identical if there are less than 5sec between them.
=cut
sub compare {
my ( $got, $expected ) = @_;
my $dt_got = dt_from_string($got);
my $dt_expected = dt_from_string($expected);
my $diff = $dt_got->epoch - $dt_expected->epoch;
if ( abs($diff) <= 5 ) { return 0 }
return $diff > 0 ? 1 : -1;
}
1;