PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / _capacity / where_to_save.php

where_to_save.php in Booking Calendar 11.2, at includes/_capacity/where_to_save.php

493 lines 25.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.0.4.
4
5 // ---------------------------------------------------------------------------------------------------------------------
6 // Check where to save the booking
7 // ---------------------------------------------------------------------------------------------------------------------
8
9 /**
10 * Check if these dates contain marker '2981-01-13', which is means that this booking was submited without dates - as Contact Form.
11 *
12 * @param array|string $dates_sql_arr - array of SQL dates.
13 *
14 * @return bool
15 */
16 function wpbc_is_these_dates__for__no_dates( $dates_sql_arr ){
17
18 // FixIn: 2981-01-13 13 Jan 2981.
19
20 if ( is_array( $dates_sql_arr ) ) {
21 foreach ( $dates_sql_arr as $date_ymd ) {
22 if ( '2981-01-13' === gmdate( 'Y-m-d', mysql2date( 'U', $date_ymd ) ) ) {
23 return true;
24 }
25 }
26 } elseif ( '2981-01-13' === gmdate( 'Y-m-d', mysql2date( 'U', $dates_sql_arr ) ) ) {
27 return true;
28 }
29
30 return false;
31 }
32
33
34 /**
35 * Get booking resources for each selected date, where we can save the booking, or false if we can not save it
36 *
37 * @param array $params = [
38 * 'resource_id' => 2
39 * 'skip_booking_id' => '', | 125 if edit booking
40 * 'dates_only_sql_arr' => [ "2023-10-18", "2023-10-25", "2023-11-25" ]
41 * 'time_as_seconds_arr' => [ 36000, 39600 ]
42 * 'how_many_items_to_book' => 1
43 * 'request_uri' => 'http://beta/resource-id2/' // Optional default -> DOING_AJAX ? $_SERVER['HTTP_REFERER'] : $_SERVER['REQUEST_URI']
44 * 'as_single_resource' => false, // Optional default false
45 * 'is_use_booking_recurrent_time' => false // Optional default ( 'On' === get_bk_option( 'booking_recurrent_time' ) )
46 * ]
47 * @return array = [ 'result' => 'ok', 'main__resource_id' => 2, 'resources_in_dates' => [ '2023-09-23':[2,10,11], '2023-09-24':[2,10,11] ], 'time_to_book' => [ "00:00:00", "24:00:00" ] ]
48 * Note. 'main__resource_id' - it's first booking resource in the list, basically needed for saving in wp_booking DB table.
49 * OR
50 * = [ 'result' => 'error', 'message' => 'Booking can not be saved ...' ]
51 */
52 function wpbc__where_to_save_booking( $local_params ){
53
54 $server_request_uri = ( ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
55 $server_http_referer_uri = ( ( isset( $_SERVER['HTTP_REFERER'] ) ) ? sanitize_text_field( $_SERVER['HTTP_REFERER'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
56 $defaults = array(
57 'request_uri' => ( ( ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) ? $server_http_referer_uri : $server_request_uri ), // front-end: $server_request_uri | ajax: $server_http_referer_uri // It different in Ajax requests. It's used for change-over days to detect for exception at specific pages
58 'allow_past' => false,
59 'as_single_resource' => false,
60 'is_use_booking_recurrent_time' => ( 'On' === get_bk_option( 'booking_recurrent_time' ) ),
61 'time_override_source' => '',
62 'aggregate_resource_id_arr' => array(),
63 'custom_form' => '' //FixIn: 10.0.0.10 // Required for checking all available time-slots and compare with booked time slots
64 );
65 $local_params = wp_parse_args( $local_params, $defaults );
66
67 $time_as_seconds_arr = $local_params['time_as_seconds_arr'];
68 $time_as_seconds_arr[0] = ( 0 != $time_as_seconds_arr[0] ) ? $time_as_seconds_arr[0] + 1 : $time_as_seconds_arr[0]; // +1 s. -- set check in time with ended 1 second
69 $time_as_seconds_arr[1] = ( ( 24 * 60 * 60 ) != $time_as_seconds_arr[1] ) ? $time_as_seconds_arr[1] + 2 : $time_as_seconds_arr[1]; // +2 s. -- set check out time with ended 2 seconds
70 if ( ( 0 != $time_as_seconds_arr[0] ) && ( ( 24 * 60 * 60 ) == $time_as_seconds_arr[1] ) ) {
71 //FixIn: 10.0.0.49 - in case if we have start time != 00:00 and end time as 24:00 then set end time as 23:59:52
72 $time_as_seconds_arr[1] += - 8;
73 }
74 $local_params['time_as_his_arr'] = array(
75 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[0] ),
76 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[1] )
77 );
78 // FixIn: 2981-01-13 13 Jan 2981
79 $availability_per_days_arr__params = array();
80 if ( ( ! empty( $local_params['dates_only_sql_arr'] ) ) && ( is_array( $local_params['dates_only_sql_arr'] ) ) && ( '2981-01-13' === $local_params['dates_only_sql_arr'][0] ) ) {
81 $availability_per_days_arr__params['is_days_always_available'] = true;
82 }
83 // If we are using the unavailable before/after booking dates, then we need to extend "$local_params['dates_only_sql_arr']" to such dates.
84 if ( function_exists( 'wpbc__extend_checking_dates_range__if_used__extra_seconds__before_after' ) ) {
85 $maybe_extended__dates_to_check_arr = wpbc__extend_checking_dates_range__if_used__extra_seconds__before_after( $local_params['dates_only_sql_arr'] );
86 } else {
87 $maybe_extended__dates_to_check_arr = $local_params['dates_only_sql_arr'];
88 }
89 // [ "dates": [ "2023-11-05": [ "day_availability":4, ... "2": [ "is_day_unavailable":false, ...]], '2023-11-06':[...] ] ,"resources_id_arr__in_dates":[2,12,10,11]}
90
91 $availability_per_days = wpbc_get_availability_per_days_arr( wp_parse_args( array(
92 'resource_id' => $local_params['resource_id'],
93 'skip_booking_id' => $local_params['skip_booking_id'],
94 'dates_to_check' => $maybe_extended__dates_to_check_arr,
95 'request_uri' => $local_params['request_uri'],
96 'allow_past' => ! empty( $local_params['allow_past'] ),
97 'as_single_resource' => $local_params['as_single_resource'], // default FALSE :: get dates as for 'single resource' or 'parent' resource including bookings in all 'child booking resources' .
98 'additional_bk_types' => $local_params['aggregate_resource_id_arr'],
99 'aggregate_type' => empty( $local_params['aggregate_type'] ) ? 'bookings_only' : $local_params['aggregate_type'], //TODO: this parameter does not transfer during saving, so here will be always default value 'bookings_only' // FixIn: 10.0.0.7.
100 'custom_form' => $local_params['custom_form'], // FixIn: 10.0.0.10.
101 ) , $availability_per_days_arr__params ) );
102
103 // Get value of how many booking resources to book
104 $how_many_items_to_book = $local_params['how_many_items_to_book'];
105
106 // FixIn: 2981-01-13 13 Jan 2981.
107 if ( ( ! empty( $local_params['dates_only_sql_arr'] ) ) && ( wpbc_is_these_dates__for__no_dates( $local_params['dates_only_sql_arr'] ) ) ) {
108 $how_many_items_to_book = 0;
109 }
110
111 // -------------------------------------------------------------------------------------------------------------
112 // [ 2023-10-18: [ 0:[ resource_id: 2, is_available: true, booked__seconds: [], booked__readable: [], time_to_book__seconds: [ 36030, 39570 ], time_to_book__readable: "10:00:00", "11:00:00" ] ], 1: [...], 2: [...], 3: [...] ], 2023-10-25: [...], 2023-11-25: [...] ]
113 $available_slots = wpbc__get_available_slots__for_selected_dates_times__bl( array(
114 'dates_sql__arr' => $local_params['dates_only_sql_arr'],
115 'time_as_seconds_arr' => $local_params['time_as_seconds_arr'],
116 'is_use_booking_recurrent_time' => $local_params['is_use_booking_recurrent_time'],
117 'time_override_source' => $local_params['time_override_source'],
118 'availability_per_days' => $availability_per_days
119 ) );
120
121 $main__resource_id = 0;
122 // == In SAME 'child' booking resources ============================================================
123 if ( 'On' === get_bk_option( 'booking_is_dissbale_booking_for_different_sub_resources' ) ) {
124
125 $availability_in_same_child_resources = $availability_per_days['resources_id_arr__in_dates'];
126
127 foreach ( $availability_per_days['resources_id_arr__in_dates'] as $child_resource_id ) {
128 foreach ( $local_params['dates_only_sql_arr'] as $day_sql_key ) {
129 foreach ( $available_slots[ $day_sql_key ] as $available_slot ) {
130 if (
131 ( $child_resource_id == $available_slot['resource_id'] )
132 && ( ! $available_slot['is_available'] )
133 ){
134 $availability_in_same_child_resources = array_diff( $availability_in_same_child_resources, array( $child_resource_id ) ); // Remove $child_resource_id from array
135 break;
136 }
137 }
138 }
139 }
140
141 // Reset indexes in this array for ability to get first [0] element in this arr.
142 $availability_in_same_child_resources = array_values( $availability_in_same_child_resources );
143 $main__resource_id = ( ! empty( $availability_in_same_child_resources ) ) ? $availability_in_same_child_resources[0] : 0;
144
145 // [ 2, 12, 11 ] <- ID of child booking resources, where we can save our booking in the same child booking resource!
146 if ( count( $availability_in_same_child_resources ) >= $how_many_items_to_book ) {
147
148 $availability_in_same_child_resources_by_dates = array();
149 foreach ( $local_params['dates_only_sql_arr'] as $day_sql_key ) {
150 $availability_in_same_child_resources_by_dates[ $day_sql_key ] = $availability_in_same_child_resources;
151 }
152 // Good Save it
153 return array(
154 'result' => 'ok',
155 'resources_in_dates' => $availability_in_same_child_resources_by_dates, // [ 2023-09-23 = [ 2, 10, 11 ], 2023-09-24 = [ 2, 10, 11 ]
156 'time_to_book' => $local_params['time_as_his_arr'], // [ "00:00:00", "24:00:00" ]
157 'main__resource_id' => $main__resource_id
158 );
159 } else {
160 // Bad not save
161 return array(
162 'result' => 'error',
163 'message' => __( 'These dates and times in this calendar are already booked or unavailable.', 'booking' )
164 . ' <br> '
165 . __( 'It is not possible to store this sequence of the dates into the one same resource.' , 'booking' )
166 . ' <br> '
167 . __( 'Please choose alternative date(s), times, or adjust the number of slots booked.' , 'booking' )
168 . ' <a href="javascript:void(0)" onclick="'
169 .'jQuery( this ).next().toggle();'
170 .'jQuery( this).hide();'
171 .'jQuery( this ).parents(\'.wpbc_alert_message\').parent().on(\'hide\',function(even){jQuery(this).show();});'
172 .'">'
173 . __( 'Show more details', 'booking' )
174 . '</a>'
175 . ' <div style="display:none;">'
176 . '<p><hr><code>'
177 . wp_json_encode( $available_slots )
178 . '</code></p>'
179 . '</div>'
180 . ' <div style="display:none;">' . wp_json_encode( $available_slots ) . '</div>'
181 );
182 }
183
184 } else {
185
186 // == In ANY 'child' booking resources =========================================================
187
188 $availability_in_any_child_resources = array();
189 foreach ( $available_slots as $day_sql_key => $available_slot ) { // '2023-09-10': [], '2023-09-14': [],
190 $availability_in_any_child_resources[ $day_sql_key ] = array();
191 foreach ( $available_slot as $ind => $slot_value ) { // [ 0:{ resource_id: 2, is_available: false,...} , .... ]
192 if ( $slot_value['is_available'] ) {
193 if ( empty( $main__resource_id ) ) {
194 $main__resource_id = $slot_value['resource_id'];
195 }
196 $availability_in_any_child_resources[ $day_sql_key ][] = $slot_value['resource_id'];
197 }
198 }
199 }
200 /**
201 * { "2023-09-10": [ 2, 10, 11 ] <- available ID of child resources in this date
202 "2023-09-14": [ 4 ] <- available ID of child resources in this date
203 }
204 */
205
206 foreach ( $availability_in_any_child_resources as $day_sql_key2 => $available_res_in_day_arr ) {
207 if ( count( $available_res_in_day_arr ) < $how_many_items_to_book ) {
208 // Bad not save
209 // We can not store booking in this date day_sql_key2, number of available child booking resources less than required
210 return array(
211 'result' => 'error',
212 'message' => __( 'These dates and times in this calendar are already booked or unavailable.', 'booking' )
213 . ' <br> '
214 . __( 'Please choose alternative date(s), times, or adjust the number of slots booked.' , 'booking' )
215 . ' <a href="javascript:void(0)" onclick="'
216 .'jQuery( this ).next().toggle();'
217 .'jQuery( this).hide();'
218 .'jQuery( this ).parents(\'.wpbc_alert_message\').parent().on(\'hide\',function(even){jQuery(this).show();});'
219 .'">'
220 . __( 'Show more details', 'booking' )
221 . '</a>'
222 . ' <div style="display:none;">'
223 . '<p><strong>'
224 /* translators: 1: ... */
225 . sprintf( __( 'Booking can not be saved in this date %1$s, number of available (single or child) booking resource(s) (%2$d) less than required (%3$d).', 'booking' )
226 , $day_sql_key2, count( $available_res_in_day_arr ), $how_many_items_to_book )
227 . '</strong><hr><code>'
228 . wp_json_encode( $available_slots )
229 // . wp_json_encode( $local_params, $availability_per_days )
230 . '</code></p>'
231 . '</div>'
232
233 );
234 }
235 }
236
237 // Good Save it
238 return array(
239 'result' => 'ok',
240 'resources_in_dates' => $availability_in_any_child_resources, // [ 2023-09-23 = [ 2, 10, 11 ], 2023-09-24 = [ 2, 10, 11 ]
241 'time_to_book' => $local_params['time_as_his_arr'], // [ "00:00:00", "24:00:00" ]
242 'main__resource_id' => $main__resource_id
243 );
244 }
245 }
246
247
248 /**
249 * Get available slots per each date in each slot (child resource). It's checking times as well.
250 *
251 * @param $params [
252 * dates_sql__arr = [ "2023-10-18", "2023-10-25", "2023-11-25" ]
253 * time_as_seconds_arr = [ 36030, 39570 ]
254 * availability_per_days = [ dates = [...], resources_id_arr__in_dates = [...] ]
255 * ]
256 *
257 * @return array [
258 * 2023-10-18 = [
259 * 0 = [
260 * resource_id = 2
261 * is_available = true
262 * booked__seconds = []
263 * booked__readable = []
264 * time_to_book__seconds = [ 36030, 39570 ]
265 * time_to_book__readable = "10:00:00", "11:00:00" ]
266 * ]
267 * 1 = [...]
268 * 2 = [...]
269 * 3 = [...]
270 * ]
271 * 2023-10-25 = [...]
272 * 2023-11-25 = [...]
273 * ]
274 */
275 function wpbc__get_available_slots__for_selected_dates_times__bl( $params ) {
276
277 $defaults = array(
278 'dates_sql__arr' => array(),
279 'time_as_seconds_arr' => array(),
280 'availability_per_days' => array(),
281 'time_override_source' => '',
282 'is_use_booking_recurrent_time' => ( 'On' === get_bk_option( 'booking_recurrent_time' ) )
283 );
284 $params = wp_parse_args( $params, $defaults );
285
286 $time_as_seconds_arr = $params['time_as_seconds_arr'];
287
288 // Shift time interval in 30 seconds
289 $shift__30sec = array( 30, 30 );
290 $time_as_seconds_arr[ 0 ] = $time_as_seconds_arr[ 0 ] + $shift__30sec[0];
291 $time_as_seconds_arr[ 1 ] = $time_as_seconds_arr[ 1 ] - $shift__30sec[1];
292
293 $available_resources_arr = array();
294
295 foreach ( $params['dates_sql__arr'] as $sql_class_day_number => $sql_class_day ) {
296 $available_resources_arr[ $sql_class_day ] = array();
297 $date_shift__30sec = $shift__30sec;
298
299 if ( isset( $params['availability_per_days']['dates'][ $sql_class_day ] ) ) {
300
301 $this_date_time_as_seconds_arr = $time_as_seconds_arr;
302
303 //TODO: debug this checking in biz_l.js 2023-09-05 16:40 --- If we are using not time slot but the check in/out times ?
304
305 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
306 // Duplicated part of code, as in ../do_search.php //FixIn: 2024-05-12_11:58
307 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
308 if (
309 ( ! $params['is_use_booking_recurrent_time'] )
310 && ( count( $params['dates_sql__arr'] ) > 1 )
311 ) {
312 if ( 0 == $sql_class_day_number ) { // check in
313 $this_date_time_as_seconds_arr[1] = 24 * 60 * 60;
314 $date_shift__30sec[1] = 0;
315 } else if ( ( count( $params['dates_sql__arr'] ) - 1 ) == $sql_class_day_number ) { // check out
316 $this_date_time_as_seconds_arr[0] = 0;
317 $date_shift__30sec[0] = 0;
318 } else {
319 $this_date_time_as_seconds_arr = array( 0, 24 * 60 * 60 );
320 $date_shift__30sec = array( 0, 0 );
321 }
322 }
323 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
324
325 $date_bookings_obj = $params['availability_per_days']['dates'][ $sql_class_day ];
326
327 foreach ( $params['availability_per_days']['resources_id_arr__in_dates'] as $child_resource_id ) {
328
329 $merged_seconds_arr = wpbc_get__booking_obj__merged_seconds_arr( $date_bookings_obj[ $child_resource_id ], $params['time_override_source'] );
330
331 $is_intersect = wpbc_is_intersect__merged_seconds_arr__and__seconds_arr( $merged_seconds_arr['merged_seconds'], $this_date_time_as_seconds_arr );
332
333 $this_date_available_resource = array(
334 'resource_id' => $child_resource_id,
335 'is_available' => (! $is_intersect),
336 'booked__seconds' => $merged_seconds_arr['merged_seconds'],
337 'booked__readable' => $merged_seconds_arr['merged_readable'],
338 'time_to_book__seconds' => $this_date_time_as_seconds_arr,
339 'time_to_book__readable'=> array()
340 );
341 $this_date_available_resource['time_to_book__readable'][] = wpbc_transform__seconds__in__24_hours_his(
342 (
343 ( ( $this_date_time_as_seconds_arr[0] - $date_shift__30sec[0] ) < 0 )
344 ? 0
345 : ( $this_date_time_as_seconds_arr[0] - $date_shift__30sec[0] )
346 )
347 );
348 $this_date_available_resource['time_to_book__readable'][] = wpbc_transform__seconds__in__24_hours_his(
349 (
350 ( ( $this_date_time_as_seconds_arr[1] + $date_shift__30sec[1] ) > 86400 )
351 ? 86400
352 : ( $this_date_time_as_seconds_arr[1] + $date_shift__30sec[1] )
353 )
354 );
355
356 $available_resources_arr[ $sql_class_day ][] = $this_date_available_resource;
357 }
358 }
359 }
360
361 return $available_resources_arr;
362 }
363
364
365 /**
366 * Get Merged Seconds Array from object -> $params['availability_per_days']['dates'][ $sql_class_day ][ $child_resource_id ]
367 *
368 * @param $date_booking_obj - date_bookings_obj from $params['availability_per_days']['dates']
369 *
370 * @return array - [
371 * 'merged_seconds' => $merged_seconds,
372 * 'merged_readable' => $merged_readable
373 * ]
374 */
375 function wpbc_get__booking_obj__merged_seconds_arr( $date_booking_obj, $time_override_source = '' ) {
376
377 $is_times_availability_full_day_status = (
378 ( 'times_availability' === $time_override_source )
379 && ( ! empty( $date_booking_obj->is_day_unavailable ) )
380 && ( ! empty( $date_booking_obj->_day_status ) )
381 && ( 'full_day_booking' === $date_booking_obj->_day_status )
382 );
383
384 if ( $is_times_availability_full_day_status ) {
385 $merged_seconds_arr = wpbc_get__booking_obj__booked_details_seconds_arr( $date_booking_obj );
386 if ( ! empty( $merged_seconds_arr['merged_seconds'] ) ) {
387 return $merged_seconds_arr;
388 }
389 }
390
391 if ( $date_booking_obj->is_day_unavailable ){
392 $merged_seconds = array( array( 0, 24 * 60 * 60 ) ); // Unavailable
393 $merged_readable = array( wpbc_transform_timerange__seconds_arr__in__formated_hours( array( 0, 24 * 60 * 60 ) ) );
394 } else {
395 $merged_seconds = $date_booking_obj->booked_time_slots['merged_seconds']; // [ [ 25211, 27002 ], [ 36011, 86400 ] ] // Time slots or Available
396 $merged_readable = $date_booking_obj->booked_time_slots['merged_readable'];
397 }
398
399 return array(
400 'merged_seconds' => $merged_seconds,
401 'merged_readable' => $merged_readable
402 );
403 }
404
405
406 /**
407 * Rebuild real booked intervals from details after capacity marks the whole day unavailable.
408 *
409 * @param object $date_booking_obj Availability object for a date/resource.
410 *
411 * @return array
412 */
413 function wpbc_get__booking_obj__booked_details_seconds_arr( $date_booking_obj ) {
414
415 $seconds_arr = array();
416 $readable_arr = array();
417
418 if ( empty( $date_booking_obj->__booked__times__details ) || ! is_array( $date_booking_obj->__booked__times__details ) ) {
419 return array(
420 'merged_seconds' => array(),
421 'merged_readable' => array(),
422 );
423 }
424
425 foreach ( $date_booking_obj->__booked__times__details as $time_key => $details ) {
426 if ( '0' === (string) $time_key || false === strpos( (string) $time_key, '-' ) ) {
427 $seconds_arr[] = array( 0, 24 * 60 * 60 );
428 } else {
429 $seconds_arr[] = wpbc_transform_timerange__s_range__in__seconds_arr( $time_key );
430 }
431 }
432
433 $seconds_arr = wpbc_merge_intersected_intervals( $seconds_arr );
434
435 foreach ( $seconds_arr as $booked_time_slots__in_seconds ) {
436 $readable_arr[] = wpbc_transform_timerange__seconds_arr__in__formated_hours( $booked_time_slots__in_seconds );
437 }
438
439 return array(
440 'merged_seconds' => $seconds_arr,
441 'merged_readable' => $readable_arr,
442 );
443 }
444
445
446 /**
447 * Check if merged_seconds in $params['availability_per_days']['dates'][ $sql_class_day ][ $child_resource_id ] intersect with $time_as_seconds_arr
448 *
449 * @param $merged_seconds - [ [ 0, 86400 ] ]
450
451 * @param $this_date_time_as_seconds_arr - [ 36030, 39570 ] | [ 0, 24*60*60 ]
452 *
453 * @return bool
454 */
455 function wpbc_is_intersect__merged_seconds_arr__and__seconds_arr( $merged_seconds, $this_date_time_as_seconds_arr ) {
456
457 $is_intersect = wpbc_is_intersect__range_time_interval(
458 array(
459 array(
460 intval( $this_date_time_as_seconds_arr[ 0 ] ) + 20
461 , intval( $this_date_time_as_seconds_arr[ 1 ] ) - 20
462 )
463 )
464 , $merged_seconds );
465 return $is_intersect;
466 }
467
468
469 /**
470 * Is these array of intervals intersected ? - overlay of Math function
471 *
472 * @param array $time_interval_A array( array( 21600, 23400 ) )
473 * @param array $time_interval_B array( array( 25211, 27002 ), array( 36011, 86400 ) )
474 *
475 * @return bool
476 */
477 function wpbc_is_intersect__range_time_interval( $time_interval_A, $time_interval_B ){
478
479 for ( $i = 0; $i < count($time_interval_A); $i++ ){
480
481 for ( $j = 0; $j < count($time_interval_B); $j++ ){
482
483 $is_intersect = wpbc_is__intervals__intersected( $time_interval_A[ $i ], $time_interval_B[ $j ] );
484
485 if ( $is_intersect ){
486 return true;
487 }
488 }
489 }
490
491 return false;
492 }
493