The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

DateTime::Span - Date/time spans

SYNOPSIS

    use DateTime;
    use DateTime::Span;

    $date1 = DateTime->new( year => 2002, month => 3, day => 11 );
    $date2 = DateTime->new( year => 2003, month => 4, day => 12 );
    $set2 = DateTime::Span->new( start => $date1, end => $date2 );
    #  set2 = 2002-03-11 until 2003-04-12

    $set = $set1->union( $set2 );         # like "OR", "insert", "both"
    $set = $set1->complement( $set2 );    # like "delete", "remove"
    $set = $set1->intersection( $set2 );  # like "AND", "while"
    $set = $set1->complement;             # like "NOT", "negate", "invert"

    if ( $set1->intersects( $set2 ) ) { ...  # like "touches", "interferes"
    if ( $set1->contains( $set2 ) ) { ...    # like "is-fully-inside"

    # data extraction 
    $date = $set1->start;           # first date of the span
    $date = $set1->end;             # last date of the span

DESCRIPTION

DateTime::Span is a module for date/time spans or time-ranges.

METHODS

  • new

    Generates a new span.

    A 'closed' span includes its end-dates:

       $dates = DateTime::Set->new( start => $dt1, end => $dt2 );

    An 'open' span does not include its end-dates:

       $dates = DateTime::Set->new( after => $dt1, before => $dt2 );

    A 'semi-open' span includes one of its end-dates:

       $dates = DateTime::Set->new( start => $dt1, before => $dt2 );
       $dates = DateTime::Set->new( after => $dt1, end => $dt2 );

    A span might have just a begin date, or just an end date. These spans end, or start, in an imaginary 'forever' date:

       $dates = DateTime::Set->new( start => $dt1 );
       $dates = DateTime::Set->new( end => $dt2 );
       $dates = DateTime::Set->new( after => $dt1 );
       $dates = DateTime::Set->new( 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 cause will cause the new() method to die.

  • duration

    Return a DateTime::Duration object that represents the length of the span.

  • start / end

    First or last dates in the span.

  • start_is_closed / end_is_closed

    Return true if the first or last dates belong to the span ( begin <= x <= end ).

  • start_is_open / end_is_open

    Return true if the first or last dates are out of the span ( begin < x < end ).

  • duration

    The duration of the span, as a DateTime::Duration.

    This is the sum of the durations of all spans.

  • union / intersection / complement

    These set operations result in a DateTime::SpanSet.

        $set = $set1->union( $set2 );         # like "OR", "insert", "both"
        $set = $set1->complement( $set2 );    # like "delete", "remove"
        $set = $set1->intersection( $set2 );  # like "AND", "while"
        $set = $set1->complement;             # like "NOT", "negate", "invert"
  • intersects / contains

    These set functions result in a boolean value.

        if ( $set1->intersects( $set2 ) ) { ...  # like "touches", "interferes"
        if ( $set1->contains( $set2 ) ) { ...    # like "is-fully-inside"

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

http://datetime.perl.org.

For details on the Perl DateTime Suite project please see http://perl-date-time.sf.net.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 266:

'=item' outside of any '=over'

Around line 298:

Expected '=item *'

Around line 305:

You forgot a '=back' before '=head1'