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.


In reply to Re^3: DateTime::Span intersection inconsistencies by ikegami
in thread DateTime::Span intersection inconsistencies by mikeman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.