| 1 | package HTML::CalendarMonth::DateTool; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | $HTML::CalendarMonth::DateTool::VERSION = '1.26'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | # Base class for determining what date calculation package to use. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use File::Which qw( which ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | my %Toolmap = ( | |||||||||||||||||||||||||||||||||||||||||
| 15 | 'Time::Local' => 'TimeLocal', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 'Date::Calc' => 'DateCalc', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 'DateTime' => 'DateTime', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'Date::Manip' => 'DateManip', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'ncal' => 'Ncal', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 'cal' => 'Cal', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | my %Classmap; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | $Classmap{lc $Toolmap{$_}} = $_ foreach keys %Toolmap; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | my($Cal_Cmd, $Ncal_Cmd); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | sub _toolmap { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 461 | ▶ | shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_toolmap: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 461 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 461 | my $tool = $Toolmap{$str}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 461 | ▶ | unless ($tool) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 308 | foreach (values %Toolmap) { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1063 | ▶ | if ($str =~ /^$_$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 308 | $tool = $_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 308 | last; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 461 | ▶ | return unless $tool; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 461 | join('::', __PACKAGE__, $tool); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 310 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 310 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 310 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 310 | my %parms = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 310 | $self->{year} = $parms{year}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 310 | $self->{month} = $parms{month}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 310 | $self->{weeknum} = $parms{weeknum}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 310 | $self->{historic} = $parms{historic}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 310 | ▶ | if (! $self->{year}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my @dmy = $self->_dmy_now; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | $self->{year} = $dmy[2]; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | $self->{month} ||= $dmy[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"month"} ||= $dmy[1]
MC/DC0%0/2
$self->{"month"} ||= $dmy[1]
$self->{"month"}
$dmy[1]
Truth table33%1/3
A ||= B
A= $self->{"month"}B= $dmy[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 310 | ▶ | $self->{month} ||= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"month"} ||= 1
MC/DC0%0/1
$self->{"month"} ||= 1
$self->{"month"}
Truth table50%1/2
A
A= $self->{"month"}
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 310 | ▶ | if ($parms{datetool}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | $self->{datetool} = $self->_toolmap($parms{datetool}) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 152 | ▶ | or croak "Sorry, didn't find a tool for datetool '$parms{datetool}'\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 310 | my $dc = $self->_summon_date_class; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 308 | ▶ | unless (eval "require $dc") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | croak "Problem loading $dc ($@)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # rebless into new class | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 308 | bless $self, $dc; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1538 | ▶ | sub year { shift->{year} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
year: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1228 | ▶ | sub month { shift->{month} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 310 | ▶ | sub weeknum { shift->{weeknum} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weeknum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub historic { shift->{historic} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
historic: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 310 | ▶ | sub datetool { shift->{datetool} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetool: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub _name { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 446 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 446 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 446 | lc((split(/::/, $class))[-1]); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | sub _cal_cmd { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cal_cmd: called CC=7 SCAR=30.7
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | if (! defined $Cal_Cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | $Cal_Cmd = which('cal') || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
which('cal') || ''
MC/DC0%0/1
which('cal') || ''
which('cal')
Truth table50%1/2
A
A= which('cal')
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | if ($Cal_Cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my @out = grep { ! /^\s*$/ } `$Cal_Cmd 9 1752`; | |||||||||||||||||||||||||||||||||||||||||
| 89 | # September 1752 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | #Su Mo Tu We Th Fr Sa | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # 1 2 14 15 16 | ||||||||||||||||||||||||||||||||||||||||||
| 92 | #17 18 19 20 21 22 23 | ||||||||||||||||||||||||||||||||||||||||||
| 93 | #24 25 26 27 28 29 30 | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my @pat = ( | |||||||||||||||||||||||||||||||||||||||||
| 95 | qr/^\s*\S+\s+\d+$/, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | qr/^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | qr/^\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | qr/^\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | qr/^\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (@out == @pat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | for my $i (0 .. $#out) { | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($out[$i] !~ $pat[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $Cal_Cmd = ''; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $Cal_Cmd = ''; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $Cal_Cmd; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | sub _ncal_cmd { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ncal_cmd: called CC=7 SCAR=31.5
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | if (! defined $Ncal_Cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | $Ncal_Cmd = which('ncal') || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
which('ncal') || ''
MC/DC0%0/1
which('ncal') || ''
which('ncal')
Truth table50%1/2
A
A= which('ncal')
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | if ($Ncal_Cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my @out = grep { ! /^\s*$/ } map { s/^\s*//; $_ } `$Ncal_Cmd 9 1752`; | |||||||||||||||||||||||||||||||||||||||||
| 123 | # September 1752 | ||||||||||||||||||||||||||||||||||||||||||
| 124 | #Mo 18 25 | ||||||||||||||||||||||||||||||||||||||||||
| 125 | #Tu 1 19 26 | ||||||||||||||||||||||||||||||||||||||||||
| 126 | #We 2 20 27 | ||||||||||||||||||||||||||||||||||||||||||
| 127 | #Th 14 21 28 | ||||||||||||||||||||||||||||||||||||||||||
| 128 | #Fr 15 22 29 | ||||||||||||||||||||||||||||||||||||||||||
| 129 | #Sa 16 23 30 | ||||||||||||||||||||||||||||||||||||||||||
| 130 | #Su 17 24 | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my @pat = ( | |||||||||||||||||||||||||||||||||||||||||
| 132 | qr/^\s*\S+\s+\d+$/, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | qr/^\s*\S+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | qr/^\s*\S+\s+\d+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | qr/^\s*\S+\s+\d+\s+\d+\s*$/, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if (@out == @pat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | for my $i (0 .. $#out) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($out[$i] !~ $pat[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $Ncal_Cmd = ''; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $Ncal_Cmd = ''; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $Ncal_Cmd; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub day_epoch { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # in case our subclasses are lazy | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my($self, $day, $month, $year) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
day_epoch: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $month ||= $self->month; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$month ||= $self->month
MC/DC0%0/2
$month ||= $self->month
$month
$self->month
Truth table0%0/3
A ||= B
A= $monthB= $self->month
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $year ||= $self->year; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$year ||= $self->year
MC/DC0%0/2
$year ||= $self->year
$year
$self->year
Truth table0%0/3
A ||= B
A= $yearB= $self->year
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | Time::Local::timegm(0,0,0,1,$month,$year); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | sub _skips { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 307 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skips: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 307 | ▶ | @_ ? $self->{skips} = shift : $self->{skips}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 307 | ▶ | sub dow1st { (shift->dow1st_and_lastday)[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dow1st: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 614 | ▶ | sub lastday { (shift->dow1st_and_lastday)[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lastday: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | sub _dmy_now { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 308 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dmy_now: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 308 | ▶ | my $ts = @_ ? shift : time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 308 | my($d, $m, $y) = (localtime($ts))[3,4,5]; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 308 | ++$m; $y += 1900; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 308 | ($d, $m, $y); | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | sub _dom_now { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 307 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dom_now: called CC=9 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 307 | ▶ | my $ts = @_ ? shift : time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 307 | my($d, $m, $y); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 307 | ▶ | if ($ts =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 307 | ▶ | if (length $ts <= 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ($d, $m, $y) = ($ts, $self->month, $self->year); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | croak "invalid day of month (1 .. " . $self->lastday . ") '$ts'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ts >= 1 and $ts <= $self->lastday
MC/DC0%0/2
$ts >= 1 and $ts <= $self->lastday
$ts >= 1
$ts <= $self->lastday
Truth table0%0/3
A and B
A= $ts >= 1B= $ts <= $self->lastday
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | unless $ts >= 1 && $ts <= $self->lastday; | ||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 307 | ($d, $m, $y) = $self->_dmy_now($ts); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ($y, $m, $d) = $ts =~ m{^(\d+)/(\d\d)/(\d\d)$}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | croak "invalid yyyy/mm/dd date string '$ts'" unless defined $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 307 | my($cy, $cm) = ($self->year, $self->month); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 307 | my $first = sprintf("%04d/%02d/%02d", $cy, $cm, 1); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 307 | my $last = sprintf("%04d/%02d/%02d", $cy, $cm, $self->lastday); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 307 | my $pivot = sprintf("%04d/%02d/%02d", $y, $m, $d); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 307 | ▶ | return -1 if $pivot gt $last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | return 0 if $pivot lt $first; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $d; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | sub _summon_date_class { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 310 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_summon_date_class: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 310 | my @tools; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 310 | ▶ | if (my $c = $self->datetool) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 152 | ▶ | eval "use $c"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 152 | ▶ | die "invalid date tool $c : $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 152 | @tools = $c->_name; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 158 | @tools = qw( timelocal datecalc datetime datemanip ncal cal ); | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 310 | my($dc, @fails); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 310 | for my $tool (@tools) { | |||||||||||||||||||||||||||||||||||||||||
| 222 | 310 | my $method = join('_', '', lc($tool), 'fails'); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 310 | ▶ | if (my $f = $self->$method) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | push(@fails, [$tool, $f]); | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 308 | $dc = $self->_toolmap($tool); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 308 | last; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 310 | ▶ | return $dc if $dc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | ▶ | if (@tools == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | croak "invalid date tool " . join(': ', @{$fails[0]}); | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | croak join("\n", | |||||||||||||||||||||||||||||||||||||||||
| 237 | "no valid date tool found:", | ||||||||||||||||||||||||||||||||||||||||||
| 238 | map(sprintf("%11s: %s", @$_), @fails), | ||||||||||||||||||||||||||||||||||||||||||
| 239 | "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | sub _dump_tests { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_tests: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | print "Time::Local : ", $self->_timelocal_fails || 1, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_timelocal_fails || 1
MC/DC0%0/1
$self->_timelocal_fails || 1
$self->_timelocal_fails
Truth table0%0/2
A
A= $self->_timelocal_fails
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | print " Date::Calc : ", $self->_datecalc_fails || 1, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_datecalc_fails || 1
MC/DC0%0/1
$self->_datecalc_fails || 1
$self->_datecalc_fails
Truth table0%0/2
A
A= $self->_datecalc_fails
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | print " DateTime : ", $self->_datetime_fails || 1, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_datetime_fails || 1
MC/DC0%0/1
$self->_datetime_fails || 1
$self->_datetime_fails
Truth table0%0/2
A
A= $self->_datetime_fails
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | print "Date::Manip : ", $self->_datemanip_fails || 1, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_datemanip_fails || 1
MC/DC0%0/1
$self->_datemanip_fails || 1
$self->_datemanip_fails
Truth table0%0/2
A
A= $self->_datemanip_fails
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | print " ncal : ", $self->_ncal_fails || 1, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_ncal_fails || 1
MC/DC0%0/1
$self->_ncal_fails || 1
$self->_ncal_fails
Truth table0%0/2
A
A= $self->_ncal_fails
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | print " cal : ", $self->_cal_fails || 1, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cal_fails || 1
MC/DC0%0/1
$self->_cal_fails || 1
$self->_cal_fails
Truth table0%0/2
A
A= $self->_cal_fails
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | sub _is_julian { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_julian: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $y = $self->year; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | $y < 1752 || ($y == 1752 && $self->month <= 9); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$y < 1752 || $y == 1752 && $self->month <= 9
$y == 1752 and $self->month <= 9
MC/DC0%0/3
$y < 1752 || $y == 1752 && $self->month <= 9
$y < 1752
$y == 1752
$self->month <= 9
Truth table0%0/4
A || B and C
A= $y < 1752B= $y == 1752C= $self->month <= 9
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | sub _timelocal_fails { | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 310 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_timelocal_fails: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 310 | ▶ | return "not installed" unless $self->_timelocal_present; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 310 | ▶ | return "week-of-year numbering unsupported" if $self->weeknum; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 310 | my $y = $self->year; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 310 | ▶ | return "only years between 1970 and 2038 supported" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$y < 1970 or $y >= 2038
MC/DC50%1/2
$y < 1970 or $y >= 2038
$y < 1970
$y >= 2038
Truth table66%2/3
A or B
A= $y < 1970B= $y >= 2038
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | if $y < 1970 || $y >= 2038; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 308 | return; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | sub _ncal_fails { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ncal_fails: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | return "command not found" unless $self->_ncal_present; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return "week-of-year numbering not supported prior to 1752/09" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->weeknum and $self->_is_julian
MC/DC0%0/2
$self->weeknum and $self->_is_julian
$self->weeknum
$self->_is_julian
Truth table0%0/3
A and B
A= $self->weeknumB= $self->_is_julian
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | if $self->weeknum && $self->_is_julian; | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | sub _cal_fails { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cal_fails: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | return "command not found" unless $self->_cal_present; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | return "week-of-year numbering not supported" if $self->weeknum; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | sub _datecalc_fails { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_datecalc_fails: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | return "not installed" unless $self->_datecalc_present; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return "historic mode prior to 1752/09 not supported" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->historic and $self->_is_julian
MC/DC0%0/2
$self->historic and $self->_is_julian
$self->historic
$self->_is_julian
Truth table0%0/3
A and B
A= $self->historicB= $self->_is_julian
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | if $self->historic && $self->_is_julian; | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | sub _datetime_fails { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_datetime_fails: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | return "not installed" unless $self->_datetime_present; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | return "historic mode prior to 1752/09 not supported" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->historic and $self->_is_julian
MC/DC0%0/2
$self->historic and $self->_is_julian
$self->historic
$self->_is_julian
Truth table0%0/3
A and B
A= $self->historicB= $self->_is_julian
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | if $self->historic && $self->_is_julian; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | sub _datemanip_fails { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_datemanip_fails: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | return "not installed" unless $self->_datemanip_present; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | return "historic mode prior to 1752/09 not supported" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->historic and $self->_is_julian
MC/DC0%0/2
$self->historic and $self->_is_julian
$self->historic
$self->_is_julian
Truth table0%0/3
A and B
A= $self->historicB= $self->_is_julian
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | if $self->historic && $self->_is_julian; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | eval { require Date::Manip && Date::Manip::Date_Init() }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | return "init failure: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 310 | ▶ | sub _timelocal_present { eval "require Time::Local"; return !$@ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_timelocal_present: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | sub _datecalc_present { eval "require Date::Calc"; return !$@ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_datecalc_present: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub _datetime_present { eval "require DateTime"; return !$@ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_datetime_present: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | sub _datemanip_present { eval "require Date::Manip"; return !$@ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_datemanip_present: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | sub _ncal_present { shift->_ncal_cmd } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ncal_present: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub _cal_present { shift->_cal_cmd }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cal_present: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | HTML::CalendarMonth::DateTool - Base class for determining which date package to use for calendrical calculations. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | my $date_tool = HTML::CalendarMonth::DateTool->new( | ||||||||||||||||||||||||||||||||||||||||||
| 330 | year => $YYYY_year, | ||||||||||||||||||||||||||||||||||||||||||
| 331 | month => $one_thru_12_month, | ||||||||||||||||||||||||||||||||||||||||||
| 332 | weeknum => $weeknum_mode, | ||||||||||||||||||||||||||||||||||||||||||
| 333 | historic => $historic_mode, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | datetool => $specific_datetool_if_desired, | ||||||||||||||||||||||||||||||||||||||||||
| 335 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | This module attempts to utilize the best date calculation package | ||||||||||||||||||||||||||||||||||||||||||
| 340 | available on the current system. For most contemporary dates this | ||||||||||||||||||||||||||||||||||||||||||
| 341 | usually ends up being the internal Time::Local package of perl. For more | ||||||||||||||||||||||||||||||||||||||||||
| 342 | exotic dates, or when week number of the years are desired, other | ||||||||||||||||||||||||||||||||||||||||||
| 343 | methods are attempted including DateTime, Date::Calc, Date::Manip, and | ||||||||||||||||||||||||||||||||||||||||||
| 344 | the linux/unix 'ncal' or 'cal' commands. Each of these has a specific | ||||||||||||||||||||||||||||||||||||||||||
| 345 | subclass of this module offering the same utility methods needed by | ||||||||||||||||||||||||||||||||||||||||||
| 346 | HTML::CalendarMonth. | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | =item new() | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | Constructor. Takes the following parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | =item year | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | Year of calendar in question (required). If you are rendering exotic | ||||||||||||||||||||||||||||||||||||||||||
| 361 | dates (i.e. dates outside of 1970 to 2038) then something besides | ||||||||||||||||||||||||||||||||||||||||||
| 362 | Time::Local will be used for calendrical calculations. | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | =item month | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | Month of calendar in question (required). 1 through 12. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | =item weeknum | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | Optional. When specified, will limit class excursions to those that are | ||||||||||||||||||||||||||||||||||||||||||
| 371 | currently set up for week of year calculations. | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | =item historic | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | Optional. If the the ncal or cal commands are available, use one of them | ||||||||||||||||||||||||||||||||||||||||||
| 376 | rather than other available date modules since these utilities | ||||||||||||||||||||||||||||||||||||||||||
| 377 | accurately handle some specific historical artifacts such as the | ||||||||||||||||||||||||||||||||||||||||||
| 378 | transition from Julian to Gregorian. | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | =item datetool | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | Optional. Mostly for debugging, this option can be used to indicate a | ||||||||||||||||||||||||||||||||||||||||||
| 383 | specific HTML::CalendarMonth::DateTool subclass for instantiation. The | ||||||||||||||||||||||||||||||||||||||||||
| 384 | value can be either the actual utility class, e.g., Date::Calc, or the | ||||||||||||||||||||||||||||||||||||||||||
| 385 | name of the CalendarMonth handler leaf class, e.g. DateCalc. Use 'ncal' | ||||||||||||||||||||||||||||||||||||||||||
| 386 | or 'cal', respectively, for the wrappers around those commands. | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | There are number of methods automatically available: | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | =item month() | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | =item year() | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | =item weeknum() | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | =item historical() | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | =item datetool() | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | Accessors for the parameters provided to C<new()> above. | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | =item dow1st() | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | Returns the day of week number for the 1st of the C<year> and C<month> | ||||||||||||||||||||||||||||||||||||||||||
| 411 | specified during the call to C<new()>. Relies on the presence of | ||||||||||||||||||||||||||||||||||||||||||
| 412 | C<dow1st_and_lastday()>. Should be 0..6 starting with Sun. | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | =item lastday() | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | Returns the last day of the month for the C<year> and C<month> specified | ||||||||||||||||||||||||||||||||||||||||||
| 417 | during the call to C<new()>. Relies on the presence of | ||||||||||||||||||||||||||||||||||||||||||
| 418 | C<dow1st_and_lastday()>. | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | =head1 Overridden methods | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | Subclasses of this module must provide at least the C<day_epoch()> and | ||||||||||||||||||||||||||||||||||||||||||
| 425 | C<dow1st_and_lastday()> methods. | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | =item dow1st_and_lastday() | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | Required. Provides a list containing the day of the week of the first | ||||||||||||||||||||||||||||||||||||||||||
| 432 | day of the month (0..6 starting with Sun) along with the last day of | ||||||||||||||||||||||||||||||||||||||||||
| 433 | the month. | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | =item day_epoch() | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | Optional unless interested in epoch values for wacky dates. For a given | ||||||||||||||||||||||||||||||||||||||||||
| 438 | day, and optionally C<month> and C<year> if they are different from | ||||||||||||||||||||||||||||||||||||||||||
| 439 | those specified in C<new()>, provide the unix epoch in seconds for that | ||||||||||||||||||||||||||||||||||||||||||
| 440 | day at midnight. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | If the subclass is expected to provide week of year numbers, three more | ||||||||||||||||||||||||||||||||||||||||||
| 445 | methods are necessary: | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | =item dow() | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | For a given day, and optionally C<month> and C<year> if they are | ||||||||||||||||||||||||||||||||||||||||||
| 452 | different from those specified in C<new()>, provide the day of week | ||||||||||||||||||||||||||||||||||||||||||
| 453 | number. (0=Sunday, 6=Saturday). | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | =item add_days($days, $delta, $day, [$month], [$year]) | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | For a given day, and optionally C<month> and C<year> if they are | ||||||||||||||||||||||||||||||||||||||||||
| 458 | different from those specified in C<new()>, provide a list of year, | ||||||||||||||||||||||||||||||||||||||||||
| 459 | month, and day once C<delta> days have been added. | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | =item week_of_year($day, [$month], [$year]) | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | For a given day, and optionally C<month> and C<year> if they are | ||||||||||||||||||||||||||||||||||||||||||
| 464 | different from those specified in C<new()>, provide a list with the week | ||||||||||||||||||||||||||||||||||||||||||
| 465 | number of the year along with the year. (some days of a particular year | ||||||||||||||||||||||||||||||||||||||||||
| 466 | can end up belonging to the prior or following years). | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | Matthew P. Sisk, E<lt>F<sisk@mojotoad.com>E<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | Copyright (c) 2010 Matthew P. Sisk. All rights reserved. All wrongs | ||||||||||||||||||||||||||||||||||||||||||
| 477 | revenged. This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 478 | modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | HTML::CalendarMonth(3), Time::Local(3), DateTime(3), Date::Calc(3), | ||||||||||||||||||||||||||||||||||||||||||
| 483 | Date::Manip(3), cal(1) | ||||||||||||||||||||||||||||||||||||||||||