line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Moment::Adjusters; |
2
|
1
|
|
|
1
|
|
1162
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp qw[]; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
125
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
1
|
|
|
1
|
|
6
|
our $VERSION = '0.44'; |
9
|
1
|
|
|
|
|
5
|
our @EXPORT_OK = qw[ NextDayOfWeek |
10
|
|
|
|
|
|
|
NextOrSameDayOfWeek |
11
|
|
|
|
|
|
|
PreviousDayOfWeek |
12
|
|
|
|
|
|
|
PreviousOrSameDayOfWeek |
13
|
|
|
|
|
|
|
FirstDayOfWeekInMonth |
14
|
|
|
|
|
|
|
LastDayOfWeekInMonth |
15
|
|
|
|
|
|
|
NthDayOfWeekInMonth |
16
|
|
|
|
|
|
|
WesternEasterSunday |
17
|
|
|
|
|
|
|
OrthodoxEasterSunday |
18
|
|
|
|
|
|
|
NearestMinuteInterval ]; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
4
|
our %EXPORT_TAGS = ( |
21
|
|
|
|
|
|
|
all => [ @EXPORT_OK ], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
4
|
require Exporter; |
25
|
1
|
|
|
|
|
1088
|
*import = \&Exporter::import; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub NextDayOfWeek { |
29
|
49
|
50
|
|
49
|
1
|
26951
|
@_ == 1 or Carp::croak(q); |
30
|
49
|
|
|
|
|
101
|
my ($day) = @_; |
31
|
|
|
|
|
|
|
|
32
|
49
|
50
|
33
|
|
|
191
|
($day >= 1 && $day <= 7) |
33
|
|
|
|
|
|
|
or Carp::croak(q); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return sub { |
36
|
49
|
|
|
49
|
|
102
|
my ($tm) = @_; |
37
|
49
|
|
|
|
|
383
|
return $tm->plus_days(($day - $tm->day_of_week + 6) % 7 + 1); |
38
|
49
|
|
|
|
|
344
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub NextOrSameDayOfWeek { |
42
|
49
|
50
|
|
49
|
1
|
26128
|
@_ == 1 or Carp::croak(q); |
43
|
49
|
|
|
|
|
94
|
my ($day) = @_; |
44
|
|
|
|
|
|
|
|
45
|
49
|
50
|
33
|
|
|
181
|
($day >= 1 && $day <= 7) |
46
|
|
|
|
|
|
|
or Carp::croak(q); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return sub { |
49
|
49
|
|
|
49
|
|
98
|
my ($tm) = @_; |
50
|
49
|
|
|
|
|
358
|
return $tm->plus_days(($day - $tm->day_of_week) % 7); |
51
|
49
|
|
|
|
|
316
|
}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub PreviousDayOfWeek { |
55
|
49
|
50
|
|
49
|
1
|
26827
|
@_ == 1 or Carp::croak(q); |
56
|
49
|
|
|
|
|
108
|
my ($day) = @_; |
57
|
|
|
|
|
|
|
|
58
|
49
|
50
|
33
|
|
|
191
|
($day >= 1 && $day <= 7) |
59
|
|
|
|
|
|
|
or Carp::croak(q); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return sub { |
62
|
49
|
|
|
49
|
|
88
|
my ($tm) = @_; |
63
|
49
|
|
|
|
|
335
|
return $tm->minus_days(($tm->day_of_week - $day + 6) % 7 + 1); |
64
|
49
|
|
|
|
|
329
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub PreviousOrSameDayOfWeek { |
68
|
49
|
50
|
|
49
|
1
|
25877
|
@_ == 1 or Carp::croak(q); |
69
|
49
|
|
|
|
|
97
|
my ($day) = @_; |
70
|
|
|
|
|
|
|
|
71
|
49
|
50
|
33
|
|
|
183
|
($day >= 1 && $day <= 7) |
72
|
|
|
|
|
|
|
or Carp::croak(q); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return sub { |
75
|
49
|
|
|
49
|
|
85
|
my ($tm) = @_; |
76
|
49
|
|
|
|
|
440
|
return $tm->minus_days(($tm->day_of_week - $day) % 7); |
77
|
49
|
|
|
|
|
313
|
}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub FirstDayOfWeekInMonth { |
81
|
0
|
0
|
|
0
|
1
|
|
@_ == 1 or Carp::croak(q); |
82
|
0
|
|
|
|
|
|
my ($day) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
0
|
|
|
|
($day >= 1 && $day <= 7) |
85
|
|
|
|
|
|
|
or Carp::croak(q); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return sub { |
88
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
89
|
0
|
|
|
|
|
|
$tm = $tm->with_day_of_month(1); |
90
|
0
|
|
|
|
|
|
return $tm->plus_days(($day - $tm->day_of_week) % 7); |
91
|
0
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub LastDayOfWeekInMonth { |
95
|
0
|
0
|
|
0
|
1
|
|
@_ == 1 or Carp::croak(q); |
96
|
0
|
|
|
|
|
|
my ($day) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
0
|
|
|
|
($day >= 1 && $day <= 7) |
99
|
|
|
|
|
|
|
or Carp::croak(q); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return sub { |
102
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
103
|
0
|
|
|
|
|
|
$tm = $tm->at_last_day_of_month; |
104
|
0
|
|
|
|
|
|
return $tm->minus_days(($tm->day_of_week - $day) % 7); |
105
|
0
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub NthDayOfWeekInMonth { |
109
|
0
|
0
|
|
0
|
1
|
|
@_ == 2 or Carp::croak(q); |
110
|
0
|
|
|
|
|
|
my ($ordinal, $day) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
0
|
|
|
|
($ordinal >= -4 && $ordinal <= 4 && $ordinal != 0) |
|
|
|
0
|
|
|
|
|
113
|
|
|
|
|
|
|
or Carp::croak(q); |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
0
|
|
|
|
($day >= 1 && $day <= 7) |
116
|
|
|
|
|
|
|
or Carp::croak(q); |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ($ordinal > 0) { |
119
|
0
|
|
|
|
|
|
my $days = 7 * --$ordinal; |
120
|
|
|
|
|
|
|
return sub { |
121
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
122
|
0
|
|
|
|
|
|
$tm = $tm->with_day_of_month(1); |
123
|
0
|
|
|
|
|
|
return $tm->plus_days($days + ($day - $tm->day_of_week) % 7); |
124
|
0
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
else { |
127
|
0
|
|
|
|
|
|
my $days = 7 * ++$ordinal; |
128
|
|
|
|
|
|
|
return sub { |
129
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
130
|
0
|
|
|
|
|
|
$tm = $tm->at_last_day_of_month; |
131
|
0
|
|
|
|
|
|
return $tm->plus_days($days - ($tm->day_of_week - $day) % 7); |
132
|
0
|
|
|
|
|
|
}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub WesternEasterSunday { |
137
|
0
|
0
|
|
0
|
1
|
|
@_ == 0 or Carp::croak(q); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return sub { |
140
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
141
|
0
|
|
|
|
|
|
return $tm->with_rdn(Time::Moment::Internal::western_easter_sunday($tm->year)); |
142
|
0
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub OrthodoxEasterSunday { |
146
|
0
|
0
|
|
0
|
1
|
|
@_ == 0 or Carp::croak(q); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
return sub { |
149
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
150
|
0
|
|
|
|
|
|
return $tm->with_rdn(Time::Moment::Internal::orthodox_easter_sunday($tm->year)); |
151
|
0
|
|
|
|
|
|
}; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub NearestMinuteInterval { |
155
|
0
|
0
|
|
0
|
1
|
|
@_ == 1 or Carp::croak(q); |
156
|
0
|
|
|
|
|
|
my ($interval) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
0
|
|
|
|
($interval >= 1 && $interval <= 1440) |
159
|
|
|
|
|
|
|
or Carp::croak(q); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $msec = $interval * 60 * 1000; |
162
|
0
|
|
|
|
|
|
my $mid = int(($msec + 1) / 2); |
163
|
|
|
|
|
|
|
return sub { |
164
|
0
|
|
|
0
|
|
|
my ($tm) = @_; |
165
|
0
|
|
|
|
|
|
my $msod = $msec * int(($tm->millisecond_of_day + $mid) / $msec); |
166
|
0
|
|
|
|
|
|
return $tm->with_millisecond_of_day($msod); |
167
|
0
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|