View | Details | Raw Unified | Return to bug 23974
Collapse All | Expand All

(-)a/t/db_dependent/Calendar.t (-45 / +44 lines)
Lines 125-151 subtest 'hours_between | days_between' => sub { Link Here
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, 'hours: 1 day, no holiday' );
129
            my $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days;
129
            my $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days;
130
            is( $diff_days, 1, '' );
130
            is( $diff_days, 1, 'days: 1 day, no holiday' );
131
131
132
            # Between 5th and 7th
132
            # Between 5th and 7th
133
            $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
133
            $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
134
            is( $diff_hours, 2 * 24, '' );
134
            is( $diff_hours, 2 * 24, 'hours: 2 days, no holiday' );
135
            $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days;
135
            $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days;
136
            is( $diff_days, 2, '' );
136
            is( $diff_days, 2, 'days: 2 days, no holiday' );
137
137
138
            # Between 5th and 12th
138
            # Between 5th and 12th
139
            $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
139
            $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
140
            is( $diff_hours, 7 * 24, '' );
140
            is( $diff_hours, 7 * 24, 'hours: 7 days, no holiday' );
141
            $diff_days = $calendar->days_between( $now, $nov_12 )->delta_days;
141
            $diff_days = $calendar->days_between( $now, $nov_12 )->delta_days;
142
            is( $diff_days, 7, '' );
142
            is( $diff_days, 7, 'days: 7 days, no holiday' );
143
143
144
            # Between 5th and 15th
144
            # Between 5th and 15th
145
            $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
145
            $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
146
            is( $diff_hours, 10 * 24, '' );
146
            is( $diff_hours, 10 * 24, 'hours: 10 days, no holiday' );
147
            $diff_days = $calendar->days_between( $now, $nov_15 )->delta_days;
147
            $diff_days = $calendar->days_between( $now, $nov_15 )->delta_days;
148
            is( $diff_days, 10, '' );
148
            is( $diff_days, 10, 'days: 10 days, no holiday' );
149
        };
149
        };
150
150
151
        subtest 'Different hours' => sub {
151
        subtest 'Different hours' => sub {
Lines 154-186 subtest 'hours_between | days_between' => sub { Link Here
154
154
155
            # Between 5th and 5th (Same day short hours loan)
155
            # Between 5th and 5th (Same day short hours loan)
156
            my $diff_hours = $calendar->hours_between( $now, $now->clone->add(hours => 3) )->hours;
156
            my $diff_hours = $calendar->hours_between( $now, $now->clone->add(hours => 3) )->hours;
157
            is( $diff_hours, 3, '' );
157
            is( $diff_hours, 3, 'hours: 3 hours, no holidays' );
158
            my $diff_days = $calendar->days_between( $now, $now->clone->add(hours => 3) )->delta_days;
158
            my $diff_days = $calendar->days_between( $now, $now->clone->add(hours => 3) )->delta_days;
159
            is( $diff_days, 0, '' );
159
            is( $diff_days, 0, 'days: 3 hours, no holidays' );
160
160
161
            # Between 5th and 6th
161
            # Between 5th and 6th
162
            $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours;
162
            $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours;
163
            is( $diff_hours, 1 * 24 - 3, '' );
163
            is( $diff_hours, 1 * 24 - 3, 'hours: 21 hours, no holidays' );
164
            $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days;
164
            $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days;
165
            is( $diff_days, 1, '' );
165
            is( $diff_days, 1, 'days: 21 hours, no holidays' );
166
166
167
            # Between 5th and 7th
167
            # Between 5th and 7th
168
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours;
168
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours;
169
            is( $diff_hours, 2 * 24 - 3, '' );
169
            is( $diff_hours, 2 * 24 - 3, 'hours: 45 hours, no holidays' );
170
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days;
170
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days;
171
            is( $diff_days, 2, '' );
171
            is( $diff_days, 2, 'days: 45 hours, no holidays' );
172
172
173
            # Between 5th and 12th
173
            # Between 5th and 12th
174
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours;
174
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours;
175
            is( $diff_hours, 7 * 24 - 3, '' );
175
            is( $diff_hours, 7 * 24 - 3, 'hours: 165 hours, no holidays' );
176
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days;
176
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days;
177
            is( $diff_days, 7, '' );
177
            is( $diff_days, 7, 'days: 165 hours, no holidays' );
178
178
179
            # Between 5th and 15th
179
            # Between 5th and 15th
180
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours;
180
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours;
181
            is( $diff_hours, 10 * 24 - 3, '' );
181
            is( $diff_hours, 10 * 24 - 3, 'hours: 237 hours, no holidays' );
182
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days;
182
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days;
183
            is( $diff_days, 10, '' );
183
            is( $diff_days, 10, 'days: 237 hours, no holidays' );
184
        };
184
        };
185
    };
