Lines 92-98
subtest 'crossing_DST' => sub {
Link Here
|
92 |
); |
92 |
); |
93 |
}; |
93 |
}; |
94 |
|
94 |
|
95 |
subtest 'hours_between' => sub { |
95 |
subtest 'hours_between | days_between' => sub { |
96 |
|
96 |
|
97 |
plan tests => 2; |
97 |
plan tests => 2; |
98 |
|
98 |
|
Lines 121-164
subtest 'hours_between' => sub {
Link Here
|
121 |
|
121 |
|
122 |
subtest 'Same hours' => sub { |
122 |
subtest 'Same hours' => sub { |
123 |
|
123 |
|
124 |
plan tests => 4; |
124 |
plan tests => 8; |
125 |
|
125 |
|
126 |
# Between 5th and 6th |
126 |
# Between 5th and 6th |
127 |
my $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; |
127 |
my $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; |
128 |
is( $diff_hours, 1 * 24, '' ); |
128 |
is( $diff_hours, 1 * 24, '' ); |
|
|
129 |
my $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days; |
130 |
is( $diff_days, 1, '' ); |
129 |
|
131 |
|
130 |
# Between 5th and 7th |
132 |
# Between 5th and 7th |
131 |
$diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; |
133 |
$diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; |
132 |
is( $diff_hours, 2 * 24, '' ); |
134 |
is( $diff_hours, 2 * 24, '' ); |
|
|
135 |
$diff_days = $calendar->days_between( $now, $nov_7 )->delta_days; |
136 |
is( $diff_days, 2, '' ); |
133 |
|
137 |
|
134 |
# Between 5th and 12th |
138 |
# Between 5th and 12th |
135 |
$diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; |
139 |
$diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; |
136 |
is( $diff_hours, 7 * 24, '' ); |
140 |
is( $diff_hours, 7 * 24, '' ); |
|
|
141 |
$diff_days = $calendar->days_between( $now, $nov_12 )->delta_days; |
142 |
is( $diff_days, 7, '' ); |
137 |
|
143 |
|
138 |
# Between 5th and 15th |
144 |
# Between 5th and 15th |
139 |
$diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; |
145 |
$diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; |
140 |
is( $diff_hours, 10 * 24, '' ); |
146 |
is( $diff_hours, 10 * 24, '' ); |
|
|
147 |
$diff_days = $calendar->days_between( $now, $nov_15 )->delta_days; |
148 |
is( $diff_days, 10, '' ); |
141 |
}; |
149 |
}; |
142 |
|
150 |
|
143 |
subtest 'Different hours' => sub { |
151 |
subtest 'Different hours' => sub { |
144 |
|
152 |
|
145 |
plan tests => 4; |
153 |
plan tests => 8; |
146 |
|
154 |
|
147 |
# Between 5th and 6th |
155 |
# Between 5th and 6th |
148 |
my $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours; |
156 |
my $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours; |
149 |
is( $diff_hours, 1 * 24 - 3, '' ); |
157 |
is( $diff_hours, 1 * 24 - 3, '' ); |
|
|
158 |
my $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days; |
159 |
is( $diff_days, 1, '' ); |
150 |
|
160 |
|
151 |
# Between 5th and 7th |
161 |
# Between 5th and 7th |
152 |
$diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; |
162 |
$diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; |
153 |
is( $diff_hours, 2 * 24 - 3, '' ); |
163 |
is( $diff_hours, 2 * 24 - 3, '' ); |
|
|
164 |
$diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days; |
165 |
is( $diff_days, 2, '' ); |
154 |
|
166 |
|
155 |
# Between 5th and 12th |
167 |
# Between 5th and 12th |
156 |
$diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; |
168 |
$diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; |
157 |
is( $diff_hours, 7 * 24 - 3, '' ); |
169 |
is( $diff_hours, 7 * 24 - 3, '' ); |
|
|
170 |
$diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days; |
171 |
is( $diff_days, 7, '' ); |
158 |
|
172 |
|
159 |
# Between 5th and 15th |
173 |
# Between 5th and 15th |
160 |
$diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; |
174 |
$diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; |
161 |
is( $diff_hours, 10 * 24 - 3, '' ); |
175 |
is( $diff_hours, 10 * 24 - 3, '' ); |
|
|
176 |
$diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days; |
177 |
is( $diff_days, 10, '' ); |
162 |
}; |
178 |
}; |
163 |
}; |
179 |
}; |
164 |
|
180 |
|
Lines 177-232
subtest 'hours_between' => sub {
Link Here
|
177 |
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); |
193 |
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); |
178 |
|
194 |
|
179 |
subtest 'Same hours' => sub { |
195 |
subtest 'Same hours' => sub { |
180 |
plan tests => 5; |
196 |
plan tests => 10; |
181 |
|
197 |
|
182 |
my $diff_hours; |
198 |
my ( $diff_hours, $diff_days ); |
183 |
|
199 |
|
184 |
# Between 5th and 6th |
200 |
# Between 5th and 6th |
185 |
$diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; |
201 |
$diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; |
186 |
is( $diff_hours, 0 * 24, '' ); # FIXME Is this really should be 0? |
202 |
is( $diff_hours, 0 * 24, '' ); # FIXME Is this really should be 0? |
|
|
203 |
$diff_days = $calendar->days_between( $now, $nov_6)->delta_days; |
204 |
is( $diff_days, 0, '' ); # FIXME Is this really should be 0? |
187 |
|
205 |
|
188 |
# Between 5th and 7th |
206 |
# Between 5th and 7th |
189 |
$diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; |
207 |
$diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; |
190 |
is( $diff_hours, 2 * 24 - 1 * 24, '' ); |
208 |
is( $diff_hours, 2 * 24 - 1 * 24, '' ); |
|
|
209 |
$diff_days = $calendar->days_between( $now, $nov_7)->delta_days; |
210 |
is( $diff_days, 2 - 1, '' ); |
191 |
|
211 |
|
192 |
# Between 5th and 12th |
212 |
# Between 5th and 12th |
193 |
$diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; |
213 |
$diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; |
194 |
is( $diff_hours, 7 * 24 - 1 * 24, '' ); |
214 |
is( $diff_hours, 7 * 24 - 1 * 24, '' ); |
|
|
215 |
$diff_days = $calendar->days_between( $now, $nov_12)->delta_days; |
216 |
is( $diff_days, 7 - 1, '' ); |
195 |
|
217 |
|
196 |
# Between 5th and 13th |
218 |
# Between 5th and 13th |
197 |
$diff_hours = $calendar->hours_between( $now, $nov_13 )->hours; |
219 |
$diff_hours = $calendar->hours_between( $now, $nov_13 )->hours; |
198 |
is( $diff_hours, 8 * 24 - 2 * 24, '' ); |
220 |
is( $diff_hours, 8 * 24 - 2 * 24, '' ); |
|
|
221 |
$diff_days = $calendar->days_between( $now, $nov_13)->delta_days; |
222 |
is( $diff_days, 8 - 2, '' ); |
199 |
|
223 |
|
200 |
# Between 5th and 15th |
224 |
# Between 5th and 15th |
201 |
$diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; |
225 |
$diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; |
202 |
is( $diff_hours, 10 * 24 - 2 * 24, '' ); |
226 |
is( $diff_hours, 10 * 24 - 2 * 24, '' ); |
|
|
227 |
$diff_days = $calendar->days_between( $now, $nov_15)->delta_days; |
228 |
is( $diff_days, 10 - 2, '' ); |
203 |
}; |
229 |
}; |
204 |
|
230 |
|
205 |
subtest 'Different hours' => sub { |
231 |
subtest 'Different hours' => sub { |
206 |
plan tests => 6; |
232 |
plan tests => 11; |
207 |
|
233 |
|
208 |
my $diff_hours; |
234 |
my ( $diff_hours, $diff_days ); |
209 |
|
235 |
|
210 |
# Between 5th and 6th |
236 |
# Between 5th and 6th |
211 |
my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) ); |
237 |
my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) ); |
212 |
is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs |
238 |
is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs |
213 |
is( $duration->is_negative, 1, ); # FIXME Do really test for that case in our calls to hours_between? |
239 |
is( $duration->is_negative, 1, ); # FIXME Do really test for that case in our calls to hours_between? |
|
|
240 |
$duration = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) ); |
241 |
is( $duration->hours, abs(0), '' ); # FIXME Is this correct? |
214 |
|
242 |
|
215 |
# Between 5th and 7th |
243 |
# Between 5th and 7th |
216 |
$diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; |
244 |
$diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; |
217 |
is( $diff_hours, 2 * 24 - 1 * 24 - 3, '' ); |
245 |
is( $diff_hours, 2 * 24 - 1 * 24 - 3, '' ); |
|
|
246 |
$diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days; |
247 |
is( $diff_days, 2 - 1, '' ); |
218 |
|
248 |
|
219 |
# Between 5th and 12th |
249 |
# Between 5th and 12th |
220 |
$diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; |
250 |
$diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; |
221 |
is( $diff_hours, 7 * 24 - 1 * 24 - 3, '' ); |
251 |
is( $diff_hours, 7 * 24 - 1 * 24 - 3, '' ); |
|
|
252 |
$diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days; |
253 |
is( $diff_days, 7 - 1, '' ); |
222 |
|
254 |
|
223 |
# Between 5th and 13th |
255 |
# Between 5th and 13th |
224 |
$diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours; |
256 |
$diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours; |
225 |
is( $diff_hours, 8 * 24 - 2 * 24 - 3, '' ); |
257 |
is( $diff_hours, 8 * 24 - 2 * 24 - 3, '' ); |
|
|
258 |
$diff_days = $calendar->days_between( $now, $nov_13->clone->subtract(hours => 3) )->delta_days; |
259 |
is( $diff_days, 8 - 1, '' ); |
226 |
|
260 |
|
227 |
# Between 5th and 15th |
261 |
# Between 5th and 15th |
228 |
$diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; |
262 |
$diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; |
229 |
is( $diff_hours, 10 * 24 - 2 * 24 - 3, '' ); |
263 |
is( $diff_hours, 10 * 24 - 2 * 24 - 3, '' ); |
|
|
264 |
$diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days; |
265 |
is( $diff_days, 10 - 2, '' ); |
230 |
}; |
266 |
}; |
231 |
|
267 |
|
232 |
}; |
268 |
}; |
233 |
- |
|
|