Koha/t/Test/Dates.t
Jonathan Druart f0e737f43a Bug 19176: Reduce the number of seconds to 5
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-30 14:55:18 -03:00

26 lines
1 KiB
Perl

use Modern::Perl;
use Test::More tests => 7;
use t::lib::Dates;
use Koha::DateUtils qw( dt_from_string );
my $date_1 = '2017-01-01 01:00:00';
my $date_2 = '2018-02-02 01:00:00';
my $dt_1 = dt_from_string($date_1);
my $dt_2 = dt_from_string($date_2);
is( t::lib::Dates::compare( $dt_1, $dt_2 ), -1, '2017 is before 2018' );
is( t::lib::Dates::compare( $dt_2, $dt_1 ), 1, '2018 is after 2017' );
is( t::lib::Dates::compare( $date_1, $date_2 ), -1, '2017 is before 2018 (strings comparison)' );
is( t::lib::Dates::compare( $date_2, $date_1 ), 1, '2018 is after 2017 (strings comparison)' );
my $dt_3 = $dt_1->clone->subtract( seconds => 5 );
is( t::lib::Dates::compare( $dt_1, $dt_3 ),
0, 'If there is less than 1min, the dates are considered identicals' );
is( t::lib::Dates::compare( $dt_3, $dt_1 ),
0, 'If there is less than 1min, the dates are considered identicals' );
$dt_1->set_time_zone('+0000');
$dt_3 = $dt_1->clone->set_time_zone('+0400');
is( t::lib::Dates::compare( $dt_1, $dt_3 ), -1, "Compare different timezones" );