Calendar/CopticEthiopic.pm

filter: Statementstmt 87.3% 62 / 71 Branchbran 43.3% 13 / 30 Conditioncond 18.5% 10 / 54 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 84.2% 16 / 19 Podpod 0.0% 0 / 6 totaltotal 50.0% 101 / 202 CC 34 SCAR 35.4
CC
34
Cov
55%
_isBogusEthiopicDate
132.0
_isBogusGregorianDate
23.2
isLeapYear
12.0
CRAP 34.5
↑ Summary Calendar/Coptic.pm »
1 package DateTime::Calendar::CopticEthiopic;
2 1 ▶use base (DateTime);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 BEGIN
5 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require 5.000;
7  
8 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 $VERSION
12  
13 $true
14 $false
15  
16 @GregorianDaysPerMonth
17  
18 $n
19 1 );
20  
21 1 $VERSION = "0.05"; # based on Date::Ethiopic v0.13
22  
23 1 ($false,$true) = (0,1);
24  
25 1 @GregorianDaysPerMonth = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
26 }
27  
28  
29 #
30 #
31 # Calender System Conversion Methods Below Here:
32 #
33 #
34 sub _AbsoluteToEthiopic
35 1 ▶{
Subroutine _AbsoluteToEthiopic: called CC=1 SCAR=0.0
36 1 my ( $self, $absolute ) = @_;
37  
38 1 my $year = quotient ( 4 * ( $absolute - $self->epoch ) + 1463, 1461 );
39 1 my $month = 1 + quotient ( $absolute - $self->_EthiopicToAbsolute ( 1, 1, $year ), 30 );
40 1 my $day = ( $absolute - $self->_EthiopicToAbsolute ( 1, $month, $year ) + 1 );
41  
42 1 ( $day, $month, $year );
43 }
44  
45  
46 sub fromGregorian
47 1 ▶{
Subroutine fromGregorian: called CC=2 SCAR=7.1
Pod undocumented
48 1 my $self = shift;
49  
50 1 ▶ die ( "Bogus Ethiopic Date!!" ) if ( $self->_isBogusGregorianDate ( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_isBogusGregorianDate(@_) 0 1 1
51  
52 1 $self->_AbsoluteToEthiopic ( $self->_GregorianToAbsolute ( @_ ) );
53 }
54  
55  
56 sub gregorian
57 1 ▶{
Subroutine gregorian: called CC=1 SCAR=0.0
Pod undocumented
58 1 my $self = shift;
59  
60 1 $self->_AbsoluteToGregorian ( $self->_EthiopicToAbsolute ( @_ ) );
61 }
62  
63  
64 sub _isBogusEthiopicDate
65 0 ▶{
Subroutine _isBogusEthiopicDate: not called CC=11 SCAR=48.8
66 0 my $self = shift;
67  
68 0 ▶ my($day, $month, $year) = (@_) ? @_ : ($self->day, $self->month, $self->year);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
69  
70 0 ▶ ( !( 1 <= $day && $day <= 30 )
Branch: 1 branch
BranchTrueFalseTotal
!((1 <= $day && $day <= 30) && (1 <= $month && $month <= 13)) || $month == 13 && $day > 6 || $month == 13 && $day == 6 && !$self->isLeapYear ? : 0 0 0
Condition0%0/24
not +(1 <= $day && $day <= 30) && (1 <= $month && $month <= 13) or $month == 13 and $day > 6 or $month == 13 and $day == 6 and not $self->isLeapYear
l!l&&r!l&&!r
000
not +(1 <= $day && $day <= 30) && (1 <= $month && $month <= 13) or $month == 13 and $day > 6
l!l&&r!l&&!r
000
(1 <= $day && $day <= 30) && (1 <= $month && $month <= 13)
!ll&&!rl&&r
000
1 <= $day and $day <= 30
!ll&&!rl&&r
000
1 <= $month and $month <= 13
!ll&&!rl&&r
000
$month == 13 and $day > 6
!ll&&!rl&&r
000
$month == 13 and $day == 6 and not $self->isLeapYear
!ll&&!rl&&r
000
$month == 13 and $day == 6
!ll&&!rl&&r
000
MC/DC0%0/9
not +(1 <= $day && $day <= 30) && (1 <= $month && $month <= 13) or $month == 13 and $day > 6 or $month == 13 and $day == 6 and not $self->isLeapYear
1 <= $day $day <= 30 1 <= $month $month <= 13 $month == 13 $day > 6 $month == 13 $day == 6 not $self->isLeapYear
Truth table0%0/13
not(A and B && C and D) or E and F or G and H and not(I)
A= 1 <= $dayB= $day <= 30C= 1 <= $monthD= $month <= 13E= $month == 13F= $day > 6G= $month == 13H= $day == 6I= not $self->isLeapYear
ABCDEFGHIresult
0XXXXXXXX1
10XXXXXXX1
110XXXXXX1
1110XXXXX1
111111XXX1
11110X1111
1111101111
11110X0XX0
11110X10X0
11110X1100
1111100XX0
11111010X0
1111101100
71 || !( 1 <= $month && $month <= 13 )
72 || ( $month == 13 && $day > 6 )
73 || ( $month == 13 && $day == 6 && !$self->isLeapYear )
74 )
75 ?
76 $true : $false;
77  
78 }
79  
80  
81 sub _isBogusGregorianDate
82 1 ▶{
Subroutine _isBogusGregorianDate: called CC=9 SCAR=31.5
83 1 my $self = shift;
84  
85 1 ▶ my($day, $month, $year) = (@_) ? @_ : ($self->day, $self->month, $self->year);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
86  
87 1 ▶ ( !( 1 <= $month && $month <= 12 )
Branch: 1 branch
BranchTrueFalseTotal
!((1 <= $month && $month <= 12) && (1 <= $day && $day <= $GregorianDaysPerMonth[$month - 1])) || $day == 29 && $month == 2 && !$self->_isGregorianLeapYear($year) ? : 0 1 1
Condition33%6/18
not +(1 <= $month && $month <= 12) && (1 <= $day && $day <= $GregorianDaysPerMonth[$month - 1]) or $day == 29 and $month == 2 and not $self->_isGregorianLeapYear($year)
l!l&&r!l&&!r
001
(1 <= $month && $month <= 12) && (1 <= $day && $day <= $GregorianDaysPerMonth[$month - 1])
!ll&&!rl&&r
001
1 <= $month and $month <= 12
!ll&&!rl&&r
001
1 <= $day and $day <= $GregorianDaysPerMonth[$month - 1]
!ll&&!rl&&r
001
$day == 29 and $month == 2 and not $self->_isGregorianLeapYear($year)
!ll&&!rl&&r
100
$day == 29 and $month == 2
!ll&&!rl&&r
100
MC/DC0%0/7
not +(1 <= $month && $month <= 12) && (1 <= $day && $day <= $GregorianDaysPerMonth[$month - 1]) or $day == 29 and $month == 2 and not $self->_isGregorianLeapYear($year)
1 <= $month $month <= 12 1 <= $day $day <= $GregorianDaysPerMonth[$month - 1] $day == 29 $month == 2 not $self->_isGregorianLeapYear($year)
Truth table12%1/8
not(A and B && C and D) or E and F and not(G)
A= 1 <= $monthB= $month <= 12C= 1 <= $dayD= $day <= $GregorianDaysPerMonth[$month - 1]E= $day == 29F= $month == 2G= not $self->_isGregorianLeapYear($year)
ABCDEFGresult
0XXXXXX1
10XXXXX1
110XXXX1
1110XXX1
11111111
11110XX0
111110X0
11111100
88 || !( 1 <= $day && $day <= $GregorianDaysPerMonth[$month-1] )
89 || ( $day == 29 && $month == 2 && !$self->_isGregorianLeapYear($year) )
90 )
91 ?
92 $true : $false;
93  
94 }
95  
96  
97 sub _EthiopicToAbsolute
98 5 ▶{
Subroutine _EthiopicToAbsolute: called CC=2 SCAR=6.9
99 5 my $self = shift;
100 5 ▶my ( $date, $month, $year ) = ( @_ ) ? @_ : ($self->day,$self->month,$self->year);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 3 5
101  
102 5 ( $self->epoch - 1 + 365 * ( $year - 1 ) + quotient ( $year, 4 ) + 30 * ( $month - 1 ) + $date );
103 }
104  
105  
106 sub _GregorianYear
107 1 ▶{
Subroutine _GregorianYear: called CC=3 SCAR=11.2
108 1 my ( $a ) = @_;
109  
110 1 my $b = $a - 1;
111 1 my $c = quotient ( $b, 146097 );
112 1 my $d = mod ( $b, 146097 );
113 1 my $e = quotient ( $d, 36524 );
114 1 my $f = mod ( $d, 36524 );
115 1 my $g = quotient ( $f, 1461 );
116 1 my $h = mod ( $f, 1461 );
117 1 my $i = quotient ( $h, 365 );
118 1 my $j = ( 400 * $c ) + ( 100 * $e ) + ( 4 * $g ) + $i;
119  
120 1 ▶ ( ( $e == 4 ) || ( $i == 4 ) )
Branch: 1 branch
BranchTrueFalseTotal
$e == 4 || $i == 4 ? : 0 1 1
Condition33%1/3
$e == 4 or $i == 4
l!l&&r!l&&!r
001
MC/DC0%0/2
$e == 4 or $i == 4
$e == 4 $i == 4
Truth table33%1/3
A or B
A= $e == 4B= $i == 4
ABresult
1X1
011
000
121 ? $j
122 : ( $j + 1 )
123 ;
124 }
125  
126  
127 sub _AbsoluteToGregorian
128 1 ▶{
Subroutine _AbsoluteToGregorian: called CC=3 SCAR=11.2
129 1 my ( $self, $absolute ) = @_;
130  
131 1 my $year = _GregorianYear ( $absolute );
132  
133 1 my $priorDays = ( $absolute - $self->_GregorianToAbsolute ( 1, 1, $year ) );
134  
135 1 ▶ my $correction
Branch: 2 branches
BranchTrueFalseTotal
$absolute < $self->_GregorianToAbsolute(1, 3, $year) ? : 0 1 1
$self->_isGregorianLeapYear($year) ? : 0 1 1
136 = ( $absolute < $self->_GregorianToAbsolute ( 1, 3, $year ) )
137 ? 0
138 : ( $self->_isGregorianLeapYear ( $year ) )
139 ? 1
140 : 2
141 ;
142  
143 1 my $month = quotient ( ( ( 12 * ( $priorDays + $correction ) + 373 ) / 367 ), 1 );
144 1 my $day = $absolute - $self->_GregorianToAbsolute ( 1, $month, $year ) + 1;
145  
146 1 ( $day, $month, $year );
147 }
148  
149  
150 sub _GregorianToAbsolute
151 4 ▶{
Subroutine _GregorianToAbsolute: called CC=4 SCAR=14.1
152 4 my $self = shift;
153 4 ▶my ( $date, $month, $year ) = ( @_ ) ? @_ : ($self->day,$self->month,$self->year);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 0 4
154  
155 4 ▶ my $correction
Branch: 2 branches
BranchTrueFalseTotal
$month <= 2 ? : 1 3 4
$self->_isGregorianLeapYear($year) ? : 0 3 3
156 = ( $month <= 2 )
157 ? 0
158 : ( $self->_isGregorianLeapYear ( $year ) )
159 ? -1
160 : -2
161 ;
162  
163 4 my $absolute =(
164 365 * ( $year - 1 )
165 + quotient ( $year - 1, 4 )
166 - quotient ( $year - 1, 100 )
167 + quotient ( $year - 1, 400 )
168 + ( 367 * $month - 362 ) / 12
169 + $correction + $date
170 );
171  
172 4 quotient ( $absolute, 1 );
173 }
174  
175  
176 sub _isGregorianLeapYear
177 4 ▶{
Subroutine _isGregorianLeapYear: called CC=5 SCAR=21.9
178 4 shift;
179  
180 (
181 4 ▶ ( ( $_[0] % 4 ) != 0 )
Branch: 1 branch
BranchTrueFalseTotal
$_[0] % 4 != 0 || $_[0] % 400 == 100 || $_[0] % 400 == 200 || $_[0] % 400 == 300 ? : 4 0 4
Condition33%3/9
$_[0] % 4 != 0 or $_[0] % 400 == 100 or $_[0] % 400 == 200 or $_[0] % 400 == 300
l!l&&r!l&&!r
400
$_[0] % 4 != 0 or $_[0] % 400 == 100 or $_[0] % 400 == 200
l!l&&r!l&&!r
400
$_[0] % 4 != 0 or $_[0] % 400 == 100
l!l&&r!l&&!r
400
MC/DC0%0/4
$_[0] % 4 != 0 or $_[0] % 400 == 100 or $_[0] % 400 == 200 or $_[0] % 400 == 300
$_[0] % 4 != 0 $_[0] % 400 == 100 $_[0] % 400 == 200 $_[0] % 400 == 300
Truth table20%1/5
A or B or C or D
A= $_[0] % 4 != 0B= $_[0] % 400 == 100C= $_[0] % 400 == 200D= $_[0] % 400 == 300
ABCDresult
1XXX1
01XX1
001X1
00011
00000
182 || ( ( $_[0] % 400 ) == 100 )
183 || ( ( $_[0] % 400 ) == 200 )
184 || ( ( $_[0] % 400 ) == 300 )
185 )
186 ? 0
187 : 1
188 ;
189 }
190  
191  
192 #
193 # argument is an ethiopic year
194 #
195 sub isLeapYear
196 0 ▶{
Subroutine isLeapYear: not called CC=3 SCAR=24.8
Pod undocumented
197 0 my $self = shift;
198 0 ▶my ( $year ) = ( @_ ) ? shift : $self->year;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
199  
200 0 ▶ ( ( $year + 1 ) % 4 ) ? 0 : 1 ;
Branch: 1 branch
BranchTrueFalseTotal
($year + 1) % 4 ? : 0 0 0
201 }
202  
203  
204 sub quotient
205 31 ▶{
Subroutine quotient: called CC=1 SCAR=0.0
Pod undocumented
206 31 $_ = $_[0] / $_[1];
207  
208 31 s/\.(.*)//;
209  
210 31 $_;
211 }
212  
213  
214 sub mod
215 3 ▶{
Subroutine mod: called CC=1 SCAR=0.0
Pod undocumented
216 3 ( $_[0] - $_[1] * quotient ( $_[0], $_[1] ) );
217 }
218  
219  
220 sub toGregorian
221 0 ▶{
Subroutine toGregorian: not called CC=1 SCAR=6.9
Pod undocumented
222 0 my $self = shift;
223  
224 0 my ($day,$month,$year) = $self->gregorian;
225  
226 0 new DateTime ( day => $day, month => $month, year => $year );
227 }
228  
229  
230 #########################################################
231 # Do not change this, Do not put anything below this.
232 # File must return "true" value at termination
233 1 1;
234 ##########################################################
235  
236 __END__
↑ Summary Calendar/Coptic.pm »