blib/lib/DateTime/Calendar/Hebrew.pm

filter: Statementstmt 87.8% 304 / 346 Branchbran 58.5% 75 / 128 Conditioncond 81.3% 61 / 75 MC/DCmcdc 55.8% 19 / 34 Subroutinesub 80.4% 78 / 97 Podpod 90.9% 30 / 33 totaltotal 79.5% 567 / 713 CC 94 SCAR 14.6
CC
94
Cov
80%
_LastDayOfMonth
12.0
set
11.5
_CalendarElapsedDays
11.0
CRAP 4.3
↑ Summary
1 package DateTime::Calendar::Hebrew;
2 12 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use Params::Validate qw/validate SCALAR OBJECT CODEREF/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 $VERSION = '0.05';
7 12 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶use constant HEBREW_EPOCH => -1373429;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 use overload
15 12 ▶ fallback => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
16 '<=>' => '_compare_overload',
17 'cmp' => '_compare_overload',
18 '+' => '_add_overload',
19 12 '-' => '_subtract_overload';
20  
21 12 ▶sub new {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
22 12 my $class = shift;
23 my %p = validate( @_,
24 { year => { type => SCALAR },
25 month => { type => SCALAR, default => 1,
26 callbacks => {
27 'is between 1 and 13' =>
28 12 ▶ sub { $_[0] >= 1 && $_[0] <= 13 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 1 and $_[0] <= 13 12 0 12
29 }
30 },
31 day => { type => SCALAR, default => 1,
32 callbacks => {
33 'is between 1 and 30' =>
34 12 ▶ sub { $_[0] >= 1 && $_[0] <= 30 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 1 and $_[0] <= 30 12 0 12
35 }
36 },
37 hour => { type => SCALAR, default => 0,
38 callbacks => {
39 'is between 0 and 23' =>
40 8 ▶ sub { $_[0] >= 0 && $_[0] <= 23 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 23 8 0 8
41 }
42 },
43 minute => { type => SCALAR, default => 0,
44 callbacks => {
45 'is between 0 and 59' =>
46 8 ▶ sub { $_[0] >= 0 && $_[0] <= 59 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 59 8 0 8
47 }
48 },
49 second => { type => SCALAR, default => 0,
50 callbacks => {
51 'is between 0 and 59' =>
52 5 ▶ sub { $_[0] >= 0 && $_[0] <= 59 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 59 5 0 5
53 }
54 },
55 nanosecond => { type => SCALAR, default => 0,
56 callbacks => {
57 'is between 0 and 999999999' =>
58 4 ▶ sub { $_[0] >= 0 && $_[0] <= 999999999 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 999999999 4 0 4
59 }
60 },
61 12 sunset => { type => OBJECT, optional => 1 },
62 time_zone => { type => SCALAR, optional => 1 },
63 } );
64  
65 12 my $self = bless \%p, $class;
66  
67 12 $self->{rd_days} = &_to_rd(@p{ qw(year month day) });
68 12 $self->{rd_secs} = $p{hour} * 60 * 60 + $p{minute} * 60 + $p{second};
69 12 ▶ if($self->{nanosecond}) { $self->{rd_nanosecs} = delete $self->{nanosecond}; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"nanosecond"}) 1 11 12
70  
71 12 ▶ if($self->{sunset} and $self->{time_zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sunset"} and $self->{"time_zone"}) 2 10 12
Condition66%2/3
$self->{"sunset"} and $self->{"time_zone"}
!ll&&!rl&&r
1002
MC/DC50%1/2
$self->{"sunset"} and $self->{"time_zone"}
$self->{"sunset"} $self->{"time_zone"}
Truth table66%2/3
A and B
A= $self->{"sunset"}B= $self->{"time_zone"}
ABresult
0X0
100
111
72 2 my $DT_Event_Sunrise = $self->{sunset};
73 2 my $time_zone = $self->{time_zone};
74 2 my $DT = DateTime->from_object(object => $self);
75  
76 2 my $sunset = $DT_Event_Sunrise->next($DT->clone->truncate(to => 'day'));
77 2 $sunset->set_time_zone($time_zone);
78  
79 2 ▶ if($DT > $sunset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DT > $sunset) 2 0 2
80 2 $self->{after_sunset} = 1;
81 2 @{$self}{qw/year month day/} = &_from_rd($self->{rd_days} + 1);
82 }
83 }
84  
85 12 return $self;
86 }
87  
88 3 ▶sub from_object {
Subroutine from_object: called CC=4 SCAR=14.0
Pod documented
89 3 my ( $class ) = shift;
90 3 my %p = validate( @_, {
91 object => {
92 type => OBJECT,
93 can => 'utc_rd_values',
94 },
95 });
96  
97 3 my $object = $p{object}->clone();
98 3 ▶ $object->set_time_zone('floating') if $object->can( 'set_time_zone' );
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("set_time_zone") 3 0 3
99  
100 3 my ($rd_days, $rd_secs, $rd_nanosecs) = $object->utc_rd_values();
101 3 ▶ $rd_nanosecs ||= 0;
Condition50%1/2
$rd_nanosecs ||= 0
l!l
03
MC/DC0%0/1
$rd_nanosecs ||= 0
$rd_nanosecs
Truth table50%1/2
A
A= $rd_nanosecs
Aresult
11
00
102  
103 3 my %args;
104 3 @args{ qw( year month day ) } = &_from_rd($rd_days);
105  
106 3 my($h, $m, $s);
107 3 $s = $rd_secs % 60;
108 3 $m = int($rd_secs / 60);
109 3 $h = int($m / 60);
110 3 $m %= 60;
111 3 @args{ qw(hour minute second) } = ($h, $m, $s);
112  
113 3 ▶ $args{nanosecond} = $rd_nanosecs || 0;
Condition50%1/2
$rd_nanosecs || 0
l!l
03
MC/DC0%0/1
$rd_nanosecs || 0
$rd_nanosecs
Truth table50%1/2
A
A= $rd_nanosecs
Aresult
11
00
114  
115 3 my $new_object = $class->new(%args);
116  
117 3 return $new_object;
118 }
119  
120 1 ▶sub set {
Subroutine set: called CC=6 SCAR=24.4
Pod documented
121 1 my $self = shift;
122 my %p = validate( @_,
123 { year => { type => SCALAR, optional => 1 },
124 month => { type => SCALAR, optional => 1,
125 callbacks => {
126 'is between 1 and 13' =>
127 1 ▶ sub { $_[0] >= 1 && $_[0] <= 13 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 1 and $_[0] <= 13 1 0 1
128 }
129 },
130 day => { type => SCALAR, optional => 1,
131 callbacks => {
132 'is between 1 and 30' =>
133 1 ▶ sub { $_[0] >= 1 && $_[0] <= 30 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 1 and $_[0] <= 30 1 0 1
134 }
135 },
136 hour => { type => SCALAR, optional => 1,
137 callbacks => {
138 'is between 0 and 23' =>
139 1 ▶ sub { $_[0] >= 0 && $_[0] <= 23 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 23 1 0 1
140 }
141 },
142 minute => { type => SCALAR, optional => 1,
143 callbacks => {
144 'is between 0 and 59' =>
145 1 ▶ sub { $_[0] >= 0 && $_[0] <= 59 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 59 1 0 1
146 }
147 },
148 second => { type => SCALAR, optional => 1,
149 callbacks => {
150 'is between 0 and 59' =>
151 1 ▶ sub { $_[0] >= 0 && $_[0] <= 59 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 59 1 0 1
152 }
153 },
154 nanosecond => { type => SCALAR, optional => 1,
155 callbacks => {
156 'is between 0 and 999999999' =>
157 0 ▶ sub { $_[0] >= 0 && $_[0] <= 999999999 }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] >= 0 and $_[0] <= 999999999 0 0 0
158 }
159 },
160 1 sunset => { type => OBJECT, optional => 1 },
161 time_zone => { type => SCALAR, optional => 1 },
162 } );
163  
164 1 $self->{$_} = $p{$_} for keys %p;
165  
166 1 $self->{rd_days} = &_to_rd($self->{year}, $self->{month}, $self->{day});
167 1 $self->{rd_secs} = $self->{hour} * 60 * 60 + $self->{minute} * 60 + $self->{second};
168 0 ▶ if($self->{nanosecond}) { $self->{rd_nanosecs} = delete $self->{nanosecond}; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"nanosecond"}) 0 1 1
169  
170 1 ▶ if($self->{sunset} and $self->{time_zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sunset"} and $self->{"time_zone"}) 0 1 1
Condition33%1/3
$self->{"sunset"} and $self->{"time_zone"}
!ll&&!rl&&r
100
MC/DC0%0/2
$self->{"sunset"} and $self->{"time_zone"}
$self->{"sunset"} $self->{"time_zone"}
Truth table33%1/3
A and B
A= $self->{"sunset"}B= $self->{"time_zone"}
ABresult
0X0
100
111
171 0 my $DT_Event_Sunrise = $self->{sunset};
172 0 my $time_zone = $self->{time_zone};
173 0 my $DT = DateTime->from_object(object => $self);
174  
175 0 my $sunset = $DT_Event_Sunrise->next($DT->clone->truncate(to => 'day'));
176 0 $sunset->set_time_zone($time_zone);
177  
178 0 ▶ if($DT > $sunset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DT > $sunset) 0 0 0
179 0 $self->{after_sunset} = 1;
180 0 @{$self}{qw/year month day/} = &_from_rd($self->{rd_days} + 1);
181 }
182 }
183  
184 1 return $self;
185 }
186  
187 15 ▶sub utc_rd_values {
Subroutine utc_rd_values: called CC=2 SCAR=6.9
Pod documented
188 15 my $self = shift;
189 15 my @res = @{$self}{ qw/rd_days rd_secs rd_nanosecs/ };
190 # Protect against undef
191 15 ▶ $res[2] ||= 0;
Condition100%2/2
$res[2] ||= 0
l!l
312
MC/DC100%1/1
$res[2] ||= 0
$res[2]
Truth table100%2/2
A
A= $res[2]
Aresult
11
00
192 15 return @res;
193 }
194  
195 2 ▶sub utc_rd_as_seconds {
Subroutine utc_rd_as_seconds: called CC=1 SCAR=0.0
Pod documented
196 2 my $self = shift;
197 2 my ($rd_days, $rd_secs, $rd_nanosecs) = $self->utc_rd_values;
198  
199 2 return $rd_days*24*60*60 + $rd_secs;
200 }
201  
202 9 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
203 9 my $self = shift;
204 9 my $clone = {%$self};
205 9 bless $clone, ref $self;
206 9 return $clone;
207 }
208  
209 4 ▶sub _compare_overload {
Subroutine _compare_overload: called CC=2 SCAR=7.6
210 4 ▶ return $_[2] ? - $_[0]->_compare($_[1]) : $_[0]->_compare($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 4 4
211 }
212  
213 4 ▶sub _compare {
Subroutine _compare: called CC=6 SCAR=19.9
214 4 my($a, $b) = @_;
215  
216 4 ▶ return undef unless defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 4 4
217  
218 4 ▶ unless($a->can('utc_rd_values') and $b->can('utc_rd_values')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($a->can("utc_rd_values") and $b->can("utc_rd_values")) 0 4 4
Condition33%1/3
$a->can("utc_rd_values") and $b->can("utc_rd_values")
!ll&&!rl&&r
004
MC/DC0%0/2
$a->can("utc_rd_values") and $b->can("utc_rd_values")
$a->can("utc_rd_values") $b->can("utc_rd_values")
Truth table33%1/3
A and B
A= $a->can("utc_rd_values")B= $b->can("utc_rd_values")
ABresult
0X0
100
111
219 0 die "Cannot compare a datetime to a regular scalar";
220 }
221  
222 4 my @a = $a->utc_rd_values;
223 4 my @b = $b->utc_rd_values;
224  
225 4 foreach my $i (0..2) {
226 12 ▶ return ($a[$i] <=> $b[$i]) if($a[$i] != $b[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $a[$i] != $b[$i] 0 12 12
227 }
228  
229 4 return 0;
230 }
231  
232 2 ▶sub _add_overload {
Subroutine _add_overload: called CC=2 SCAR=7.1
233 2 my($dt, $dur, $reversed) = @_;
234 2 ▶ ($dur,$dt) = ($dt,$dur) if $reversed;
Branch: 1 branch
BranchTrueFalseTotal
if $reversed 0 2 2
235 2 return $dt->clone->add_duration($dur);
236 }
237  
238 2 ▶sub _subtract_overload {
Subroutine _subtract_overload: called CC=2 SCAR=7.1
239 2 my($dt, $dur, $reversed) = @_;
240 2 ▶ ($dur,$dt) = ($dt,$dur) if $reversed;
Branch: 1 branch
BranchTrueFalseTotal
if $reversed 0 2 2
241 2 return $dt->clone->subtract_duration($dur);
242 }
243  
244 8 ▶sub add_duration {
Subroutine add_duration: called CC=7 SCAR=20.5
Pod documented
245 8 my ($self, $dur) = @_;
246 8 my %deltas = $dur->deltas;
247  
248 8 ▶ if($deltas{days}) { $self->{rd_days} += $deltas{days}; }
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"days"}) 8 0 8
249 0 ▶ if($deltas{hours}) { $self->{rd_secs} += $deltas{hours} * 60 * 60; }
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"hours"}) 0 8 8
250 8 ▶ if($deltas{minutes}) { $self->{rd_secs} += $deltas{minutes} * 60; }
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"minutes"}) 8 0 8
251 8 ▶ if($deltas{seconds}) { $self->{rd_secs} += $deltas{seconds}; }
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"seconds"}) 8 0 8
252 0 ▶ if($deltas{nanoseconds}) { $self->{rd_nanosecs} += $deltas{nanoseconds}; }
Branch: 1 branch
BranchTrueFalseTotal
if ($deltas{"nanoseconds"}) 0 8 8
253  
254 8 ▶ while($self->{rd_secs} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rd_secs"} < 0) 8 8 16
255 8 $self->{rd_days}--;
256 8 $self->{rd_secs} += (24 * 60 * 60);
257 }
258  
259 8 return $self->_normalize;
260 }
261  
262 4 ▶sub subtract_duration {
Subroutine subtract_duration: called CC=1 SCAR=0.0
Pod documented
263 4 my ($self, $dur) = @_;
264 4 return $self->add_duration($dur->inverse);
265 }
266  
267 8 ▶sub _normalize {
Subroutine _normalize: called CC=1 SCAR=0.0
268 8 my($self) = shift;
269  
270 8 my($h, $m, $s, $d);
271 8 $s = $self->{rd_secs} % 60;
272 8 $m = int($self->{rd_secs} / 60);
273 8 $h = int($m / 60);
274 8 $m %= 60;
275 8 $d = int($h / 24);
276 8 $h %= 24;
277  
278 8 $self->{rd_days} += $d;
279 8 $self->{rd_secs} = ($h * 60 * 60) + ($m * 60) + $s;
280  
281 8 @{$self}{qw/year month day/} = &_from_rd($self->{rd_days});
282 8 @{$self}{qw/hour minute second/} = ($h, $m, $s);
283
284 8 return $self;
285 }
286  
287 1 ▶sub now {
Subroutine now: called CC=2 SCAR=7.2
Pod documented
288 1 my $class = shift;
289 1 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
290  
291 1 my $dt = DateTime->now;
292 1 my $ht = $class->from_object(object => $dt);
293 1 return($ht);
294 }
295  
296 1 ▶sub today {
Subroutine today: called CC=2 SCAR=7.2
Pod documented
297 1 my $class = shift;
298 1 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
299  
300 1 my $dt = DateTime->today;
301 1 my $ht = $class->from_object(object => $dt);
302 1 return($ht);
303 }
304  
305 13 ▶sub _from_rd {
Subroutine _from_rd: called CC=4 SCAR=13.9
306 13 my $rd = shift;
307  
308 13 my ($year, $month, $day);
309 13 $year = int(($rd - HEBREW_EPOCH) / 366);
310 13 ▶ while ($rd >= &_to_rd($year + 1, 7, 1)) { $year++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($rd >= &_to_rd($year + 1, 7, 1)) 122 13 135
311 13 ▶ if ($rd < &_to_rd($year, 1, 1)) { $month = 7; }
Branch: 1 branch
BranchTrueFalseTotal
if ($rd < &_to_rd($year, 1, 1)) { } 6 7 13
312 7 else { $month = 1; }
313 13 ▶ while ($rd > &_to_rd($year, $month, (&_LastDayOfMonth($year, $month)))) { $month++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($rd > &_to_rd($year, $month, &_LastDayOfMonth($year, $month))) 25 13 38
314 13 $day = $rd - &_to_rd($year, $month, 1) + 1;
315  
316 13 return $year, $month, $day;
317 }
318  
319 215 ▶sub _to_rd {
Subroutine _to_rd: called CC=6 SCAR=17.9
320 215 my ($year, $month, $day) = @_;
321 215 ▶ if(scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 215 0 215
322 215 ($year, $month, $day) = @_;
323 }
324  
325 215 my($m, $DayInYear);
326  
327 215 $DayInYear = $day;
328 215 ▶ if ($month < 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($month < 7) { } 57 158 215
329 57 $m = 7;
330 57 ▶ while ($m <= (&_LastMonthOfYear($year))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m <= &_LastMonthOfYear($year)) 393 57 450
331 393 $DayInYear += &_LastDayOfMonth($year, $m++);
332 }
333 57 $m = 1;
334 57 ▶ while ($m < $month) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m < $month) 81 57 138
335 81 $DayInYear += &_LastDayOfMonth($year, $m);
336 81 $m++;
337 }
338 }
339 else {
340 158 $m = 7;
341 158 ▶ while ($m < $month) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m < $month) 26 158 184
342 26 $DayInYear += &_LastDayOfMonth($year, $m);
343 26 $m++;
344 }
345 }
346  
347 215 return($DayInYear + (&_CalendarElapsedDays($year) + HEBREW_EPOCH));
348 }
349  
350 610 ▶sub _leap_year {
Subroutine _leap_year: called CC=2 SCAR=6.9
351 610 my $year = shift;
352  
353 610 ▶ if ((((7 * $year) + 1) % 19) < 7) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ((7 * $year + 1) % 19 < 7) { } 556 54 610
354 54 else { return 0; }
355 }
356  
357 450 ▶sub _LastMonthOfYear {
Subroutine _LastMonthOfYear: called CC=2 SCAR=6.9
358 450 my $year = shift;
359  
360 450 ▶ if (&_leap_year($year)) { return 13; }
Branch: 1 branch
BranchTrueFalseTotal
if (&_leap_year($year)) { } 408 42 450
361 42 else { return 12; }
362 }
363  
364 481 ▶sub _CalendarElapsedDays {
Subroutine _CalendarElapsedDays: called CC=11 SCAR=24.0
365 481 my $year = shift;
366  
367 481 my($MonthsElapsed, $PartsElapsed, $HoursElapsed, $ConjunctionDay, $ConjunctionParts);
368 481 my($AlternativeDay);
369  
370 481 $MonthsElapsed = (235 * int(($year - 1) / 19)) + (12 * (($year - 1) % 19)) + int((7 * (($year - 1) % 19) + 1) / 19);
371 481 $PartsElapsed = 204 + 793 * ($MonthsElapsed % 1080);
372 481 $HoursElapsed = 5 + 12 * $MonthsElapsed + 793 * int($MonthsElapsed / 1080) + int($PartsElapsed / 1080);
373 481 $ConjunctionDay = 1 + 29 * $MonthsElapsed + int($HoursElapsed / 24);
374 481 $ConjunctionParts = 1080 * ($HoursElapsed % 24) + $PartsElapsed % 1080;
375  
376 481 $AlternativeDay = 0;
377 481 ▶ if (($ConjunctionParts >= 19440) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($ConjunctionParts >= 19440 or $ConjunctionDay % 7 == 2 and $ConjunctionParts >= 9924 and not &_leap_year($year) or $ConjunctionDay % 7 == 1 and $ConjunctionParts >= 16789 and &_leap_year($year - 1)) { } 273 208 481
Condition88%16/18
$ConjunctionParts >= 19440 or $ConjunctionDay % 7 == 2 and $ConjunctionParts >= 9924 and not &_leap_year($year) or $ConjunctionDay % 7 == 1 and $ConjunctionParts >= 16789 and &_leap_year($year - 1)
l!l&&r!l&&!r
17796208
$ConjunctionParts >= 19440 or $ConjunctionDay % 7 == 2 and $ConjunctionParts >= 9924 and not &_leap_year($year)
l!l&&r!l&&!r
1770304
$ConjunctionDay % 7 == 2 and $ConjunctionParts >= 9924 and not &_leap_year($year)
!ll&&!rl&&r
30310
$ConjunctionDay % 7 == 2 and $ConjunctionParts >= 9924
!ll&&!rl&&r
289141
$ConjunctionDay % 7 == 1 and $ConjunctionParts >= 16789 and &_leap_year($year - 1)
!ll&&!rl&&r
202696
$ConjunctionDay % 7 == 1 and $ConjunctionParts >= 16789
!ll&&!rl&&r
17428102
MC/DC57%4/7
$ConjunctionParts >= 19440 or $ConjunctionDay % 7 == 2 and $ConjunctionParts >= 9924 and not &_leap_year($year) or $ConjunctionDay % 7 == 1 and $ConjunctionParts >= 16789 and &_leap_year($year - 1)
$ConjunctionParts >= 19440 $ConjunctionDay % 7 == 2 $ConjunctionParts >= 9924 not &_leap_year($year) $ConjunctionDay % 7 == 1 $ConjunctionParts >= 16789 &_leap_year($year - 1)
Truth table50%7/14
A or B and C and not(D) or E and F and G
A= $ConjunctionParts >= 19440B= $ConjunctionDay % 7 == 2C= $ConjunctionParts >= 9924D= not &_leap_year($year)E= $ConjunctionDay % 7 == 1F= $ConjunctionParts >= 16789G= &_leap_year($year - 1)
ABCDEFGresult
1XXXXXX1
0111XXX1
00XX1111
010X1111
01101111
00XX0XX0
00XX10X0
00XX1100
010X0XX0
010X10X0
010X1100
01100XX0
011010X0
01101100
378 ((($ConjunctionDay % 7) == 2)
379 && ($ConjunctionParts >= 9924)
380 && (!&_leap_year($year))) ||
381 ((($ConjunctionDay % 7) == 1)
382 && ($ConjunctionParts >= 16789)
383 && (&_leap_year($year - 1))))
384 273 { $AlternativeDay = $ConjunctionDay + 1; }
385 208 else { $AlternativeDay = $ConjunctionDay; }
386  
387 481 ▶ if ((($AlternativeDay % 7) == 0) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($AlternativeDay % 7 == 0 or $AlternativeDay % 7 == 3 or $AlternativeDay % 7 == 5) { } 223 258 481
Condition100%6/6
$AlternativeDay % 7 == 0 or $AlternativeDay % 7 == 3 or $AlternativeDay % 7 == 5
l!l&&r!l&&!r
16459258
$AlternativeDay % 7 == 0 or $AlternativeDay % 7 == 3
l!l&&r!l&&!r
20144317
MC/DC100%3/3
$AlternativeDay % 7 == 0 or $AlternativeDay % 7 == 3 or $AlternativeDay % 7 == 5
$AlternativeDay % 7 == 0 $AlternativeDay % 7 == 3 $AlternativeDay % 7 == 5
Truth table100%4/4
A or B or C
A= $AlternativeDay % 7 == 0B= $AlternativeDay % 7 == 3C= $AlternativeDay % 7 == 5
ABCresult
1XX1
01X1
0011
0000
388 (($AlternativeDay % 7) == 3) ||
389 (($AlternativeDay % 7) == 5))
390 223 { return (1 + $AlternativeDay); }
391 258 else { return $AlternativeDay; }
392 }
393  
394 133 ▶sub _DaysInYear {
Subroutine _DaysInYear: called CC=1 SCAR=0.0
395 133 my $year = shift;
396 133 return ((&_CalendarElapsedDays($year + 1)) - (&_CalendarElapsedDays($year)));
397 }
398  
399 70 ▶sub _LongCheshvan {
Subroutine _LongCheshvan: called CC=2 SCAR=6.9
400 70 my $year = shift;
401 70 ▶ if ((&_DaysInYear($year) % 10) == 5) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (&_DaysInYear($year) % 10 == 5) { } 19 51 70
402 51 else { return 0; }
403 }
404  
405 63 ▶sub _ShortKislev {
Subroutine _ShortKislev: called CC=2 SCAR=6.9
406 63 my $year = shift;
407 63 ▶ if ((&_DaysInYear($year) % 10) == 3) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (&_DaysInYear($year) % 10 == 3) { } 43 20 63
408 20 else { return 0; }
409 }
410  
411 553 ▶sub _LastDayOfMonth {
Subroutine _LastDayOfMonth: called CC=12 SCAR=24.9
412 553 my ($year, $month) = @_;
413  
414 553 ▶ if (($month == 2) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year) or $month == 9 and &_ShortKislev($year) or $month == 10 or $month == 12 and not &_leap_year($year) or $month == 13) { } 259 294 553
Condition96%29/30
$month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year) or $month == 9 and &_ShortKislev($year) or $month == 10 or $month == 12 and not &_leap_year($year) or $month == 13
l!l&&r!l&&!r
20851294
$month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year) or $month == 9 and &_ShortKislev($year) or $month == 10 or $month == 12 and not &_leap_year($year)
l!l&&r!l&&!r
2026345
$month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year) or $month == 9 and &_ShortKislev($year) or $month == 10
l!l&&r!l&&!r
14458351
$month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year) or $month == 9 and &_ShortKislev($year)
l!l&&r!l&&!r
10143409
$month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year)
l!l&&r!l&&!r
5051452
$month == 2 or $month == 4 or $month == 6
l!l&&r!l&&!r
500503
$month == 2 or $month == 4
l!l&&r!l&&!r
3020503
$month == 8 and not &_LongCheshvan($year)
!ll&&!rl&&r
4331951
$month == 9 and &_ShortKislev($year)
!ll&&!rl&&r
3892043
$month == 12 and not &_leap_year($year)
!ll&&!rl&&r
294516
MC/DC90%10/11
$month == 2 or $month == 4 or $month == 6 or $month == 8 and not &_LongCheshvan($year) or $month == 9 and &_ShortKislev($year) or $month == 10 or $month == 12 and not &_leap_year($year) or $month == 13
$month == 2 $month == 4 $month == 6 $month == 8 not &_LongCheshvan($year) $month == 9 &_ShortKislev($year) $month == 10 $month == 12 not &_leap_year($year) $month == 13
Truth table36%11/30
A or B or C or D and not(E) or F and G or H or I and not(J) or K
A= $month == 2B= $month == 4C= $month == 6D= $month == 8E= not &_LongCheshvan($year)F= $month == 9G= &_ShortKislev($year)H= $month == 10I= $month == 12J= not &_leap_year($year)K= $month == 13
ABCDEFGHIJKresult
1XXXXXXXXXX1
01XXXXXXXXX1
001XXXXXXXX1
00011XXXXXX1
0000X11XXXX1
0001011XXXX1
0000X0X1XXX1
0000X101XXX1
000100X1XXX1
00010101XXX1
0000X0X011X1
0000X10011X1
000100X011X1
0001010011X1
0000X0X00X11
0000X0X01011
0000X1000X11
0000X1001011
000100X00X11
000100X01011
000101000X11
000101001011
0000X0X00X00
0000X0X01000
0000X1000X00
0000X1001000
000100X00X00
000100X01000
000101000X00
000101001000
415 ($month == 4) ||
416 ($month == 6) ||
417 (($month == 8) && (! &_LongCheshvan($year))) ||
418 (($month == 9) && &_ShortKislev($year)) ||
419 ($month == 10) ||
420 (($month == 12) && (!&_leap_year($year))) ||
421 259 ($month == 13)) { return 29; }
422 294 else { return 30; }
423 }
424  
425 2 ▶sub month_name {
Subroutine month_name: called CC=2 SCAR=7.4
Pod documented
426 2 my $self = shift;
427 2 my $month = $self->month;
428 0 ▶ if(@_) { $month = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
429  
430 2 return (qw/Nissan Iyar Sivan Tamuz Av Elul Tishrei Cheshvan Kislev Tevet Shevat AdarI AdarII/)[$month-1];
431 }
432  
433 2 ▶sub day_name {
Subroutine day_name: called CC=2 SCAR=7.4
Pod documented
434 2 my $self = shift;
435 2 my $day = $self->day_of_week;
436 0 ▶ if(@_) { $day = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
437  
438 2 return (qw/Sunday Monday Tuesday Wednesday Thursday Friday Shabbos/)[$day - 1];
439 }
440  
441 12 ▶use DateTime::TimeZone::Floating qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
442 6 ▶sub time_zone { DateTime::TimeZone::Floating->new() }
Subroutine time_zone: called CC=1 SCAR=0.0
Pod undocumented
443  
444  
445 11 ▶sub year { $_[0]->{year} }
Subroutine year: called CC=1 SCAR=0.0
Pod documented
446  
447 10 ▶sub month { $_[0]->{month} }
Subroutine month: called CC=1 SCAR=0.0
Pod documented
448 12 *mon = \&month;
449  
450 1 ▶sub month_0 { $_[0]->month - 1 }
Subroutine month_0: called CC=1 SCAR=0.0
Pod undocumented
451 12 *mon_0 = \&month_0;
452  
453 9 ▶sub day_of_month { $_[0]->{day} }
Subroutine day_of_month: called CC=1 SCAR=0.0
Pod documented
454 12 *day = \&day_of_month;
455 12 *mday = \&day_of_month;
456  
457 1 ▶sub day_of_month_0 { $_[0]->day - 1 }
Subroutine day_of_month_0: called CC=1 SCAR=0.0
Pod documented
458 12 *day_0 = \&day_of_month_0;
459 12 *mday_0 = \&day_of_month_0;
460  
461 3 ▶sub day_of_week {
Subroutine day_of_week: called CC=2 SCAR=7.6
Pod documented
462 3 my $rd_days = $_[0]->{rd_days};
463 0 ▶ if($_[0]->{after_sunset}) { $rd_days++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"after_sunset"}) 0 3 3
464 3 return $rd_days % 7 + 1;
465 }
466 12 *wday = \&day_of_week;
467 12 *dow = \&day_of_week;
468  
469 4 ▶sub day_of_week_0 {
Subroutine day_of_week_0: called CC=2 SCAR=7.6
Pod documented
470 4 my $rd_days = $_[0]->{rd_days};
471 0 ▶ if($_[0]->{after_sunset}) { $rd_days++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"after_sunset"}) 0 4 4
472 4 return $rd_days % 7;
473 }
474 12 *wday_0 = \&day_of_week_0;
475 12 *dow_0 = \&day_of_week_0;
476  
477 1 ▶sub hour { $_[0]->{hour} }
Subroutine hour: called CC=1 SCAR=0.0
Pod documented
478 12 *hr = \&hour;
479  
480 1 ▶sub minute { $_[0]->{minute} }
Subroutine minute: called CC=1 SCAR=0.0
Pod documented
481 12 *min = \&minute;
482  
483 1 ▶sub second { $_[0]->{second} }
Subroutine second: called CC=1 SCAR=0.0
Pod documented
484 12 *sec = \&second;
485  
486 6 ▶sub day_of_year {
Subroutine day_of_year: called CC=2 SCAR=6.9
Pod documented
487 6 my $self = shift;
488 6 my ($year, $month, $day) = @{$self}{qw/year month day/};
489  
490 6 my $m = 1;
491 6 ▶ while ($m < $month) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m < $month) 15 6 21
492 15 $day += &_LastDayOfMonth($year, $m);
493 15 $m++;
494 }
495 6 return $day;
496 }
497 12 *doy = \&day_of_year;
498  
499 3 ▶sub week_number {
Subroutine week_number: called CC=1 SCAR=0.0
Pod undocumented
500 3 my $self = shift;
501  
502 3 my $day_of_year = $self->day_of_year;
503 3 my $start_of_year = &_to_rd($self->year, 1, 1);
504 3 my $first_week_started_on = $start_of_year % 7 + 1;
505  
506 3 return (($day_of_year + (7 - $first_week_started_on)) / 7) + 1;
507 }
508  
509 1 ▶sub day_of_year_0 { $_[0]->day_of_year - 1; }
Subroutine day_of_year_0: called CC=1 SCAR=0.0
Pod documented
510 12 *doy_0 = \&day_of_year_0;
511  
512 0 ▶sub hms {
Subroutine hms: not called CC=2 SCAR=17.9
Pod documented
513 0 my ($self, $sep) = @_;
514 0 ▶ $sep = ':' unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 0 0 0
515  
516 0 return sprintf( "%02d%s%02d%s%02d",
517 $self->hour, $sep,
518 $self->minute, $sep,
519 $self->second );
520 }
521 12 *time = \&hms;
522  
523 0 ▶sub hm {
Subroutine hm: not called CC=2 SCAR=17.9
Pod documented
524 0 my ($self, $sep) = @_;
525 0 ▶ $sep = ':' unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 0 0 0
526  
527 0 return sprintf( "%02d%s%02d",
528 $self->hour, $sep,
529 $self->minute );
530 }
531  
532 2 ▶sub ymd {
Subroutine ymd: called CC=2 SCAR=6.9
Pod documented
533 2 my ($self, $sep) = @_;
534 2 ▶ $sep = '-' unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 1 1 2
535  
536 2 return sprintf( "%04d%s%02d%s%02d",
537 $self->year, $sep,
538 $self->month, $sep,
539 $self->day );
540 }
541 12 *date = \&ymd;
542  
543 1 ▶sub mdy {
Subroutine mdy: called CC=2 SCAR=7.1
Pod documented
544 1 my ($self, $sep) = @_;
545 1 ▶ $sep = '-' unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 0 1 1
546  
547 1 return sprintf( "%02d%s%02d%s%04d",
548 $self->month, $sep,
549 $self->day, $sep,
550 $self->year );
551 }
552  
553 1 ▶sub dmy {
Subroutine dmy: called CC=2 SCAR=7.1
Pod documented
554 1 my ($self, $sep) = @_;
555 1 ▶ $sep = '-' unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 0 1 1
556  
557 1 return sprintf( "%02d%s%02d%s%04d",
558 $self->day, $sep,
559 $self->month, $sep,
560 $self->year );
561 }
562  
563 0 ▶sub datetime {
Subroutine datetime: not called CC=1 SCAR=6.9
Pod documented
564 0 my $self = shift;
565 0 return ($self->ymd('-') . "T" . $self->hms);
566 }
567  
568 my %formats = (
569 1 ▶ 'A' => sub { $_[0]->day_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
570 1 ▶ 'a' => sub { my $a = $_[0]->day_of_week_0; (qw/Sun Mon Tue Wed Thu Fri Shabbat/)[$a] },
Subroutine __ANON__: called CC=1 SCAR=0.0
571 1 ▶ 'B' => sub { $_[0]->month_name },
Subroutine __ANON__: called CC=1 SCAR=0.0
572 2 ▶ 'd' => sub { sprintf( '%02d', $_[0]->day) },
Subroutine __ANON__: called CC=1 SCAR=0.0
573 1 ▶ 'D' => sub { $_[0]->strftime( '%m/%d/%Y') },
Subroutine __ANON__: called CC=1 SCAR=0.0
574 1 ▶ 'e' => sub { sprintf( '%2d', $_[0]->day) },
Subroutine __ANON__: called CC=1 SCAR=0.0
575 1 ▶ 'F' => sub { $_[0]->ymd('-') },
Subroutine __ANON__: called CC=1 SCAR=0.0
576 1 ▶ 'j' => sub { sprintf('%03d', $_[0]->day_of_year) },
Subroutine __ANON__: called CC=1 SCAR=0.0
577 0 ▶ 'H' => sub { sprintf('%02d', $_[0]->hour) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
578 0 ▶ 'I' => sub { ($_[0]->hour == 12) ? '12' : sprintf('%02d', ($_[0]->hour % 12)) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->hour == 12 ? : 0 0 0
579 0 ▶ 'k' => sub { sprintf('%2d', $_[0]->hour) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
580 0 ▶ 'l' => sub { ($_[0]->hour == 12) ? '12' : sprintf('%2d', ($_[0]->hour % 12)) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->hour == 12 ? : 0 0 0
581 0 ▶ 'M' => sub { sprintf('%02d', $_[0]->minute) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
582 2 ▶ 'm' => sub { sprintf('%02d', $_[0]->month) },
Subroutine __ANON__: called CC=1 SCAR=0.0
583 0 ▶ 'n' => sub { "\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
584 0 ▶ 'P' => sub { ($_[0]->hour >= 12) ? "PM" : "AM" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->hour >= 12 ? : 0 0 0
585 0 ▶ 'p' => sub { ($_[0]->hour >= 12) ? "pm" : "am" },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->hour >= 12 ? : 0 0 0
586 0 ▶ 'r' => sub { $_[0]->strftime( '%I:%M:%S %p') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
587 0 ▶ 'R' => sub { $_[0]->strftime( '%H:%M') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
588 0 ▶ 'S' => sub { sprintf('%02d', $_[0]->second) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
589 0 ▶ 'T' => sub { $_[0]->strftime( '%H:%M:%S') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
590 0 ▶ 't' => sub { "\t" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
591 1 ▶ 'u' => sub { my $u = $_[0]->day_of_week_0; $u == 0 ? 7 : $u },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$u == 0 ? : 0 1 1
592 2 ▶ 'U' => sub { my $w = $_[0]->week_number; defined $w ? sprintf('%02d', $w) : ' ' },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $w ? : 2 0 2
593 1 ▶ 'w' => sub { $_[0]->day_of_week_0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
594 0 ▶ 'W' => sub { sprintf('%02d', $_[0]->week_number) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
595 1 ▶ 'y' => sub { sprintf('%02d', substr($_[0]->year, -2)) },
Subroutine __ANON__: called CC=1 SCAR=0.0
596 2 ▶ 'Y' => sub { return $_[0]->year },
Subroutine __ANON__: called CC=1 SCAR=0.0
597 0 ▶ '%' => sub { '%' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
598 12 );
599 12 $formats{W} = $formats{V} = $formats{U};
600  
601 16 ▶sub strftime {
Subroutine strftime: called CC=4 SCAR=14.9
Pod documented
602 16 my ($self, @r) = @_;
603  
604 16 foreach (@r) {
605 16 ▶ s/%([%*A-Za-z])/ $formats{$1} ? $formats{$1}->($self) : $1 /ge;
Branch: 1 branch
BranchTrueFalseTotal
$formats{$1} ? : 18 0 18
606 16 ▶ return $_ unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 16 0 16
607 }
608 0 return @r;
609 }
610  
611  
612  
613 12 1;
614 __END__
↑ Summary