| 1 | # Copyright (c) 2003 Flavio Soibelmann Glock. All rights reserved. | ||||||||||||||||||||||||||||
| 2 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 3 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package DateTime::SpanSet; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use DateTime::Set; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 23 | ▶ | use DateTime::Infinite; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 23 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 23 | ▶ | use Params::Validate qw( validate SCALAR BOOLEAN OBJECT CODEREF ARRAYREF ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use constant INFINITY => 100 ** 100 ** 100 ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 23 | ▶ | use constant NEG_INFINITY => -1 * (100 ** 100 ** 100); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 23 | $VERSION = $DateTime::Set::VERSION; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub iterate { | ||||||||||||||||||||||||||
|
Subroutine
iterate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 0 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||
| 22 | 0 | my $class = ref( $self ); | |||||||||||||||||||||||||||
| 23 | 0 | my $return = $class->empty_set; | |||||||||||||||||||||||||||
| 24 | $return->{set} = $self->{set}->iterate( | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 26 | 0 | my $span = bless { set => $_[0] }, 'DateTime::Span'; | |||||||||||||||||||||||||||
| 27 | 0 | $callback->( $span->clone ); | |||||||||||||||||||||||||||
| 28 | $span = $span->{set} | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if UNIVERSAL::can( $span, 'union' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | return $span; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | ); | |||||||||||||||||||||||||||
| 33 | 0 | $return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub map { | ||||||||||||||||||||||||||
|
Subroutine
map: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 1 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||
| 38 | 1 | my $class = ref( $self ); | |||||||||||||||||||||||||||
| 39 | 1 | ▶ | die "The callback parameter to map() must be a subroutine reference" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | unless ref( $callback ) eq 'CODE'; | ||||||||||||||||||||||||||||
| 41 | 1 | my $return = $class->empty_set; | |||||||||||||||||||||||||||
| 42 | $return->{set} = $self->{set}->iterate( | ||||||||||||||||||||||||||||
| 43 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 2 | local $_ = bless { set => $_[0]->clone }, 'DateTime::Span'; | |||||||||||||||||||||||||||
| 45 | 2 | my @list = $callback->(); | |||||||||||||||||||||||||||
| 46 | 2 | my $set = $class->empty_set; | |||||||||||||||||||||||||||
| 47 | 2 | $set = $set->union( $_ ) for @list; | |||||||||||||||||||||||||||
| 48 | 2 | return $set->{set}; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 1 | ); | |||||||||||||||||||||||||||
| 51 | 1 | $return; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub grep { | ||||||||||||||||||||||||||
|
Subroutine
grep: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | my $class = ref( $self ); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | die "The callback parameter to grep() must be a subroutine reference" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | unless ref( $callback ) eq 'CODE'; | ||||||||||||||||||||||||||||
| 59 | 0 | my $return = $class->empty_set; | |||||||||||||||||||||||||||
| 60 | $return->{set} = $self->{set}->iterate( | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 62 | 0 | local $_ = bless { set => $_[0]->clone }, 'DateTime::Span'; | |||||||||||||||||||||||||||
| 63 | 0 | my $result = $callback->(); | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | return $_->{set} if $result && $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$result and $_
MC/DC0%0/2
$result and $_
$result
$_
Truth table0%0/3
A and B
A= $resultB= $_
| |||||||||||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | ); | |||||||||||||||||||||||||||
| 68 | 0 | $return; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub set_time_zone { | ||||||||||||||||||||||||||
|
Subroutine
set_time_zone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my ( $self, $tz ) = @_; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # TODO - use iterate() instead | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | my $result = $self->{set}->iterate( | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 78 | 0 | my %tmp = %{ $_[0]->{list}[0] }; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | $tmp{a} = $tmp{a}->clone->set_time_zone( $tz ) if ref $tmp{a}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $tmp{b} = $tmp{b}->clone->set_time_zone( $tz ) if ref $tmp{b}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | \%tmp; | |||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | backtrack_callback => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 84 | 0 | my ( $min, $max ) = ( $_[0]->min, $_[0]->max ); | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( ref($min) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | 0 | $min = $min->clone; | |||||||||||||||||||||||||||
| 88 | 0 | $min->set_time_zone( 'floating' ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( ref($max) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 0 | $max = $max->clone; | |||||||||||||||||||||||||||
| 93 | 0 | $max->set_time_zone( 'floating' ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | return Set::Infinite::_recurrence->new( $min, $max ); | |||||||||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||||||||||
| 97 | 0 | ); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | ### this code enables 'subroutine method' behaviour | ||||||||||||||||||||||||||||
| 100 | 0 | $self->{set} = $result; | |||||||||||||||||||||||||||
| 101 | 0 | return $self; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | ▶ | sub from_spans { | ||||||||||||||||||||||||||
|
Subroutine
from_spans: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 5 | my $class = shift; | |||||||||||||||||||||||||||
| 106 | 5 | my %args = validate( @_, | |||||||||||||||||||||||||||
| 107 | { spans => | ||||||||||||||||||||||||||||
| 108 | { type => ARRAYREF, | ||||||||||||||||||||||||||||
| 109 | optional => 1, | ||||||||||||||||||||||||||||
| 110 | }, | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | 5 | my $self = {}; | |||||||||||||||||||||||||||
| 114 | 5 | my $set = Set::Infinite::_recurrence->new(); | |||||||||||||||||||||||||||
| 115 | 5 | $set = $set->union( $_->{set} ) for @{ $args{spans} }; | |||||||||||||||||||||||||||
| 116 | 5 | $self->{set} = $set; | |||||||||||||||||||||||||||
| 117 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 118 | 5 | return $self; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 3 | ▶ | sub from_set_and_duration { | ||||||||||||||||||||||||||
|
Subroutine
from_set_and_duration: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | # set => $dt_set, days => 1 | ||||||||||||||||||||||||||||
| 123 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 124 | 3 | my %args = @_; | |||||||||||||||||||||||||||
| 125 | my $set = delete $args{set} || | ||||||||||||||||||||||||||||
| 126 | 3 | ▶ | carp "from_set_and_duration needs a 'set' parameter"; | ||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'set'} || carp(q[from_set_and_duration needs a 'set' parameter])
MC/DC0%0/2
delete $args{'set'} || carp(q[from_set_and_duration needs a 'set' parameter])
delete $args{'set'}
carp(q[from_set_and_duration needs a 'set' parameter])
Truth table33%1/3
A || B
A= delete $args{'set'}B= carp(q[from_set_and_duration needs a 'set' parameter])
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 3 | ▶ | $set = $set->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | if UNIVERSAL::can( $set, 'as_set' ); | ||||||||||||||||||||||||||||
| 130 | 3 | ▶ | unless ( UNIVERSAL::can( $set, 'union' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | carp "'set' must be a set" }; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | my $duration = delete $args{duration} || | ||||||||||||||||||||||||||||
| 134 | 3 | ▶ | new DateTime::Duration( %args ); | ||||||||||||||||||||||||||
|
Condition66%2/3
delete $args{'duration'} || 'DateTime::Duration'->new(%args)
MC/DC0%0/2
delete $args{'duration'} || 'DateTime::Duration'->new(%args)
delete $args{'duration'}
'DateTime::Duration'->new(%args)
Truth table66%2/3
A || B
A= delete $args{'duration'}B= 'DateTime::Duration'->new(%args)
| |||||||||||||||||||||||||||||
| 135 | 3 | my $end_set = $set->clone->add_duration( $duration ); | |||||||||||||||||||||||||||
| 136 | 3 | return $class->from_sets( start_set => $set, | |||||||||||||||||||||||||||
| 137 | end_set => $end_set ); | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 13 | ▶ | sub from_sets { | ||||||||||||||||||||||||||
|
Subroutine
from_sets: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 13 | my $class = shift; | |||||||||||||||||||||||||||
| 142 | 13 | my %args = validate( @_, | |||||||||||||||||||||||||||
| 143 | { start_set => | ||||||||||||||||||||||||||||
| 144 | { # can => 'union', | ||||||||||||||||||||||||||||
| 145 | optional => 0, | ||||||||||||||||||||||||||||
| 146 | }, | ||||||||||||||||||||||||||||
| 147 | end_set => | ||||||||||||||||||||||||||||
| 148 | { # can => 'union', | ||||||||||||||||||||||||||||
| 149 | optional => 0, | ||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||
| 153 | 13 | my $start_set = delete $args{start_set}; | |||||||||||||||||||||||||||
| 154 | 13 | my $end_set = delete $args{end_set}; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 13 | ▶ | $start_set = $start_set->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | if UNIVERSAL::can( $start_set, 'as_set' ); | ||||||||||||||||||||||||||||
| 158 | 13 | ▶ | $end_set = $end_set->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | if UNIVERSAL::can( $end_set, 'as_set' ); | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 13 | ▶ | unless ( UNIVERSAL::can( $start_set, 'union' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | carp "'start_set' must be a set" }; | |||||||||||||||||||||||||||
| 163 | 13 | ▶ | unless ( UNIVERSAL::can( $end_set, 'union' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | carp "'end_set' must be a set" }; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 13 | my $self; | |||||||||||||||||||||||||||
| 167 | $self->{set} = $start_set->{set}->until( | ||||||||||||||||||||||||||||
| 168 | 13 | $end_set->{set} ); | |||||||||||||||||||||||||||
| 169 | 13 | bless $self, $class; | |||||||||||||||||||||||||||
| 170 | 13 | return $self; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 8 | ▶ | sub start_set { | ||||||||||||||||||||||||||
|
Subroutine
start_set: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 8 | ▶ | if ( exists $_[0]->{set}{method} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
MC/DC50%1/2
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
exists $_[0]{"set"}{"method"}
$_[0]{"set"}{"method"} eq "until"
Truth table66%2/3
A and B
A= exists $_[0]{"set"}{"method"}B= $_[0]{"set"}{"method"} eq "until"
| |||||||||||||||||||||||||||||
| 175 | $_[0]->{set}{method} eq 'until' ) | ||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | 5 | return bless { set => $_[0]->{set}{parent}[0] }, 'DateTime::Set'; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 3 | my $return = DateTime::Set->empty_set; | |||||||||||||||||||||||||||
| 180 | 3 | $return->{set} = $_[0]->{set}->start_set; | |||||||||||||||||||||||||||
| 181 | 3 | $return; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 7 | ▶ | sub end_set { | ||||||||||||||||||||||||||
|
Subroutine
end_set: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 7 | ▶ | if ( exists $_[0]->{set}{method} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
MC/DC50%1/2
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
exists $_[0]{"set"}{"method"}
$_[0]{"set"}{"method"} eq "until"
Truth table66%2/3
A and B
A= exists $_[0]{"set"}{"method"}B= $_[0]{"set"}{"method"} eq "until"
| |||||||||||||||||||||||||||||
| 186 | $_[0]->{set}{method} eq 'until' ) | ||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | 5 | return bless { set => $_[0]->{set}{parent}[1] }, 'DateTime::Set'; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 2 | my $return = DateTime::Set->empty_set; | |||||||||||||||||||||||||||
| 191 | 2 | $return->{set} = $_[0]->{set}->end_set; | |||||||||||||||||||||||||||
| 192 | 2 | $return; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 34 | ▶ | sub empty_set { | ||||||||||||||||||||||||||
|
Subroutine
empty_set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 196 | 34 | my $class = shift; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 34 | return bless { set => Set::Infinite::_recurrence->new }, $class; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub is_empty_set { | ||||||||||||||||||||||||||
|
Subroutine
is_empty_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 0 | my $set = $_[0]; | |||||||||||||||||||||||||||
| 203 | 0 | $set->{set}->is_null; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 9 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | bless { | ||||||||||||||||||||||||||||
| 208 | set => $_[0]->{set}->copy, | ||||||||||||||||||||||||||||
| 209 | 9 | }, ref $_[0]; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 12 | ▶ | sub iterator { | ||||||||||||||||||||||||||
|
Subroutine
iterator: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 12 | my %args = @_; | |||||||||||||||||||||||||||
| 217 | 12 | my $span; | |||||||||||||||||||||||||||
| 218 | 12 | $span = delete $args{span}; | |||||||||||||||||||||||||||
| 219 | 12 | ▶ | $span = DateTime::Span->new( %args ) if %args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 12 | ▶ | return $self->intersection( $span ) if $span; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 8 | return $self->clone; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | # next() gets the next element from an iterator() | ||||||||||||||||||||||||||||
| 227 | 48 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | 48 | my ($self) = shift; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # TODO: this is fixing an error from elsewhere | ||||||||||||||||||||||||||||
| 231 | # - find out what's going on! (with "sunset.pl") | ||||||||||||||||||||||||||||
| 232 | 48 | ▶ | return undef unless ref $self->{set}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 45 | ▶ | if ( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||
| 236 | 6 | my $max; | |||||||||||||||||||||||||||
| 237 | 6 | ▶ | $max = $_[0]->max if UNIVERSAL::can( $_[0], 'union' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 6 | ▶ | $max = $_[0] if ! defined $max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 6 | ▶ | return undef if ! ref( $max ) && $max == INFINITY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $max and $max == "Inf"
MC/DC0%0/2
not ref $max and $max == "Inf"
not ref $max
$max == "Inf"
Truth table33%1/3
not(A) and B
A= not ref $maxB= $max == "Inf"
| |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 6 | my $span = DateTime::Span->from_datetimes( start => $max ); | |||||||||||||||||||||||||||
| 243 | 6 | my $iterator = $self->intersection( $span ); | |||||||||||||||||||||||||||
| 244 | 6 | my $return = $iterator->next; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 6 | ▶ | return $return if ! defined $return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 6 | ▶ | return $return if ! $return->intersects( $max ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 1 | return $iterator->next; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 39 | my ($head, $tail) = $self->{set}->first; | |||||||||||||||||||||||||||
| 253 | 39 | $self->{set} = $tail; | |||||||||||||||||||||||||||
| 254 | 39 | ▶ | return $head unless ref $head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 39 | my $return = { | |||||||||||||||||||||||||||
| 256 | set => $head, | ||||||||||||||||||||||||||||
| 257 | }; | ||||||||||||||||||||||||||||
| 258 | 39 | bless $return, 'DateTime::Span'; | |||||||||||||||||||||||||||
| 259 | 39 | return $return; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | # previous() gets the last element from an iterator() | ||||||||||||||||||||||||||||
| 263 | 17 | ▶ | sub previous { | ||||||||||||||||||||||||||
|
Subroutine
previous: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | 17 | my ($self) = shift; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 17 | ▶ | return undef unless ref $self->{set}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 15 | ▶ | if ( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||
| 270 | 3 | my $min; | |||||||||||||||||||||||||||
| 271 | 3 | ▶ | $min = $_[0]->min if UNIVERSAL::can( $_[0], 'union' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 3 | ▶ | $min = $_[0] if ! defined $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 3 | ▶ | return undef if ! ref( $min ) && $min == INFINITY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $min and $min == "Inf"
MC/DC0%0/2
not ref $min and $min == "Inf"
not ref $min
$min == "Inf"
Truth table33%1/3
not(A) and B
A= not ref $minB= $min == "Inf"
| |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 3 | my $span = DateTime::Span->from_datetimes( end => $min ); | |||||||||||||||||||||||||||
| 277 | 3 | my $iterator = $self->intersection( $span ); | |||||||||||||||||||||||||||
| 278 | 3 | my $return = $iterator->previous; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 3 | ▶ | return $return if ! defined $return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 3 | ▶ | return $return if ! $return->intersects( $min ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 2 | return $iterator->previous; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 12 | my ($head, $tail) = $self->{set}->last; | |||||||||||||||||||||||||||
| 287 | 12 | $self->{set} = $tail; | |||||||||||||||||||||||||||
| 288 | 12 | ▶ | return $head unless ref $head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 12 | my $return = { | |||||||||||||||||||||||||||
| 290 | set => $head, | ||||||||||||||||||||||||||||
| 291 | }; | ||||||||||||||||||||||||||||
| 292 | 12 | bless $return, 'DateTime::Span'; | |||||||||||||||||||||||||||
| 293 | 12 | return $return; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # "current" means less-or-equal to a DateTime | ||||||||||||||||||||||||||||
| 297 | 4 | ▶ | sub current { | ||||||||||||||||||||||||||
|
Subroutine
current: called CC=9 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||||||||
| 298 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 4 | my $previous; | |||||||||||||||||||||||||||
| 301 | my $next; | ||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||
| 303 | 4 | my $min; | |||||||||||||||||||||||||||
| 304 | 4 | ▶ | $min = $_[0]->min if UNIVERSAL::can( $_[0], 'union' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | 4 | ▶ | $min = $_[0] if ! defined $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 4 | ▶ | return undef if ! ref( $min ) && $min == INFINITY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $min and $min == "Inf"
MC/DC0%0/2
not ref $min and $min == "Inf"
not ref $min
$min == "Inf"
Truth table33%1/3
not(A) and B
A= not ref $minB= $min == "Inf"
| |||||||||||||||||||||||||||||
| 307 | 4 | my $span = DateTime::Span->from_datetimes( end => $min ); | |||||||||||||||||||||||||||
| 308 | 4 | my $iterator = $self->intersection( $span ); | |||||||||||||||||||||||||||
| 309 | 4 | $previous = $iterator->previous; | |||||||||||||||||||||||||||
| 310 | 4 | $span = DateTime::Span->from_datetimes( start => $min ); | |||||||||||||||||||||||||||
| 311 | 4 | $iterator = $self->intersection( $span ); | |||||||||||||||||||||||||||
| 312 | 4 | $next = $iterator->next; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 4 | ▶ | return $previous unless defined $next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 4 | ▶ | my $dt1 = defined $previous | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | ? $next->union( $previous ) | ||||||||||||||||||||||||||||
| 318 | : $next; | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 4 | my $return = $dt1->intersected_spans( $_[0] ); | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 4 | ▶ | $return = $previous | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | if !defined $return->max; | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 4 | ▶ | bless $return, 'DateTime::SpanSet' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | if defined $return; | ||||||||||||||||||||||||||||
| 327 | 4 | return $return; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 3 | ▶ | sub closest { | ||||||||||||||||||||||||||
|
Subroutine
closest: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 331 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 332 | 3 | my $dt = shift; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 3 | my $dt1 = $self->current( $dt ); | |||||||||||||||||||||||||||
| 335 | 3 | my $dt2 = $self->next( $dt ); | |||||||||||||||||||||||||||
| 336 | 3 | ▶ | bless $dt2, 'DateTime::SpanSet' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | if defined $dt2; | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 3 | ▶ | return $dt2 unless defined $dt1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 3 | ▶ | return $dt1 unless defined $dt2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 2 | ▶ | $dt = DateTime::Set->from_datetimes( dates => [ $dt ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | unless UNIVERSAL::can( $dt, 'union' ); | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 2 | ▶ | return $dt1 if $dt1->contains( $dt ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 2 | my $delta = $dt->min - $dt1->max; | |||||||||||||||||||||||||||
| 348 | 2 | ▶ | return $dt1 if ( $dt2->min - $delta ) >= $dt->max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 1 | return $dt2; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 1 | ▶ | sub as_list { | ||||||||||||||||||||||||||
|
Subroutine
as_list: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 354 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 355 | 1 | ▶ | return undef unless ref( $self->{set} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 1 | my %args = @_; | |||||||||||||||||||||||||||
| 358 | 1 | my $span; | |||||||||||||||||||||||||||
| 359 | 1 | $span = delete $args{span}; | |||||||||||||||||||||||||||
| 360 | 1 | ▶ | $span = DateTime::Span->new( %args ) if %args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 1 | my $set = $self->clone; | |||||||||||||||||||||||||||
| 363 | 1 | ▶ | $set = $set->intersection( $span ) if $span; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | # Note: removing this line means we may end up in an infinite loop! | ||||||||||||||||||||||||||||
| 366 | 1 | ▶ | return undef if $set->{set}->is_too_complex; # undef = no start/end | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | # return if $set->{set}->is_null; # nothing = empty | ||||||||||||||||||||||||||||
| 369 | 1 | my @result; | |||||||||||||||||||||||||||
| 370 | # we should extract _copies_ of the set elements, | ||||||||||||||||||||||||||||
| 371 | # such that the user can't modify the set indirectly | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 1 | my $iter = $set->iterator; | |||||||||||||||||||||||||||
| 374 | 1 | ▶ | while ( my $dt = $iter->next ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||
| 376 | 3 | ▶ | push @result, $dt | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | if ref( $dt ); # we don't want to return INFINITY value | ||||||||||||||||||||||||||||
| 378 | }; | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 1 | return @result; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | # Set::Infinite methods | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 22 | ▶ | sub intersection { | ||||||||||||||||||||||||||
|
Subroutine
intersection: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 386 | 22 | my ($set1, $set2) = ( shift, shift ); | |||||||||||||||||||||||||||
| 387 | 22 | my $class = ref($set1); | |||||||||||||||||||||||||||
| 388 | 22 | my $tmp = $class->empty_set(); | |||||||||||||||||||||||||||
| 389 | 22 | ▶ | $set2 = $set2->as_spanset | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | if $set2->can( 'as_spanset' ); | ||||||||||||||||||||||||||||
| 391 | 22 | ▶ | $set2 = $set2->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | if $set2->can( 'as_set' ); | ||||||||||||||||||||||||||||
| 393 | 22 | ▶ | $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | unless $set2->can( 'union' ); | ||||||||||||||||||||||||||||
| 395 | 22 | $tmp->{set} = $set1->{set}->intersection( $set2->{set} ); | |||||||||||||||||||||||||||
| 396 | 22 | return $tmp; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 5 | ▶ | sub intersected_spans { | ||||||||||||||||||||||||||
|
Subroutine
intersected_spans: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 400 | 5 | my ($set1, $set2) = ( shift, shift ); | |||||||||||||||||||||||||||
| 401 | 5 | my $class = ref($set1); | |||||||||||||||||||||||||||
| 402 | 5 | my $tmp = $class->empty_set(); | |||||||||||||||||||||||||||
| 403 | 5 | ▶ | $set2 = $set2->as_spanset | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | if $set2->can( 'as_spanset' ); | ||||||||||||||||||||||||||||
| 405 | 5 | ▶ | $set2 = $set2->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | if $set2->can( 'as_set' ); | ||||||||||||||||||||||||||||
| 407 | 5 | ▶ | $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | unless $set2->can( 'union' ); | ||||||||||||||||||||||||||||
| 409 | 5 | $tmp->{set} = $set1->{set}->intersected_spans( $set2->{set} ); | |||||||||||||||||||||||||||
| 410 | 5 | return $tmp; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 1 | ▶ | sub intersects { | ||||||||||||||||||||||||||
|
Subroutine
intersects: called CC=7 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||
| 414 | 1 | my ($set1, $set2) = ( shift, shift ); | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 1 | ▶ | unless ( $set2->can( 'union' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||
| 418 | 1 | for ( $set2, @_ ) | |||||||||||||||||||||||||||
| 419 | { | ||||||||||||||||||||||||||||
| 420 | 1 | ▶ | return 1 if $set1->contains( $_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | 1 | return 0; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 0 | my $class = ref($set1); | |||||||||||||||||||||||||||
| 426 | 0 | ▶ | $set2 = $set2->as_spanset | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | if $set2->can( 'as_spanset' ); | ||||||||||||||||||||||||||||
| 428 | 0 | ▶ | $set2 = $set2->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | if $set2->can( 'as_set' ); | ||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | unless $set2->can( 'union' ); | ||||||||||||||||||||||||||||
| 432 | 0 | return $set1->{set}->intersects( $set2->{set} ); | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 6 | ▶ | sub contains { | ||||||||||||||||||||||||||
|
Subroutine
contains: called CC=11 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||
| 436 | 6 | my ($set1, $set2) = ( shift, shift ); | |||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 6 | ▶ | unless ( $set2->can( 'union' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | { | ||||||||||||||||||||||||||||
| 440 | 4 | ▶ | if ( exists $set1->{set}{method} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $set1->{"set"}{"method"} and $set1->{"set"}{"method"} eq "until"
MC/DC0%0/2
exists $set1->{"set"}{"method"} and $set1->{"set"}{"method"} eq "until"
exists $set1->{"set"}{"method"}
$set1->{"set"}{"method"} eq "until"
Truth table33%1/3
A and B
A= exists $set1->{"set"}{"method"}B= $set1->{"set"}{"method"} eq "until"
| |||||||||||||||||||||||||||||
| 441 | $set1->{set}{method} eq 'until' ) | ||||||||||||||||||||||||||||
| 442 | { | ||||||||||||||||||||||||||||
| 443 | 4 | my $start_set = $set1->start_set; | |||||||||||||||||||||||||||
| 444 | 4 | my $end_set = $set1->end_set; | |||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 4 | for ( $set2, @_ ) | |||||||||||||||||||||||||||
| 447 | { | ||||||||||||||||||||||||||||
| 448 | 4 | my $start = $start_set->next( $set2 ); | |||||||||||||||||||||||||||
| 449 | 4 | my $end = $end_set->next( $set2 ); | |||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 4 | ▶ | goto ABORT unless defined $start && defined $end; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $start and defined $end
MC/DC0%0/2
defined $start and defined $end
defined $start
defined $end
Truth table33%1/3
A and B
A= defined $startB= defined $end
| |||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 4 | ▶ | return 0 if $start < $end; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | 1 | return 1; | |||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | ABORT: ; | |||||||||||||||||||||||||||
| 458 | # don't know | ||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 2 | my $class = ref($set1); | |||||||||||||||||||||||||||
| 463 | 2 | ▶ | $set2 = $set2->as_spanset | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | if $set2->can( 'as_spanset' ); | ||||||||||||||||||||||||||||
| 465 | 2 | ▶ | $set2 = $set2->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | if $set2->can( 'as_set' ); | ||||||||||||||||||||||||||||
| 467 | 2 | ▶ | $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | unless $set2->can( 'union' ); | ||||||||||||||||||||||||||||
| 469 | 2 | return $set1->{set}->contains( $set2->{set} ); | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 4 | ▶ | sub union { | ||||||||||||||||||||||||||
|
Subroutine
union: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 473 | 4 | my ($set1, $set2) = ( shift, shift ); | |||||||||||||||||||||||||||
| 474 | 4 | my $class = ref($set1); | |||||||||||||||||||||||||||
| 475 | 4 | my $tmp = $class->empty_set(); | |||||||||||||||||||||||||||
| 476 | 4 | ▶ | $set2 = $set2->as_spanset | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | if $set2->can( 'as_spanset' ); | ||||||||||||||||||||||||||||
| 478 | 4 | ▶ | $set2 = $set2->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | if $set2->can( 'as_set' ); | ||||||||||||||||||||||||||||
| 480 | 4 | ▶ | $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | unless $set2->can( 'union' ); | ||||||||||||||||||||||||||||
| 482 | 4 | $tmp->{set} = $set1->{set}->union( $set2->{set} ); | |||||||||||||||||||||||||||
| 483 | 4 | return $tmp; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 0 | ▶ | sub complement { | ||||||||||||||||||||||||||
|
Subroutine
complement: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 487 | 0 | my ($set1, $set2) = ( shift, shift ); | |||||||||||||||||||||||||||
| 488 | 0 | my $class = ref($set1); | |||||||||||||||||||||||||||
| 489 | 0 | my $tmp = $class->empty_set(); | |||||||||||||||||||||||||||
| 490 | 0 | ▶ | if (defined $set2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $set2 = $set2->as_spanset | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | if $set2->can( 'as_spanset' ); | ||||||||||||||||||||||||||||
| 493 | 0 | ▶ | $set2 = $set2->as_set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | if $set2->can( 'as_set' ); | ||||||||||||||||||||||||||||
| 495 | 0 | ▶ | $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | unless $set2->can( 'union' ); | ||||||||||||||||||||||||||||
| 497 | 0 | $tmp->{set} = $set1->{set}->complement( $set2->{set} ); | |||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | else { | ||||||||||||||||||||||||||||
| 500 | 0 | $tmp->{set} = $set1->{set}->complement; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | 0 | return $tmp; | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 16 | ▶ | sub start { | ||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 506 | 16 | return DateTime::Set::_fix_datetime( $_[0]->{set}->min ); | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 23 | *min = \&start; | |||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 20 | ▶ | sub end { | ||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 512 | 20 | return DateTime::Set::_fix_datetime( $_[0]->{set}->max ); | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 23 | *max = \&end; | |||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | # returns a DateTime::Span | ||||||||||||||||||||||||||||
| 518 | 0 | ▶ | sub span { | ||||||||||||||||||||||||||
|
Subroutine
span: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 519 | 0 | my $set = $_[0]->{set}->span; | |||||||||||||||||||||||||||
| 520 | 0 | my $self = bless { set => $set }, 'DateTime::Span'; | |||||||||||||||||||||||||||
| 521 | 0 | return $self; | |||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | # returns a DateTime::Duration | ||||||||||||||||||||||||||||
| 525 | 3 | ▶ | sub duration { | ||||||||||||||||||||||||||
|
Subroutine
duration: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 526 | 3 | my $dur; | |||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | return DateTime::Duration->new( seconds => 0 ) | ||||||||||||||||||||||||||||
| 529 | 3 | ▶ | if $_[0]->{set}->is_empty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 2 | local $@; | |||||||||||||||||||||||||||
| 532 | 2 | eval { | |||||||||||||||||||||||||||
| 533 | 2 | local $SIG{__DIE__}; # don't want to trap this (rt ticket 5434) | |||||||||||||||||||||||||||
| 534 | $dur = $_[0]->{set}->size | ||||||||||||||||||||||||||||
| 535 | 2 | }; | |||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 2 | ▶ | return $dur if defined $dur && ref( $dur ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $dur and ref $dur
MC/DC0%0/2
defined $dur and ref $dur
defined $dur
ref $dur
Truth table66%2/3
A and B
A= defined $durB= ref $dur
| |||||||||||||||||||||||||||||
| 538 | 2 | return DateTime::Infinite::Future->new - | |||||||||||||||||||||||||||
| 539 | DateTime::Infinite::Past->new; | ||||||||||||||||||||||||||||
| 540 | # return INFINITY; | ||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | 23 | *size = \&duration; | |||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 23 | 1; | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | __END__ | ||||||||||||||||||||||||||||