• from_datetimes
Creates a new span based on a starting and ending datetime.
A 'closed' span includes its end-dates:
$span = DateTime::Span->from_datetimes( start => $dt1, end => $dt2 );
An 'open' span does not include its end-dates:
$span = DateTime::Span->from_datetimes( after => $dt1, before => $dt2 );
A 'semi-open' span includes one of its end-dates:
$span = DateTime::Span->from_datetimes( start => $dt1, before => $dt2 );
$span = DateTime::Span->from_datetimes( after => $dt1, end => $dt2 );
A span might have just a starting date, or just an ending date. These spans end, or start, in an
imaginary 'forever' date:
$span = DateTime::Span->from_datetimes( start => $dt1 );
$span = DateTime::Span->from_datetimes( end => $dt2 );
$span = DateTime::Span->from_datetimes( after => $dt1 );
$span = DateTime::Span->from_datetimes( before => $dt2 );
You cannot give both a "start" and "after" argument, nor can you give both an "end" and "before"
argument. Either of these conditions will cause the "from_datetimes()" method to die.
To summarize, a datetime passed as either "start" or "end" is included in the span. A datetime
passed as either "after" or "before" is excluded from the span.
• from_datetime_and_duration
Creates a new span.
$span = DateTime::Span->from_datetime_and_duration(
start => $dt1, duration => $dt_dur1 );
$span = DateTime::Span->from_datetime_and_duration(
after => $dt1, hours => 12 );
The new "end of the set" is open by default.
• clone
This object method returns a replica of the given object.
• set_time_zone( $tz )
This method accepts either a time zone object or a string that can be passed as the "name" parameter
to "DateTime::TimeZone->new()". If the new time zone's offset is different from the old time zone,
then the local time is adjusted accordingly.
If the old time zone was a floating time zone, then no adjustments to the local time are made, except
to account for leap seconds. If the new time zone is floating, then the UTC time is adjusted in
order to leave the local time untouched.
• duration
The total size of the set, as a "DateTime::Duration" object, or as a scalar containing infinity.
Also available as "size()".
• start, min
• end, max
First or last dates in the span.
It is possible that the return value from these methods may be a "DateTime::Infinite::Future" or a
"DateTime::Infinite::Past"xs object.
If the set ends "before" a date $dt, it returns $dt. Note that in this case $dt is not a set element
- but it is a set boundary.
These methods return just a copy of the actual boundary value. If you modify the result, the set
will not be modified.
• start_is_closed
• end_is_closed
Returns true if the first or last dates belong to the span ( start <= x <= end ).
• start_is_open
• end_is_open
Returns true if the first or last dates are excluded from the span ( start < x < end ).
• union
• intersection
• complement
Set operations may be performed not only with "DateTime::Span" objects, but also with "DateTime::Set"
and "DateTime::SpanSet" objects. These set operations always return a "DateTime::SpanSet" object.
$set = $span->union( $set2 ); # like "OR", "insert", "both"
$set = $span->complement( $set2 ); # like "delete", "remove"
$set = $span->intersection( $set2 ); # like "AND", "while"
$set = $span->complement; # like "NOT", "negate", "invert"
• intersects
• contains
These set functions return a boolean value.
if ( $span->intersects( $set2 ) ) { ... # like "touches", "interferes"
if ( $span->contains( $dt ) ) { ... # like "is-fully-inside"
These methods can accept a "DateTime", "DateTime::Set", "DateTime::Span", or "DateTime::SpanSet"
object as an argument.