Which test?
I only investigated the failing test, #5.
Note that the end time and duration of each span is the same.
That could indicate a problem with test #2 or the possibility for confusion in reading the code for test #2.
There's no problem with test #2 because the docs clearly show one should use before instead of end if you want test #2 to be consistent with test #5.
Fixed test:
use strict;
use warnings;
use DateTime;
use DateTime::Span;
use Test::More tests => 6;
my $dt1 = DateTime->new(
day => 1, month => 1, year => 2011,
hour => 12, minute => 0, second => 0,
);
my $dt2 = $dt1->clone->add( hours => 1 );
my $duration = DateTime::Duration->new( hours => 1 );
{
my $span = DateTime::Span->from_datetimes(
start => $dt1,
before => $dt2,
);
diag $span->start->datetime();
diag $span->end->datetime();
ok( $span->intersects( $dt1 ),
'Span intersects $dt1'
);
ok( !$span->intersects( $dt2 ),
'Span doesn\'t intersects $dt2'
);
is( DateTime::Duration->compare( $span->duration, $duration ), 0,
'Duration is 1 hour'
);
}
{
my $span = DateTime::Span->from_datetime_and_duration(
start => $dt1,
duration => $duration,
);
diag $span->start->datetime();
diag $span->end->datetime();
ok( $span->intersects( $dt1 ),
'Span intersects $dt1'
);
ok( !$span->intersects( $dt2 ),
'Span doesn\'t intersects $dt2'
);
is( DateTime::Duration->compare( $span->duration, $duration ), 0,
'Duration is 1 hour'
);
}
1;
1..6
# 2011-01-01T12:00:00
# 2011-01-01T13:00:00
ok 1 - Span intersects $dt1
ok 2 - Span doesn't intersects $dt2
ok 3 - Duration is 1 hour
# 2011-01-01T12:00:00
# 2011-01-01T13:00:00
ok 4 - Span intersects $dt1
ok 5 - Span doesn't intersects $dt2
ok 6 - Duration is 1 hour
PS - I used ok instead of is because intersects is documented to return a boolean, not zero or one.
|