PluginProbe
Booking Calendar / 10.11.2
Booking Calendar v10.11.2
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 10.11.3 All 202 releases
booking / core / wpbc_functions_dates.php

wpbc_functions_dates.php in Booking Calendar 10.11.2, at core/wpbc_functions_dates.php

686 lines 27.1 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
4
5 // ---------------------------------------------------------------------------------------------------------------------
6 // Localize dates
7 // ---------------------------------------------------------------------------------------------------------------------
8
9
10 /**
11 * Return date / time in 'LOCAL_FORMAT'.
12 *
13 * @param string|int $date_str_ymdhis Date to format.
14 * @param string $format Optional. Date/Time Format, like 'Y-m-d H:i:s'
15 * @param bool $is_add_timezone_offset Optional. Timezone offset.
16 *
17 * @return string
18 */
19 function wpbc_datetime_localized( $date_str_ymdhis, $format = '', $is_add_timezone_offset = false ) {
20
21 if ( empty( $format ) ) {
22 $format = sprintf( '%s %s', get_option( 'booking_date_format' ), get_option( 'booking_time_format' ) );
23 }
24 if ( empty( $format ) ) {
25 $format = sprintf( '%s %s', get_option( 'date_format' ), get_option( 'time_format' ) );
26 }
27
28 $server_zone = date_default_timezone_get(); // If in 'Theme' or 'other plugin' set default timezone other than UTC. Save it.
29 if ( 'UTC' !== $server_zone ) { // Needed for WP date functions - set timezone to UTC
30 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
31 @date_default_timezone_set( 'UTC' );
32 }
33
34 if ( is_string( $date_str_ymdhis ) ) {
35 $date_str_ymdhis = strtotime( $date_str_ymdhis );
36 }
37
38 if ( $is_add_timezone_offset ) {
39 $date_str_ymdhis += (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
40 }
41
42 $local_date = date_i18n( $format, $date_str_ymdhis );
43
44 if ( 'UTC' !== $server_zone ) { // Back to previos state, if it was changed.
45 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
46 @date_default_timezone_set( $server_zone );
47 }
48
49 return $local_date;
50 }
51
52 // -----------------------------------------------------------------------------------------------------------------
53
54 // FixIn: 9.9.0.17.
55 /**
56 * Return date / time in 'LOCAL_FORMAT' with WordPress Timezone offset from WordPress > Settings General page
57 *
58 * @param string|int $date_str_ymdhis Date to format.
59 * @param string $format Optional. Date/Time Format, like 'Y-m-d H:i:s'
60 *
61 * @return string
62 */
63 function wpbc_datetime_localized__use_wp_timezone( $date_str_ymdhis, $format = '') {
64
65 $is_add_timezone_offset = true;
66
67 $datetime_localized = wpbc_datetime_localized( $date_str_ymdhis, $format, $is_add_timezone_offset );
68
69 return $datetime_localized;
70 }
71
72 /**
73 * Return date / time in 'LOCAL_FORMAT' without WordPress Timezone offset - NO TIMEZONE
74 *
75 * @param string|int $date_str_ymdhis Date to format.
76 * @param string $format Optional. Date/Time Format, like 'Y-m-d H:i:s'
77 *
78 * @return string
79 */
80 function wpbc_datetime_localized__no_wp_timezone( $date_str_ymdhis, $format = '') {
81
82 $is_add_timezone_offset = false;
83
84 $datetime_localized = wpbc_datetime_localized( $date_str_ymdhis, $format, $is_add_timezone_offset );
85
86 return $datetime_localized;
87 }
88
89
90 // -----------------------------------------------------------------------------------------------------------------
91
92 /**
93 * Return date / time in 'LOCAL_FORMAT' with WordPress Timezone offset from WordPress > Settings General page,
94 * Better use: wpbc_datetime_localized__use_wp_timezone()
95 *
96 * @param string $format Optional. Date/Time Format, like 'Y-m-d H:i:s'
97 * @param string|int $date_str_ymdhis Date to format, e.g.: '2025-01-25 12:27:20'
98 *
99 * @return string
100 */
101 function wpbc_datetime__use_wp_timezone( $format, $date_str_ymdhis = '' ) {
102
103 if ( '' === $date_str_ymdhis ) {
104 $date_str_ymdhis = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
105 }
106
107 return wpbc_datetime_localized__use_wp_timezone( $date_str_ymdhis, $format );
108 }
109
110
111 /**
112 * Return date / time in 'LOCAL_FORMAT' without WordPress Timezone offset - NO TIMEZONE
113 * Better use: wpbc_datetime_localized__no_wp_timezone()
114 *
115 * @param string $format Optional. Date/Time Format, like 'Y-m-d H:i:s'
116 * @param string|int $date_str_ymdhis Date to format, e.g.: '2025-01-25 12:27:20'
117 *
118 * @return string
119 */
120 function wpbc_datetime__no_wp_timezone( $format, $date_str_ymdhis = '' ) {
121
122 if ( '' === $date_str_ymdhis ) {
123 $date_str_ymdhis = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
124 }
125
126 return wpbc_datetime_localized__no_wp_timezone( $date_str_ymdhis, $format );
127 }
128
129
130 // -----------------------------------------------------------------------------------------------------------------
131
132
133 /**
134 * Return date in 'LOCAL_FORMAT'.
135 *
136 * @param string|int $date_str_ymd Date to format.
137 * @param string $format Optional. Date/Time Format, like 'Y-m-d'
138 * @param bool $is_add_timezone_offset Optional. Timezone offset.
139 *
140 * @return string
141 */
142 function wpbc_date_localized( $date_str_ymd, $format = '', $is_add_timezone_offset = false ) {
143
144 if ( empty( $format ) ) {
145 $format = get_option( 'booking_date_format' );
146 }
147 if ( $format === '' ) {
148 $format = get_option( 'date_format' );
149 }
150
151 return wpbc_datetime_localized( $date_str_ymd, $format, $is_add_timezone_offset );
152 }
153
154 /**
155 * Return date in 'LOCAL_FORMAT'.
156 *
157 * @param string|int $time_str_his Date to format.
158 * @param string $format Optional. Date/Time Format, like 'Y-m-d'
159 * @param bool $is_add_timezone_offset Optional. Timezone offset.
160 *
161 * @return string
162 */
163 function wpbc_time_localized( $time_str_his, $format = '', $is_add_timezone_offset = false ) {
164
165 if ( empty( $format ) ) {
166 $format = get_option( 'booking_time_format' );
167 }
168 if ( $format === '' ) {
169 $format = get_option( 'time_format' );
170 }
171
172 return wpbc_datetime_localized( $time_str_his, $format, $is_add_timezone_offset );
173 }
174
175
176 // ---------------------------------------------------------------------------------------------------------------------
177 // Localize support
178 // ---------------------------------------------------------------------------------------------------------------------
179
180 /**
181 * Get localized Dates as comma separated string from SQL comma separated Dates
182 *
183 * @param string $dates_str_in_sql_format - '2015-02-29 00:00:00, 2015-02-30 00:00:00' | '2015-02-29, 2015-02-30' | '2015-02-29 16:00:00, 2015-02-30 12:00:00'
184 *
185 * @return string - localized comma separated Dates string
186 */
187 function wpbc_get_dates_comma_string_localized( $dates_str_in_sql_format ) {
188
189 if ( empty( $dates_str_in_sql_format ) ) {
190 return '';
191 }
192
193 $dates_array_in_sql_format = explode( ',', $dates_str_in_sql_format );
194
195 $result_dates_arr = array();
196
197 foreach ( $dates_array_in_sql_format as $date_sql ) {
198
199 $date_sql = trim( $date_sql );
200
201 $date_arr = explode( ' ', $date_sql );
202
203 if ( count( $date_arr ) > 1 ) {
204 $time_arr = explode( ':', $date_arr[1] );
205 } else {
206 $time_arr = array( '00', '00', '00' );
207 }
208
209 if ( $time_arr == array( '00', '00', '00' ) ) {
210 $result_dates_arr[] = wpbc_date_localized( $date_sql ); // Only Date
211 } else {
212 $result_dates_arr[] = wpbc_datetime_localized( $date_sql ); // Date and Time
213 }
214 }
215
216 $mydates_result = implode( ', ', $result_dates_arr );
217
218 return $mydates_result;
219 }
220
221
222 // ---------------------------------------------------------------------------------------------------------------------
223 // Readable dates
224 // ---------------------------------------------------------------------------------------------------------------------
225
226 /**
227 * Get readable dates for showing text to Users.
228 *
229 * @param $dates_ymd_arr [ '2023-10-11', '2023-11-12', '2023-11-13' ]
230 * @param $params [ ] Optional
231 *
232 * @return string
233 */
234 function wpbc_get_redable_dates( $dates_ymd_arr , $params = array() ){
235
236 $defaults = array(
237 'is_use_booking_recurrent_time' => ( 'On' === get_bk_option( 'booking_recurrent_time' ) ),
238 'output_dates' => get_bk_option( 'booking_date_view_type' ), // 'short' | 'wide'
239 'date_label' => ( wpbc_is_multiple_dates( $dates_ymd_arr ) ) ? __( 'Dates', 'booking' ) : __( 'Date', 'booking' ),
240 'is_in_html' => true
241 );
242 $params = wp_parse_args( $params, $defaults );
243
244 if ( 'short' == $params['output_dates'] ) {
245 $dates_view = wpbc_get_dates_short_format( implode( ',', $dates_ymd_arr ) ); // Short dates: '01 Jan 2023 - 30 Jan 2023'
246 } else {
247 $dates_view = wpbc_get_dates_comma_string_localized( implode( ',', $dates_ymd_arr ) ); // Comma separated dates: '01 Jan 2023, 02 Jan 2023, ... 30 Jan 2023'
248 }
249
250
251 $readable_dates_html = '';
252
253 $readable_dates_html .= ( ! empty( $params['date_label'] ) )
254 ? $params['date_label'] . ': '
255 : '';
256
257 $readable_dates_html .= ( $params['is_in_html'] )
258 ? '<strong>' . $dates_view . '</strong>'
259 : $dates_view;
260
261 return $readable_dates_html;
262 }
263
264
265
266
267 /**
268 * Get readable dates for showing text to Users.
269 *
270 * @param $dates_ymd_arr [ '2023-10-11', '2023-11-12', '2023-11-13' ]
271 * @param $times_arr_his [ "16:00:01", "18:00:02" ]
272 * @param $params [ ] Optional
273 *
274 * @return string
275 */
276 function wpbc_get_redable_times( $dates_ymd_arr , $times_arr_his, $params = array() ){
277
278 $defaults = array(
279 'is_use_booking_recurrent_time' => ( 'On' === get_bk_option( 'booking_recurrent_time' ) ),
280 'output_dates' => get_bk_option( 'booking_date_view_type' ), // 'short' | 'wide'
281 'times_label' => ( wpbc_is_multiple_dates( $dates_ymd_arr ) ) ? __( 'Dates', 'booking' ) : __( 'Date', 'booking' ),
282 'is_in_html' => true
283 );
284 $params = wp_parse_args( $params, $defaults );
285
286 if ( wpbc_is_times_used_as_timeslots( $dates_ymd_arr ) ){
287 $readable_times_html = __( 'Time', 'booking' ) . ': <strong>' . wpbc_time_localized( $times_arr_his[0] ) . ' - ' . wpbc_time_localized( $times_arr_his[1] ) . '</strong>';
288 } else {
289 $readable_times_html = __( 'Check in', 'booking' ) . ': <strong>' . wpbc_time_localized( $times_arr_his[0] ) . '</strong>' . ' '
290 . __( 'Check out', 'booking' ) . ': <strong>' . wpbc_time_localized( $times_arr_his[1] ) . '</strong>';
291 }
292
293 return $readable_times_html;
294
295
296 // $readable_times_html = '';
297 //
298 // $readable_times_html .= ( ! empty( $params['date_label'] ) )
299 // ? $params['date_label'] . ': '
300 // : '';
301 //
302 // $readable_times_html .= ( $params['is_in_html'] )
303 // ? '<strong>' . $dates_view . '</strong>'
304 // : $dates_view;
305 //
306 // return $readable_times_html;
307 }
308
309
310
311 /**
312 * Get days in short format view
313 *
314 * @param string $sql_dates_str Dates: 2023-10-12, 2023-10-13, 2023-10-14
315 *
316 * @return string Dates in format: 2023-10-12 - 2023-10-14
317 */
318 function wpbc_get_dates_short_format( $sql_dates_str ) { // $days - string with comma seperated dates
319
320 if ( empty( $sql_dates_str ) ) {
321 return '';
322 }
323
324 $sql_dates_arr = explode( ',', $sql_dates_str );
325 $previos_date = '';
326 $short_dates_arr = array();
327
328 foreach ( $sql_dates_arr as $date_sql ) {
329
330 $date_sql = trim( $date_sql );
331
332 if ( empty( $previos_date ) ) {
333
334 // 1st date
335 $short_dates_arr[] = wpbc_get_dates_comma_string_localized( $date_sql ); // Readable date format
336
337 } else {
338
339 // 2nd and more
340 //if ( wpbc_is_next_day( $date_sql, $previos_date ) ) {
341 $next_day_if__check_in__then__check_out = true;
342 if ( wpbc_is_less_than_next_day( $date_sql, $previos_date, $next_day_if__check_in__then__check_out ) ) {
343
344 if ( ' - ' != $short_dates_arr[ ( count( $short_dates_arr ) - 1 ) ] ){
345 $short_dates_arr[] = ' - ';
346 }
347
348 } else {
349
350 if ( ' - ' == $short_dates_arr[ ( count( $short_dates_arr ) - 1 ) ] ){
351
352 $short_dates_arr[] = wpbc_get_dates_comma_string_localized( $previos_date );
353 }
354
355 $short_dates_arr[] = ', ';
356 $short_dates_arr[] = wpbc_get_dates_comma_string_localized( $date_sql ); // Readable date format
357 }
358 }
359
360 $previos_date = $date_sql;
361 }
362
363 if ( ' - ' == $short_dates_arr[ ( count( $short_dates_arr ) - 1 ) ] ){
364 $short_dates_arr[] = wpbc_get_dates_comma_string_localized( $previos_date );
365 }
366
367 $result_string = implode( '', $short_dates_arr );
368
369 return $result_string;
370 }
371
372
373
374 // ---------------------------------------------------------------------------------------------------------------------
375 // Dates Math
376 // ---------------------------------------------------------------------------------------------------------------------
377
378 /**
379 * Is multiple dates
380 *
381 * @param $dates_ymd_arr [ '2023-10-11', '2023-11-12', '2023-11-13' ]
382 *
383 * @return bool
384 */
385 function wpbc_is_multiple_dates( $dates_ymd_arr ) {
386
387 return (bool) ( count( $dates_ymd_arr ) );
388 }
389
390
391 /**
392 * Is times use as 'TIME-SLOT' or 'CHECK IN/OUT' [start/end time] for first and last dates ?
393 *
394 * @param $dates_ymd_arr [ '2023-10-11', '2023-11-12', '2023-11-13' ]
395 *
396 * @return bool
397 */
398 function wpbc_is_times_used_as_timeslots( $dates_ymd_arr ) {
399
400 if ( ( count( $dates_ymd_arr ) > 1 ) && ( 'On' != get_bk_option( 'booking_recurrent_time' ) ) ) {
401 return false; // Check In/Out
402 } else {
403 return true; // Time Slots
404 }
405 }
406
407
408 /**
409 * Check if $now_date_sql is TOMORROW of $previous_date_sql
410 *
411 * @param string $now_date_sql : '2015-02-29' | '2015-02-29 00:00:00'
412 * @param string $previous_date_sql : '2015-02-30' | '2015-02-30 00:00:00'
413 *
414 * @return boolean : true | false
415 */
416 function wpbc_is_next_day( $now_date_sql, $previous_date_sql ) {
417
418 if ( empty( $previous_date_sql ) ) {
419 return false;
420 }
421
422 $now_date_sql = wpbc_date_sql__ymd_his__to__ymd_000( $now_date_sql );
423 $previous_date_sql = wpbc_date_sql__ymd_his__to__ymd_000( $previous_date_sql );
424
425 $is_next_date = ( strtotime( $now_date_sql ) == strtotime( '+1 day', strtotime( $previous_date_sql ) ) );
426
427 return $is_next_date;
428 }
429
430 /**
431 * Check if $now_date_sql is TOMORROW of $previous_date_sql
432 *
433 * @param string $now_date_sql : '2015-02-29' | '2015-02-29 00:00:00'
434 * @param string $previous_date_sql : '2015-02-30' | '2015-02-30 00:00:00'
435 *
436 * @return boolean : true | false
437 */
438 function wpbc_is_less_than_next_day( $now_date_sql, $previous_date_sql, $next_day_if__check_in__then__check_out = false ) {
439
440 if ( empty( $previous_date_sql ) ) {
441 return false;
442 }
443
444 $now_date_sql = wpbc_date_sql__ymd_his__to__ymd_000( $now_date_sql );
445 $previous_date_sql = wpbc_date_sql__ymd_his__to__ymd_000( $previous_date_sql );
446
447 $is_next_date = ( strtotime( $now_date_sql ) <= strtotime( '+1 day', strtotime( $previous_date_sql ) ) );
448
449 // One exception for dates with check in/out times. For example '2023-10-13 13:00:01' <=> '2023-10-13 10:00:02'
450 // return false,
451 // because it's check in/out dates for the dif bookings or "recurrent times"
452 if ( ( $is_next_date )
453 && ( $next_day_if__check_in__then__check_out )
454 && ( '1' == substr( $now_date_sql, 18 ) )
455 && ( '2' == substr( $previous_date_sql, 18 ) )
456 ){
457 $is_next_date = false;
458 }
459
460
461 return $is_next_date;
462 }
463
464
465 /**
466 * Convert SQL date '2023-10-12 14:40:01' -> '2023-10-12 00:00:00'
467 *
468 * @param $sql_date '2023-10-12 14:40:01'
469 *
470 * @return string '2023-10-12 00:00:00'
471 */
472 function wpbc_date_sql__ymd_his__to__ymd_000( $sql_date ) {
473
474 $sql_date = trim( $sql_date );
475
476 $date_arr = explode( ' ', $sql_date );
477
478 return $date_arr[0] . ' 00:00:00';
479 }
480
481
482
483
484 /**
485 * Get weekday NUM from date_sql_str '2023-10-26' -> 4
486 *
487 * @param $date_sql_str
488 *
489 * @return int
490 */
491 function wpbc_date_get_week_day_num( $date_sql_str ) {
492
493 return intval( gmdate( 'w', strtotime( $date_sql_str ) ) );
494 }
495
496
497
498
499 // ---------------------------------------------------------------------------------------------------------------------
500 // Dates Debug
501 // ---------------------------------------------------------------------------------------------------------------------
502
503 //TODO: replace functions like this: date_i18n( 'Y-m-d H:i:s' ... to wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s',
504 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
505 // date_default_timezone_set( 'Europe/Amsterdam' ); // For Debug in Booking Calendar - booking form, for shortcode [wpbc_test_dates_functions] this line can be commented
506
507 // <editor-fold defaultstate="collapsed" desc=" == [wpbc_test_dates_functions] == " >
508 //TODO: delete it in version 9.9 or later, if no errors
509 /**
510 * Shortcode [wpbc_test_dates_functions] to test different dates functions on the server.
511 *
512 * @return void
513 */
514 function wpbc_test_dates_functions() {
515
516 if ( wpbc_is_on_edit_page() ) {
517 return wpbc_get_preview_for_shortcode( 'wpbc_test_dates_functions', array() ); // FixIn: 9.9.0.39.
518 }
519
520 ob_start();
521 ob_clean();
522
523 $server_zone = date_default_timezone_get();
524 debuge( array( 'init' => 'Default Timezones', 'server' => date_default_timezone_get(), 'wordpress' => wp_timezone()->getName(), 'wordpress - gmt_offset' => get_option( 'gmt_offset' ) ) );
525 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
526 // date_default_timezone_set( 'Europe/Oslo' );
527 // date_default_timezone_set( 'Europe/Amsterdam' );
528 // date_default_timezone_set( 'UTC' );
529
530 debuge( array( 'init' => 'After WPBC changed timezone to UTC', 'server' => date_default_timezone_get(), 'wordpress' => wp_timezone()->getName(), 'wordpress - gmt_offset' => get_option( 'gmt_offset' ) ) );
531 echo '<hr>';
532 echo '<h1>Test dates functions: </h1>';
533
534
535 echo '<hr>';
536
537 for ( $i = 0; $i < 366; $i ++ ) {
538
539 $ts = gmdate( 'Y-m-d 16:00:01', strtotime( '+' . $i . ' days' ) );
540
541 $ts_arr = explode(' ',$ts);
542
543
544
545 $date_arr = array();
546 $date_arr['str'] = '+' . $i . ' days for ' . $ts_arr[0] . ' ' .$ts_arr[1] ;
547
548 $date_arr['server'] = date_default_timezone_get();
549 $date_arr['wordpress'] = wp_timezone()->getName();
550
551 $date_arr['loc_DT'] = wpbc_datetime_localized( $ts );
552 $date_arr['loc_D'] = wpbc_date_localized( $ts );
553 $date_arr['loc_T'] = wpbc_time_localized( $ts );
554
555 $date_arr['loc_D_param_D'] = wpbc_date_localized( $ts_arr[0] );
556 $date_arr['loc_T_param_T'] = wpbc_time_localized( $ts_arr[1] );
557
558
559 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_var_export
560 echo '<pre><code>' . var_export( $date_arr, 1 ) . '</code></pre><br>';
561 }
562 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
563 date_default_timezone_set( $server_zone );
564
565 debuge( array( 'end' => 'Back to default previos timezone', 'server' => date_default_timezone_get(), 'wordpress' => wp_timezone_string() ) );
566
567 $content = ob_get_contents();
568 ob_end_clean();
569
570 return $content;
571 }
572 add_shortcode( 'wpbc_test_dates_functions', 'wpbc_test_dates_functions' );
573 // </editor-fold>
574
575 //TODO: it's only for Debug: Comment it. // FixIn: 9.9.0.17.
576 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
577 // date_default_timezone_set( 'America/Chicago' ); // For Debug in Booking Calendar - booking form, for shortcode [wpbc_test_dates_functions] this line can be commented
578
579
580 // ---------------------------------------------------------------------------------------------------------------------
581 // Get available / unavailable intervals based from Today date (current time).
582 // ---------------------------------------------------------------------------------------------------------------------
583
584 /**
585 * Get unavailable from today array values and hints
586 *
587 * @return array - [
588 * booking_unavailable_days_num_from_today = "540m"
589 * booking_unavailable_days_num_from_today__hint = ": 2025-01-25 15:19 - 2025-01-26 00:18:42"
590 * booking_available_days_num_from_today = "0"
591 * booking_available_days_num_from_today__hint = ": 26 Jan, 2025 - ..."
592 * ]
593 */
594 function wpbc_get_unavailable_from_today_hints_arr() {
595
596 $data_arr = array();
597
598 // -----------------------------------------------------------------------------------------------------
599 // == UNAVAILABLE Today days ==
600 // -----------------------------------------------------------------------------------------------------
601 // FixIn: 10.8.1.4.
602 $last_unavailable_date = '';
603 if ( 'm' === substr( get_bk_option( 'booking_unavailable_days_num_from_today' ), - 1 ) ) {
604 // -------------------------------------------------------------------------------------------------
605 // == Minutes ==
606 // -------------------------------------------------------------------------------------------------
607 $data_arr['booking_unavailable_days_num_from_today'] = intval( get_bk_option( 'booking_unavailable_days_num_from_today' ) );
608
609 // Hints.
610 $data_arr['booking_unavailable_days_num_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">' . __( 'None', 'booking' ) . '</span>';
611 if ( ! empty( $data_arr['booking_unavailable_days_num_from_today'] ) ) {
612
613 $start_date_unix = strtotime( 'now' );
614 $todate_with_wp_timezone = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d H:i' );
615
616 $start_date_unix = strtotime( '+' . ( intval( $data_arr['booking_unavailable_days_num_from_today'] ) - 1 ) . ' minutes' );
617 $max_date_with_wp_timezone = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d H:i:s' );
618
619 $last_unavailable_date = $max_date_with_wp_timezone;
620
621 $data_arr['booking_unavailable_days_num_from_today__hint'] = ': <a style="color:#626262;" href="'.esc_url(get_admin_url( null, 'options-general.php#timezone_string' )).'">' . $todate_with_wp_timezone . '</a> - ' . $max_date_with_wp_timezone; // FixIn: 10.9.4.2.
622 }
623 $data_arr['booking_unavailable_days_num_from_today'] .= 'm';
624 } else {
625 // -------------------------------------------------------------------------------------------------
626 // == Days ==
627 // -------------------------------------------------------------------------------------------------
628 $data_arr['booking_unavailable_days_num_from_today'] = intval( get_bk_option( 'booking_unavailable_days_num_from_today' ) );
629
630 // Hints.
631 $data_arr['booking_unavailable_days_num_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">' . __( 'None', 'booking' ) . '</span>';
632
633 if ( 1 === $data_arr['booking_unavailable_days_num_from_today'] ) {
634 $last_unavailable_date = wp_date( 'Y-m-d 00:00:00' );
635 $data_arr['booking_unavailable_days_num_from_today__hint'] = ': ' . wp_date( 'd M', strtotime( $last_unavailable_date ) );
636 }
637 if ( $data_arr['booking_unavailable_days_num_from_today'] > 1 ) {
638 $last_unavailable_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $data_arr['booking_unavailable_days_num_from_today'] - 1 ) . ' days' ) );
639 $data_arr['booking_unavailable_days_num_from_today__hint'] = ': ' . wp_date( 'd M' ) . ' - ' . wp_date( 'd M', strtotime( $last_unavailable_date ) );
640 }
641 }
642
643 // -----------------------------------------------------------------------------------------------------
644 // == AVAILABLE Today days ==
645 // -----------------------------------------------------------------------------------------------------
646 // if ( class_exists( 'wpdev_bk_biz_m' ) ) { .
647 $data_arr['booking_available_days_num_from_today'] = esc_js( get_bk_option( 'booking_available_days_num_from_today' ) );
648
649 // Hints.
650 // $start_available_date = ( '' === $last_unavailable_date ) ? wp_date( 'Y-m-d 00:00:00' ) : wp_date( 'Y-m-d 00:00:00', strtotime( '+1 day', strtotime( $last_unavailable_date ) ) );
651 if ( '' === $last_unavailable_date ) {
652 $start_date_unix = strtotime( 'now' );
653 $todate_with_wp_timezone = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d 00:00:00' );
654 $start_available_date = $todate_with_wp_timezone;
655 } else {
656 $start_available_date = $last_unavailable_date;
657 // We use here with no WP timezone, because timezone already applied to $last_unavailable_date.
658 $start_available_date = wpbc_datetime_localized__no_wp_timezone( strtotime( $last_unavailable_date ), 'Y-m-d 00:00:00' );
659 }
660
661
662 if ( empty( $data_arr['booking_available_days_num_from_today'] ) ) {
663 $last_available_date = '';
664 } else {
665 // $last_available_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $data_arr['booking_available_days_num_from_today'] ) . ' days' ) );
666 // FixIn: 10.9.6.3.
667 $start_date_unix = strtotime( '+' . ( intval( $data_arr['booking_available_days_num_from_today'] ) - 1 ) . ' days' );
668 $last_available_date = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d 00:00:00' );
669 }
670
671 if ( ! empty( $data_arr['booking_available_days_num_from_today'] ) ) {
672
673 if ( strtotime( $start_available_date ) < strtotime( $last_available_date ) ) {
674
675 $data_arr['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . ' - ' . wp_date( 'd M, Y', strtotime( $last_available_date ) );
676 } else if ( strtotime( $start_available_date ) == strtotime( $last_available_date ) ) {
677 $data_arr['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) );
678 } else {
679 $data_arr['booking_available_days_num_from_today__hint'] = ': <span style="text-transform: uppercase;font-size:1.1em;">' . esc_html__( 'None', 'booking' ) . '</span><br>' . ' <span style="text-transform: lowercase;font-size:0.9em;color:#cc3a5f;">' . 'Start available' . ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . '<br>' . 'Last available' . ': ' . wp_date( 'd M, Y', strtotime( $last_available_date ) ) . '</span>';
680 }
681 } else {
682 $data_arr['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . ' - ...';
683 }
684
685 return $data_arr;
686 }