Bug 9302: Use patron-title.inc
[koha.git] / t / Test / Dates.t
blob4857e278c58b8b603f62c3474c5cd5b31cc43610
1 use Modern::Perl;
2 use Test::More tests => 8;
3 use t::lib::Dates;
4 use Koha::DateUtils qw( dt_from_string );
6 my $date_1 = '2017-01-01 01:00:00';
7 my $date_2 = '2018-02-02 01:00:00';
8 my $dt_1   = dt_from_string($date_1);
9 my $dt_2   = dt_from_string($date_2);
11 is( t::lib::Dates::compare( $dt_1, $dt_2 ), -1, '2017 is before 2018' );
12 is( t::lib::Dates::compare( $dt_2, $dt_1 ), 1,  '2018 is after 2017' );
14 is( t::lib::Dates::compare( $date_1, $date_2 ), -1, '2017 is before 2018 (strings comparison)' );
15 is( t::lib::Dates::compare( $date_2, $date_1 ), 1,  '2018 is after 2017 (strings comparison)' );
17 my $dt_3 = $dt_1->clone->subtract( seconds => 5 );
18 is( t::lib::Dates::compare( $dt_1, $dt_3 ),
19     0, 'If there is less than 1min, the dates are considered identicals' );
20 is( t::lib::Dates::compare( $dt_3, $dt_1 ),
21     0, 'If there is less than 1min, the dates are considered identicals' );
23 $dt_1 = DateTime->new(year => 2001, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => '+0000');
24 $dt_3 = DateTime->new(year => 2001, month => 1, day => 1, hour => 4, minute => 0, second => 0, time_zone => '+0400');
25 is( t::lib::Dates::compare( $dt_1, $dt_3 ), 0, 'Different timezone but same date/time' );
27 $dt_1 = DateTime->new(year => 2001, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => '+0000');
28 $dt_3 = DateTime->new(year => 2001, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => '+0400');
29 is( t::lib::Dates::compare( $dt_1, $dt_3 ), 1, 'Different timezone and different date/time' );