Hi All,
I wrote a script with two cases.
In the first case the set unites between the spans and in the second set it
does not unite.
Can you please explain me what is the difference and how in the first case I
can bring them to unite ?

Best regards,
David

Here is the script
#####################################
use strict;
use warnings;
use DateTime::SpanSet;
my $a= DateTime->new(year=>1998);
my $b = DateTime->new(year=>2002);
my $c = DateTime->new(year=>2004);
my $d = DateTime->new(year=>2005);
my $e = DateTime->new(year=>1994);

my $span1 = DateTime::Span->from_datetimes( start => $a, before => $b );
my $span2 = DateTime::Span->from_datetimes( start => $c, before => $d );
my $span3 = DateTime::Span->from_datetimes( start => $e, before => $c );
my $set1 = DateTime::SpanSet->from_spans(spans=>[$span1,$span2]);
my $set2 = DateTime::SpanSet->from_spans(spans=>[$span3]);
my $set3 = $set1->union($set2);
my @list = $set3->as_list;
print "running union between [1998,2002),[2004,2005),[1994,2004) gives the
following result\n";
print $list[0]->start->ymd,"\t",$list[0]->end->ymd,"\n";
print $list[1]->start->ymd,"\t",$list[1]->end->ymd,"\n";
print "running union between [2002,2004),[2004,2005) gives the following
result\n";
my $span4 = DateTime::Span->from_datetimes( start => $b, before => $c );
my $set4 = DateTime::SpanSet->from_spans(spans=>[$span4]);
my $set5 = DateTime::SpanSet->from_spans(spans=>[$span2]);
my $set6 = $set4->union($set5);
my @list = $set6->as_list;
print $list[0]->start->ymd,"\t",$list[0]->end->ymd,"\n";


##################################
And here is the output
running union between [1998,2002),[2004,2005),[1994,2004) gives the
following result
1994-01-01      2004-01-01
2004-01-01      2005-01-01
running union between [2002,2004),[2004,2005) gives the following result
2002-01-01      2005-01-01

Reply via email to