| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Cron::Toolkit::Pattern::NearestWeekday; |
|
2
|
2
|
|
|
2
|
|
12
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
89
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
159
|
|
|
4
|
2
|
|
|
2
|
|
14
|
use parent 'Cron::Toolkit::Pattern'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
13
|
|
|
5
|
2
|
|
|
2
|
|
161
|
use Cron::Toolkit::Utils qw(num_to_ordinal); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
928
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
|
8
|
3
|
|
|
3
|
0
|
15
|
my ($class, %args) = @_; |
|
9
|
3
|
|
|
|
|
19
|
my $self = $class->SUPER::new(%args); |
|
10
|
3
|
|
|
|
|
22
|
$self->{dom} = $args{dom}; |
|
11
|
3
|
|
|
|
|
12
|
return $self; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub type { |
|
15
|
214
|
|
|
214
|
0
|
299
|
return 'nearest_weekday'; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub match { |
|
19
|
187
|
|
|
187
|
0
|
221
|
my ( $self, undef, $tm ) = @_; |
|
20
|
187
|
|
|
|
|
196
|
my $day = $self->{dom}; |
|
21
|
187
|
|
|
|
|
243
|
my $dom = $tm->day_of_month; |
|
22
|
187
|
|
|
|
|
294
|
my $dow = $tm->day_of_week; |
|
23
|
187
|
|
|
|
|
263
|
my $days_in_month = $tm->length_of_month; |
|
24
|
187
|
100
|
66
|
|
|
481
|
return 0 if $day < 1 || $day > $days_in_month; |
|
25
|
157
|
|
|
|
|
339
|
my $target_tm = $tm->with_day_of_month($day); |
|
26
|
157
|
|
|
|
|
188
|
my $target_dow = $target_tm->day_of_week; |
|
27
|
|
|
|
|
|
|
|
|
28
|
157
|
100
|
100
|
|
|
397
|
if ( $target_dow >= 2 && $target_dow <= 5) { |
|
29
|
80
|
100
|
|
|
|
274
|
return $dom == $day ? 1 : 0; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
77
|
|
|
|
|
136
|
my $before = $target_tm->minus_days(1); |
|
32
|
77
|
|
|
|
|
119
|
my $after = $target_tm->plus_days(1); |
|
33
|
77
|
|
|
|
|
101
|
my $before_dow = $before->day_of_week; |
|
34
|
77
|
|
|
|
|
121
|
my $after_dow = $after->day_of_week; |
|
35
|
77
|
100
|
66
|
|
|
231
|
if ( $before_dow >= 1 && $before_dow <= 5 && $dom == $day - 1 ) { |
|
|
|
|
100
|
|
|
|
|
|
36
|
1
|
|
|
|
|
3
|
return 1; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
76
|
100
|
66
|
|
|
215
|
if ( $after_dow >= 1 && $after_dow <= 5 && $dom == $day + 1 && $day + 1 <= $days_in_month ) { |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
39
|
1
|
|
|
|
|
4
|
return 1; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
75
|
|
|
|
|
237
|
return 0; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub to_english { |
|
45
|
3
|
|
|
3
|
0
|
8
|
my $self = shift; |
|
46
|
3
|
|
|
|
|
15
|
return "on the nearest weekday to the " . num_to_ordinal($self->{dom}); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|