blib/lib/Time/Moment/Adjusters.pm

filter: Statementstmt 95.6% 87 / 91 Branchbran 50.0% 22 / 44 Conditioncond 33.3% 11 / 33 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 92.5% 25 / 27 Podpod 100% 11 / 11 totaltotal 68.7% 156 / 227 CC 34 SCAR 14.3
CC
34
Cov
71%
NthDayOfWeekInMonth
9.4
OrthodoxEasterSunday
6.0
NextDayOfWeek
4.5
CRAP 4.2
↑ Summary blib/lib/Time/Moment.pm »
1 package Time::Moment::Adjusters;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '0.46';
9 1 our @EXPORT_OK = qw[ NextDayOfWeek
10 NextOrSameDayOfWeek
11 PreviousDayOfWeek
12 PreviousOrSameDayOfWeek
13 NearestDayOfWeek
14 FirstDayOfWeekInMonth
15 LastDayOfWeekInMonth
16 NthDayOfWeekInMonth
17 WesternEasterSunday
18 OrthodoxEasterSunday
19 NearestMinuteInterval ];
20  
21 1 our %EXPORT_TAGS = (
22 all => [ @EXPORT_OK ],
23 );
24  
25 1 require Exporter;
26 1 *import = \&Exporter::import;
27 }
28  
29 49 ▶sub NextDayOfWeek {
Subroutine NextDayOfWeek: called CC=4 SCAR=15.0
Pod documented
30 49 ▶ @_ == 1 or Carp::croak(q<Usage: NextDayOfWeek(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: NextDayOfWeek(day)") 49 0 49
31 49 my ($day) = @_;
32  
33 49 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 49 0 49
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
0049
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
34 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
35  
36 49 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
37 49 my ($tm) = @_;
38 49 return $tm->plus_days(($day - $tm->day_of_week + 6) % 7 + 1);
39 49 };
40 }
41  
42 49 ▶sub NextOrSameDayOfWeek {
Subroutine NextOrSameDayOfWeek: called CC=4 SCAR=15.0
Pod documented
43 49 ▶ @_ == 1 or Carp::croak(q<Usage: NextOrSameDayOfWeek(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: NextOrSameDayOfWeek(day)") 49 0 49
44 49 my ($day) = @_;
45  
46 49 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 49 0 49
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
0049
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
47 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
48  
49 49 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 49 my ($tm) = @_;
51 49 return $tm->plus_days(($day - $tm->day_of_week) % 7);
52 49 };
53 }
54  
55 49 ▶sub PreviousDayOfWeek {
Subroutine PreviousDayOfWeek: called CC=4 SCAR=15.0
Pod documented
56 49 ▶ @_ == 1 or Carp::croak(q<Usage: PreviousDayOfWeek(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: PreviousDayOfWeek(day)") 49 0 49
57 49 my ($day) = @_;
58  
59 49 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 49 0 49
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
0049
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
60 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
61  
62 49 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 49 my ($tm) = @_;
64 49 return $tm->minus_days(($tm->day_of_week - $day + 6) % 7 + 1);
65 49 };
66 }
67  
68 49 ▶sub PreviousOrSameDayOfWeek {
Subroutine PreviousOrSameDayOfWeek: called CC=4 SCAR=15.0
Pod documented
69 49 ▶ @_ == 1 or Carp::croak(q<Usage: PreviousOrSameDayOfWeek(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: PreviousOrSameDayOfWeek(day)") 49 0 49
70 49 my ($day) = @_;
71  
72 49 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 49 0 49
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
0049
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
73 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
74  
75 49 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 49 my ($tm) = @_;
77 49 return $tm->minus_days(($tm->day_of_week - $day) % 7);
78 49 };
79 }
80  
81 9 ▶sub NearestDayOfWeek {
Subroutine NearestDayOfWeek: called CC=4 SCAR=15.0
Pod documented
82 9 ▶ @_ == 1 or Carp::croak(q<Usage: NearestDayOfWeek(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: NearestDayOfWeek(day)") 9 0 9
83 9 my ($day) = @_;
84  
85 9 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 9 0 9
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
009
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
86 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
87  
88 9 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
89 9 my ($tm) = @_;
90 9 return $tm->plus_days((($day - $tm->day_of_week + 3) % 7) - 3);
91 9 };
92 }
93  
94 2562 ▶sub FirstDayOfWeekInMonth {
Subroutine FirstDayOfWeekInMonth: called CC=4 SCAR=14.8
Pod documented
95 2562 ▶ @_ == 1 or Carp::croak(q<Usage: FirstDayOfWeekInMonth(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: FirstDayOfWeekInMonth(day)") 2562 0 2562
96 2562 my ($day) = @_;
97  
98 2562 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 2562 0 2562
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
002562
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
99 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
100  
101 2562 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 2562 my ($tm) = @_;
103 2562 $tm = $tm->with_day_of_month(1);
104 2562 return $tm->plus_days(($day - $tm->day_of_week) % 7);
105 2562 };
106 }
107  
108 2562 ▶sub LastDayOfWeekInMonth {
Subroutine LastDayOfWeekInMonth: called CC=4 SCAR=14.8
Pod documented
109 2562 ▶ @_ == 1 or Carp::croak(q<Usage: LastDayOfWeekInMonth(day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: LastDayOfWeekInMonth(day)") 2562 0 2562
110 2562 my ($day) = @_;
111  
112 2562 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 2562 0 2562
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
002562
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
113 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
114  
115 2562 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
116 2562 my ($tm) = @_;
117 2562 $tm = $tm->at_last_day_of_month;
118 2562 return $tm->minus_days(($tm->day_of_week - $day) % 7);
119 2562 };
120 }
121  
122 672 ▶sub NthDayOfWeekInMonth {
Subroutine NthDayOfWeekInMonth: called CC=8 SCAR=22.4
Pod documented
123 672 ▶ @_ == 2 or Carp::croak(q<Usage: NthDayOfWeekInMonth(ordinal, day)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or Carp::croak("Usage: NthDayOfWeekInMonth(ordinal, day)") 672 0 672
124 672 my ($ordinal, $day) = @_;
125  
126 672 ▶ ($ordinal >= -4 && $ordinal <= 4 && $ordinal != 0)
Branch: 1 branch
BranchTrueFalseTotal
$ordinal >= -4 and $ordinal <= 4 and $ordinal != 0 or Carp::croak("Parameter 'ordinal' is out of the range [-4, -1] u [1, 4]") 672 0 672
Condition33%2/6
$ordinal >= -4 and $ordinal <= 4 and $ordinal != 0
!ll&&!rl&&r
00672
$ordinal >= -4 and $ordinal <= 4
!ll&&!rl&&r
00672
MC/DC0%0/3
$ordinal >= -4 and $ordinal <= 4 and $ordinal != 0
$ordinal >= -4 $ordinal <= 4 $ordinal != 0
Truth table25%1/4
A and B and C
A= $ordinal >= -4B= $ordinal <= 4C= $ordinal != 0
ABCresult
0XX0
10X0
1100
1111
127 or Carp::croak(q<Parameter 'ordinal' is out of the range [-4, -1] u [1, 4]>);
128  
129 672 ▶ ($day >= 1 && $day <= 7)
Branch: 1 branch
BranchTrueFalseTotal
$day >= 1 and $day <= 7 or Carp::croak("Parameter 'day' is out of the range [1, 7]") 672 0 672
Condition33%1/3
$day >= 1 and $day <= 7
!ll&&!rl&&r
00672
MC/DC0%0/2
$day >= 1 and $day <= 7
$day >= 1 $day <= 7
Truth table33%1/3
A and B
A= $day >= 1B= $day <= 7
ABresult
0X0
100
111
130 or Carp::croak(q<Parameter 'day' is out of the range [1, 7]>);
131  
132 672 ▶ if ($ordinal > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ordinal > 0) { } 336 336 672
133 336 my $days = 7 * --$ordinal;
134 336 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
135 336 my ($tm) = @_;
136 336 $tm = $tm->with_day_of_month(1);
137 336 return $tm->plus_days($days + ($day - $tm->day_of_week) % 7);
138 336 };
139 }
140 else {
141 336 my $days = 7 * ++$ordinal;
142 336 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
143 336 my ($tm) = @_;
144 336 $tm = $tm->at_last_day_of_month;
145 336 return $tm->plus_days($days - ($tm->day_of_week - $day) % 7);
146 336 };
147 }
148 }
149  
150 500 ▶sub WesternEasterSunday {
Subroutine WesternEasterSunday: called CC=2 SCAR=7.0
Pod documented
151 500 ▶ @_ == 0 or Carp::croak(q<Usage: WesternEasterSunday()>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or Carp::croak("Usage: WesternEasterSunday()") 500 0 500
152  
153 500 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
154 500 my ($tm) = @_;
155 500 return $tm->with_rdn(Time::Moment::Internal::western_easter_sunday($tm->year));
156 500 };
157 }
158  
159 0 ▶sub OrthodoxEasterSunday {
Subroutine OrthodoxEasterSunday: not called CC=2 SCAR=17.9
Pod documented
160 0 ▶ @_ == 0 or Carp::croak(q<Usage: OrthodoxEasterSunday()>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or Carp::croak("Usage: OrthodoxEasterSunday()") 0 0 0
161  
162 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 0 my ($tm) = @_;
164 0 return $tm->with_rdn(Time::Moment::Internal::orthodox_easter_sunday($tm->year));
165 0 };
166 }
167  
168 7 ▶sub NearestMinuteInterval {
Subroutine NearestMinuteInterval: called CC=4 SCAR=14.5
Pod documented
169 7 ▶ @_ == 1 or Carp::croak(q<Usage: NearestMinuteInterval(interval)>);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or Carp::croak("Usage: NearestMinuteInterval(interval)") 7 0 7
170 7 my ($interval) = @_;
171
172 7 ▶ ($interval >= 1 && $interval <= 1440)
Branch: 1 branch
BranchTrueFalseTotal
$interval >= 1 and $interval <= 1440 or Carp::croak("Parameter 'interval' is out of the range [1, 1440]") 7 0 7
Condition33%1/3
$interval >= 1 and $interval <= 1440
!ll&&!rl&&r
007
MC/DC0%0/2
$interval >= 1 and $interval <= 1440
$interval >= 1 $interval <= 1440
Truth table33%1/3
A and B
A= $interval >= 1B= $interval <= 1440
ABresult
0X0
100
111
173 or Carp::croak(q<Parameter 'interval' is out of the range [1, 1440]>);
174
175 7 my $msec = $interval * 60 * 1000;
176 7 my $mid = int(($msec + 1) / 2);
177 7 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
178 7 my ($tm) = @_;
179 7 my $msod = $msec * int(($tm->millisecond_of_day + $mid) / $msec);
180 7 return $tm->with_millisecond_of_day($msod);
181 7 };
182 }
183  
184 1 1;
185  
↑ Summary blib/lib/Time/Moment.pm »