On Tue, 31 Mar 2009, Terrence Brannon wrote:
Intuitively, it would seem that specifying the 'before' of a datetime
span using the end option of the ->from_datetimes() constructor would
yield a range that is 1 second (1 nanosecond?) earlier than the actual
date supplied.
But as it is stands, the end of a range specified using the 'before'
option is the same as one specified using the 'end' option:
use strict; use warnings;
use DateTime;
use DateTime::Span;
my $dt1 = DateTime->new( year => 2002, month => 3, day => 11 );
my $dt2 = DateTime->new( year => 2003, month => 4, day => 12 );
my $span = DateTime::Span->from_datetimes( start => $dt1, before => $dt2 );
warn 'start: ' . $span->start . ' end: ' . $span->end;
my $span = DateTime::Span->from_datetimes( start => $dt1, end => $dt2 );
warn 'start: ' . $span->start . ' end: ' . $span->end; ### same
output as with 'before'
_But_ if you check whether the span _includes_ its end date you get a
different answer:
use strict;
use warnings;
use DateTime;
use DateTime::Span;
my $dt1 = DateTime->new( year => 2002, month => 3, day => 11 );
my $dt2 = DateTime->new( year => 2003, month => 4, day => 12 );
my $span1 = DateTime::Span->from_datetimes( start => $dt1, before => $dt2 );
my $span2 = DateTime::Span->from_datetimes( start => $dt1, end => $dt2 );
for my $span ($span1, $span2 )
{
warn 'start: ' . $span->start . ' end: ' . $span->end;
warn 'includes end? ' . ( $span->contains($dt2) ? 'yes' : 'no' ) . "\n";
}
-dave
/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/