185
    };
186
186
Lines 205-243 subtest 'hours_between | days_between' => sub { Link Here
205
205
206
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
206
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
207
            $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours;
207
            $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours;
208
            is( $diff_hours, 0 * 24, '' ); # FIXME Is this really should be 0?
208
            is( $diff_hours, 0 * 24, 'hours: 1 day, end_dt = holiday' ); # FIXME Is this really should be 0?
209
            $diff_days = $calendar->days_between( $now, $nov_6)->delta_days;
209
            $diff_days = $calendar->days_between( $now, $nov_6)->delta_days;
210
            is( $diff_days, 0, '' ); # FIXME Is this really should be 0?
210
            is( $diff_days, 0, 'days: 1 day, end_dt = holiday' ); # FIXME Is this really should be 0?
211
211
212
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
212
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
213
            $diff_hours = $calendar->hours_between( $nov_6, $nov_7 )->hours;
213
            $diff_hours = $calendar->hours_between( $nov_6, $nov_7 )->hours;
214
            is( $diff_hours, 0 * 24, '' ); # FIXME Is this really should be 0?
214
            is( $diff_hours, 0 * 24, 'hours: 1 day, start_dt = holiday' ); # FIXME Is this really should be 0?
215
            $diff_days = $calendar->days_between( $nov_6, $nov_7 )->delta_days;
215
            $diff_days = $calendar->days_between( $nov_6, $nov_7 )->delta_days;
216
            is( $diff_days, 0, '' ); # FIXME Is this really should be 0?
216
            is( $diff_days, 0, 'days: 1 day, start_dt = holiday' ); # FIXME Is this really should be 0?
217
217
218
            # Between 5th and 7th
218
            # Between 5th and 7th
219
            $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
219
            $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
220
            is( $diff_hours, 2 * 24 - 1 * 24, '' );
220
            is( $diff_hours, 2 * 24 - 1 * 24, 'hours: 2 days, 1 holiday' );
221
            $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days;
221
            $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days;
222
            is( $diff_days, 2 - 1, '' );
222
            is( $diff_days, 2 - 1, 'days: 2 days, 1 holiday' );
223
223
224
            # Between 5th and 12th
224
            # Between 5th and 12th
225
            $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
225
            $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
226
            is( $diff_hours, 7 * 24 - 1 * 24, '' );
226
            is( $diff_hours, 7 * 24 - 1 * 24, 'hours: 7 days, 1 holiday' );
227
            $diff_days = $calendar->days_between( $now, $nov_12)->delta_days;
227
            $diff_days = $calendar->days_between( $now, $nov_12)->delta_days;
228
            is( $diff_days, 7 - 1, '' );
228
            is( $diff_days, 7 - 1, 'day: 7 days, 1 holiday' );
229
229
230
            # Between 5th and 13th
230
            # Between 5th and 13th
231
            $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours;
231
            $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours;
232
            is( $diff_hours, 8 * 24 - 2 * 24, '' );
232
            is( $diff_hours, 8 * 24 - 2 * 24, 'hours: 8 days, 2 holidays' );
233
            $diff_days = $calendar->days_between( $now, $nov_13)->delta_days;
233
            $diff_days = $calendar->days_between( $now, $nov_13)->delta_days;
234
            is( $diff_days, 8 - 2, '' );
234
            is( $diff_days, 8 - 2, 'days: 8 days, 2 holidays' );
235
235
236
            # Between 5th and 15th
236
            # Between 5th and 15th
237
            $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
237
            $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
238
            is( $diff_hours, 10 * 24 - 2 * 24, '' );
238
            is( $diff_hours, 10 * 24 - 2 * 24, 'hours: 10 days, 2 holidays' );
239
            $diff_days = $calendar->days_between( $now, $nov_15)->delta_days;
239
            $diff_days = $calendar->days_between( $now, $nov_15)->delta_days;
240
            is( $diff_days, 10 - 2, '' );
240
            is( $diff_days, 10 - 2, 'days: 10 days, 2 holidays' );
241
        };
