| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package Date::Handler::Delta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | $VERSION = '1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use POSIX qw(floor strftime mktime); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | '""' => 'AsScalar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | '0+' => 'AsNumber', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 'neg' => 'Neg', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | '+' => 'Add', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | '-' => 'Sub', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | '*' => 'Mul', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | '/' => 'Div', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | '<=>' => 'Cmp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | '++' => 'Incr', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | '%' => sub { croak "Impossible to modulo a Date::Handler::Delta"; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | '**' => sub { croak "Trying to obtain square virtual minutes out of a virtual delta boy ?"; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 377 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 377 | my ($classname, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 377 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 377 | bless $self, $classname; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 377 | ▶ | croak "No args to new()" if not defined $delta; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 377 | ▶ | if(ref($delta) =~ /ARRAY/) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 360 | my $delta_array = $self->DeltaFromArray($delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 360 | $self->{months} = $delta_array->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 360 | $self->{seconds} = $delta_array->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | elsif(ref($delta) =~ /HASH/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my $delta_array = $self->DeltaFromArray([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $delta->{years}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | $delta->{months}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | $delta->{days}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $delta->{hours}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $delta->{minutes}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $delta->{seconds}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | $self->{months} = $delta_array->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | $self->{seconds} = $delta_array->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | elsif(!ref($delta)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | $self->{months} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | $self->{seconds} = $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | croak "Arguments to new in unknown format."; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 377 | ▶ | croak "Could not parse delta" if !defined $self->{months} && !defined $self->{seconds}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"months"} or defined $self->{"seconds"}
MC/DC0%0/2
defined $self->{"months"} or defined $self->{"seconds"}
defined $self->{"months"}
defined $self->{"seconds"}
Truth table33%1/3
A or B
A= defined $self->{"months"}B= defined $self->{"seconds"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 377 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | #Accessors (Might want to optimised some of those) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 631 | ▶ | sub Months { return shift->{months}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Months: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 580 | ▶ | sub Seconds { return shift->{seconds}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Seconds: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | #Oveload methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 268 | ▶ | sub AsScalar { return sprintf("%d:%d", @{shift()->AsArray()}); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AsScalar: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub AsNumber { return sprintf("%d.%d",@{shift()->AsArray()}); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AsNumber: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | sub AsArray | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 323 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AsArray: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 323 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 323 | ▶ | return [$self->Months()||0,$self->Seconds()||0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$self->Months || 0
$self->Seconds || 0
MC/DC100%1/1
$self->Months || 0
$self->Months
MC/DC100%1/1
$self->Seconds || 0
$self->Seconds
Truth table100%2/2
A
A= $self->Months
Truth table100%2/2
A
A= $self->Seconds
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | sub AsHash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AsHash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | month => $self->Months(), | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | seconds => $self->Seconds(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | sub Add | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 55 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Add: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 55 | my ($self, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 55 | my $self_array = $self->AsArray(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 55 | ▶ | if(!ref($delta)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | $self_array->[1] += $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | elsif($delta->isa('Date::Handler::Delta')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 39 | $self_array->[0] += $delta->Months(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 39 | $self_array->[1] += $delta->Seconds(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | elsif($delta->isa('Date::Handler')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 14 | return $delta->Add($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self_array->[1] += $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 41 | return ref($self)->new([0, $self_array->[0], 0,0,0,$self_array->[1]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | sub Sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Sub: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 19 | my ($self, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 19 | ▶ | if(ref($delta) && $delta->isa('Date::Handler')) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $delta and $delta->isa("Date::Handler")
MC/DC0%0/2
ref $delta and $delta->isa("Date::Handler")
ref $delta
$delta->isa("Date::Handler")
Truth table33%1/3
A and B
A= ref $deltaB= $delta->isa("Date::Handler")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | croak "Cannot substract a date from a Delta."; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 19 | return $self->Add(-$delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | sub Cmp | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Cmp: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my ($self, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | croak "Cannot compare a Delta with something else than another Delta" if(!ref($delta)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if($delta->isa('Date::Handler::Delta')) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $self_time = 24*60*60*(30*$self->Months())+$self->Seconds(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $delta_time = 24*60*60*(30*$delta->Months())+$delta->Seconds(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return $self_time <=> $delta_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | croak "Cannot compare a Delta with something else than another Delta"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub Mul | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Mul: called CC=4 SCAR=20.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 14 | my ($self, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 14 | ▶ | if(!ref($delta)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 14 | my $months = $self->Months() * $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 14 | my $seconds = $self->Seconds() * $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 14 | return ref($self)->new([0, $months,0,0,0,$seconds]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | elsif($delta->isa('Date::Handler::Delta')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | croak "Cannot obtain square minutes from Delta multiplication"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | elsif($delta->isa('Date::Handler')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | croak "Cannot Multiply a date with a delta."; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $months = $self->Months() * $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $seconds = $self->Seconds() * $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return ref($self)->new([0, $months,0,0,0,$seconds]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | sub Div | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Div: called CC=14 SCAR=49.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 9 | my ($self, $delta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 9 | ▶ | if(!ref($delta)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | my $months = floor($self->Months() / $delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 9 | my $seconds = floor($self->Seconds() / $delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | return ref($self)->new([0, $months,0,0,0,$seconds]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | elsif($delta->isa('Date::Handler::Delta')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | croak "Cannot divide a delta expressed in months and seconds." if($self->Months() && $self->Seconds()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->Months and $self->Seconds
MC/DC0%0/2
$self->Months and $self->Seconds
$self->Months
$self->Seconds
Truth table0%0/3
A and B
A= $self->MonthsB= $self->Seconds
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | croak "Cannot divide a delta expressed in months and seconds." if($delta->Months() && $delta->Seconds()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$delta->Months and $delta->Seconds
MC/DC0%0/2
$delta->Months and $delta->Seconds
$delta->Months
$delta->Seconds
Truth table0%0/3
A and B
A= $delta->MonthsB= $delta->Seconds
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | croak "You can only divide by a delta expressed in the same unit." if($self->Months() && $delta->Seconds()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->Months and $delta->Seconds
MC/DC0%0/2
$self->Months and $delta->Seconds
$self->Months
$delta->Seconds
Truth table0%0/3
A and B
A= $self->MonthsB= $delta->Seconds
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | croak "You can only divide by a delta expressed in the same unit." if($self->Seconds() && $delta->Months()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->Seconds and $delta->Months
MC/DC0%0/2
$self->Seconds and $delta->Months
$self->Seconds
$delta->Months
Truth table0%0/3
A and B
A= $self->SecondsB= $delta->Months
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if($self->Months()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $recurrence = $self->Months() / $delta->Months(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $recurrence; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if($delta->Seconds()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $recurrence = $self->Seconds() / $delta->Seconds(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return $recurrence; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return (0 / $delta->Months()); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | elsif($delta->isa('Date::Handler')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | croak "Cannot divide a date and a delta."; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $months = floor($self->Months() / $delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $seconds = floor($self->Seconds() / $delta); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return ref($self)->new([0, $months,0,0,0,$seconds]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | sub ApproximateInSeconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ApproximateInSeconds: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $direction = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if($direction eq 'over') | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my $years = floor($self->Months() / 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return $self->Seconds() + (24 * 60 * 60 * (($years * 366) + ($self->Months() % 12) * 31)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | elsif($direction eq 'under') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $years = floor($self->Months() / 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $months = $self->Months() % 12; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $months_as_days = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if($months) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $months--; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $months_as_days += 28; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $months_as_days += $months * 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | return $self->Seconds() + (24 * 60 * 60 * ( ($years * 365) + ($months_as_days) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | croak "Allowed argument for ApproximateInSeconds is 'over','under','average'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | sub Incr | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Incr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $secs = $self->Seconds(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | return ref($self)->new([0, $self->Months(),0,0,0,$secs++]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | sub Neg | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 53 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Neg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 53 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 53 | return ref($self)->new([0, -$self->Months(),0,0,0,-$self->Seconds()]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | #Useful methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | #Taken from Class::Date | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | sub DeltaFromArray | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 364 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeltaFromArray: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 364 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 364 | my $input = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 364 | my ($y,$m,$d,$hh,$mm,$ss) = @{$input}[0,1,2,3,4,5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 364 | ▶ | $y = 0 unless (defined $y); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 364 | $y = floor($y * 12); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 364 | $m += $y; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 364 | ▶ | return [$m||0,($ss||0)+60*(($mm||0)+60*(($hh||0)+24*($d||0)))]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%10/10
$m || 0
$ss || 0
$mm || 0
$hh || 0
$d || 0
MC/DC100%1/1
$m || 0
$m
MC/DC100%1/1
$ss || 0
$ss
MC/DC100%1/1
$mm || 0
$mm
MC/DC100%1/1
$hh || 0
$hh
MC/DC100%1/1
$d || 0
$d
Truth table100%2/2
A
A= $m
Truth table100%2/2
A
A= $ss
Truth table100%2/2
A
A= $mm
Truth table100%2/2
A
A= $hh
Truth table100%2/2
A
A= $d
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 8 | 666; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||