Lines 1-7
Link Here
|
1 |
package t::lib::Dates; |
1 |
package t::lib::Dates; |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More; |
|
|
5 |
use Koha::DateUtils; |
4 |
use Koha::DateUtils; |
6 |
use DateTime; |
5 |
use DateTime; |
7 |
|
6 |
|
Lines 13-31
t::lib::Dates.pm - test helper module for working with dates
Link Here
|
13 |
|
12 |
|
14 |
=head2 compare |
13 |
=head2 compare |
15 |
|
14 |
|
16 |
compare( $got_dt, $expected_dt, $test_description ); |
15 |
compare( $got_dt, $expected_dt ); |
17 |
|
16 |
|
18 |
Will execute a test and compare the 2 dates given in parameters |
17 |
Will execute a test and compare the 2 dates given in parameters |
19 |
The date will be compared truncated to minutes |
18 |
The dates will be considered as identical if there are less than 5sec between them. |
20 |
|
19 |
|
21 |
=cut |
20 |
=cut |
22 |
|
21 |
|
23 |
sub compare { |
22 |
sub compare { |
24 |
my ( $got, $expected, $description ) = @_; |
23 |
my ( $got, $expected ) = @_; |
25 |
my $dt_got = dt_from_string($got); |
24 |
my $dt_got = dt_from_string($got); |
26 |
my $dt_expected = dt_from_string($expected); |
25 |
my $dt_expected = dt_from_string($expected); |
27 |
my $diff = $dt_got->epoch - $dt_expected->epoch; |
26 |
my $diff = $dt_got->epoch - $dt_expected->epoch; |
28 |
if ( abs($diff) < 6 ) { return 0 } |
27 |
if ( abs($diff) <= 5 ) { return 0 } |
29 |
return $diff > 0 ? 1 : -1; |
28 |
return $diff > 0 ? 1 : -1; |
30 |
} |
29 |
} |
31 |
|
30 |
|
32 |
- |
|
|