241
        };
242
242
243
        subtest 'Different hours' => sub {
243
        subtest 'Different hours' => sub {
Lines 250-290 subtest 'hours_between | days_between' => sub { Link Here
250
250
251
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
251
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
252
            my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) );
252
            my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) );
253
            is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs
253
            is( $duration->hours, abs(0 * 24 - 3), 'hours: 21 hours, end_dt = holiday' ); # FIXME $duration->hours always return a abs
254
            is( $duration->is_negative, 1, ); # FIXME Do really test for that case in our calls to hours_between?
254
            is( $duration->is_negative, 1, '? is negative ?' ); # FIXME Do really test for that case in our calls to hours_between?
255
            $duration = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) );
255
            $duration = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) );
256
            is( $duration->hours, abs(0), '' ); # FIXME Is this correct?
256
            is( $duration->hours, abs(0), 'days: 21 hours, end_dt = holiday' ); # FIXME Is this correct?
257
257
258
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
258
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
259
            $duration = $calendar->hours_between( $nov_6, $nov_7->clone->subtract(hours => 3) );
259
            $duration = $calendar->hours_between( $nov_6, $nov_7->clone->subtract(hours => 3) );
260
            is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs
260
            is( $duration->hours, abs(0 * 24 - 3), 'hours: 21 hours, start_dt = holiday' ); # FIXME $duration->hours always return a abs
261
            is( $duration->is_negative, 1, ); # FIXME Do really test for that case in our calls to hours_between?
261
            is( $duration->is_negative, 1, '? is negative ?' ); # FIXME Do really test for that case in our calls to hours_between?
262
            $duration = $calendar->days_between( $nov_6, $nov_7->clone->subtract(hours => 3) );
262
            $duration = $calendar->days_between( $nov_6, $nov_7->clone->subtract(hours => 3) );
263
            is( $duration->hours, abs(0), '' ); # FIXME Is this correct?
263
            is( $duration->hours, abs(0), 'days: 21 hours, start_dt = holiday' ); # FIXME Is this correct?
264
264
265
            # Between 5th and 7th
265
            # Between 5th and 7th
266
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours;
266
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours;
267
            is( $diff_hours, 2 * 24 - 1 * 24 - 3, '' );
267
            is( $diff_hours, 2 * 24 - 1 * 24 - 3, 'hours: 45 hours, 1 holiday' );
268
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days;
268
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days;
269
            is( $diff_days, 2 - 1, '' );
269
            is( $diff_days, 2 - 1, 'days: 45 hours, 1 holiday' );
270
270
271
            # Between 5th and 12th
271
            # Between 5th and 12th
272
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours;
272
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours;
273
            is( $diff_hours, 7 * 24 - 1 * 24 - 3, '' );
273
            is( $diff_hours, 7 * 24 - 1 * 24 - 3, 'hours: 165 hours, 1 holiday' );
274
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days;
274
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days;
275
            is( $diff_days, 7 - 1, '' );
275
            is( $diff_days, 7 - 1, 'days: 165 hours, 1 holiday' );
276
276
277
            # Between 5th and 13th
277
            # Between 5th and 13th
278
            $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours;
278
            $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours;
279
            is( $diff_hours, 8 * 24 - 2 * 24 - 3, '' );
279
            is( $diff_hours, 8 * 24 - 2 * 24 - 3, 'hours: 289 hours, 2 holidays ' );
280
            $diff_days = $calendar->days_between( $now, $nov_13->clone->subtract(hours => 3) )->delta_days;
280
            $diff_days = $calendar->days_between( $now, $nov_13->clone->subtract(hours => 3) )->delta_days;
281
            is( $diff_days, 8 - 1, '' );
281
            is( $diff_days, 8 - 1, 'days: 289 hours, 2 holidays' );
282
282
283
            # Between 5th and 15th
283
            # Between 5th and 15th
284
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours;
284
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours;
285
            is( $diff_hours, 10 * 24 - 2 * 24 - 3, '' );
285
            is( $diff_hours, 10 * 24 - 2 * 24 - 3, 'hours: 237 hours, 2 holidays' );
286
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days;
286
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days;
287
            is( $diff_days, 10 - 2, '' );
287
            is( $diff_days, 10 - 2, 'days: 237 hours, 2 holidays' );
288
        };
288
        };
289
289
290
    };
290
    };
291
- 

Return to bug 23974