NAME
DateTime::SpanSet - set of DateTime spans
SYNOPSIS
$spanset = DateTime::SpanSet->from_spans( spans => [ $dt_span, $dt_span ] );
$set = $spanset->union( $set2 ); # like "OR", "insert", "both"
$set = $spanset->complement( $set2 ); # like "delete", "remove"
$set = $spanset->intersection( $set2 ); # like "AND", "while"
$set = $spanset->complement; # like "NOT", "negate", "invert"
if ( $spanset->intersects( $set2 ) ) { ... # like "touches", "interferes"
if ( $spanset->contains( $set2 ) ) { ... # like "is-fully-inside"
# data extraction
$date = $spanset->min; # first date of the set
$date = $spanset->max; # last date of the set
$iter = $spanset->iterator;
while ( $dt = $iter->next ) {
# $dt is a DateTime::Span
print $dt->start->ymd; # first date of span
print $dt->end->ymd; # last date of span
};
DESCRIPTION
DateTime::SpanSet is a class that represents sets of datetime spans. An example would be a recurring meeting that occurs from 13:00-15:00 every Friday.
METHODS
from_spans
Creates a new span set from one or more
DateTime::Spanobjects.$spanset = DateTime::SpanSet->from_spans( spans => [ $dt_span ] );from_set_and_duration
Creates a new span set from one or more
DateTime::Setobjects and a duration.The duration can be a
DateTime::Durationobject, or the parameters to create a newDateTime::Durationobject, such as "days", "months", etc.$spanset = DateTime::SpanSet->from_set_and_duration ( set => $dt_set, days => 1 );from_sets
Creates a new span set from two
DateTime::Setobjects.One set defines the starting dates, and the other defines the end dates.
$spanset = DateTime::SpanSet->from_sets ( start_set => $dt_set1, end_set => $dt_set2 );The spans have the starting date
closed, and the end dateopen, like in[$dt1, $dt2).If an end date comes without a starting date before it, then it defines a span like
(-inf, $dt).If a starting date comes without an end date after it, then it defines a span like
[$dt, inf).empty_set
Creates a new empty set.
min / max
First or last dates in the set. These methods may return
undefif the set is empty. It is also possible that these methods may return a scalar containing infinity or negative infinity.duration
The total size of the set, as a
DateTime::Durationobject, or as a scalar containing infinity.Also available as
size().span
The total span of the set, as a
DateTime::Spanobject.union / intersection / complement
Set operations may be performed not only with
DateTime::SpanSetobjects, but also withDateTime,DateTime::SetandDateTime::Spanobjects. These set operations always return aDateTime::SpanSetobject.$set = $spanset->union( $set2 ); # like "OR", "insert", "both" $set = $spanset->complement( $set2 ); # like "delete", "remove" $set = $spanset->intersection( $set2 ); # like "AND", "while" $set = $spanset->complement; # like "NOT", "negate", "invert"intersects / contains
These set functions return a boolean value.
if ( $spanset->intersects( $set2 ) ) { ... # like "touches", "interferes" if ( $spanset->contains( $dt ) ) { ... # like "is-fully-inside"These methods can accept a
DateTime,DateTime::Set,DateTime::Span, orDateTime::SpanSetobject as an argument.iterator / next
This method can be used to iterate over the spans in a set.
$iter = $spanset->iterator; while ( $dt = $iter->next ) { # $dt is a DateTime::Span print $dt->min->ymd; # first date of span print $dt->max->ymd; # last date of span }The boundaries of the iterator can be limited by passing it a
spanparameter. This should be aDateTime::Spanobject which delimits the iterator's boundaries. Optionally, instead of passing an object, you can pass any parameters that would work for one of theDateTime::Spanclass's constructors, and an object will be created for you.Obviously, if the span you specify does is not restricted both at the start and end, then your iterator may iterate forever, depending on the nature of your set. User beware!
The
next()method will returnundefwhen there are no more datetimes in the iterator.
SUPPORT
Support is offered through the datetime@perl.org mailing list.
Please report bugs using rt.cpan.org
AUTHOR
Flavio Soibelmann Glock <fglock@pucrs.br>
The API was developed together with Dave Rolsky and the DateTime Community.
COPYRIGHT
Copyright (c) 2003 Flavio Soibelmann Glock. All rights reserved. This program is free software; you can distribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
SEE ALSO
Set::Infinite
For details on the Perl DateTime Suite project please see http://datetime.perl.org.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 304:
Expected '=item *'
- Around line 339:
You forgot a '=back' before '=head1'