PluginProbe
Booking Calendar / 11.0
Booking Calendar v11.0
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 / js / wpbc_times.js

wpbc_times.js in Booking Calendar 11.0, at js/wpbc_times.js

684 lines 25.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var start_time_checking_index;
2
3 /**
4 * Get dots for partially booked dates.
5 * For parent booking resources with specific capacity,
6 * System do not show partially booked dates, if at least one child booking resource fully available
7 * Otherwise it show maximum number of time-slot in one specific child booking resource
8 *
9 * @param param_calendar_id ID of booking resource
10 * @param my_thisDateTime timestamp of date
11 * @returns {string}
12 */
13 function wpbc_show_date_info_top( param_calendar_id, my_thisDateTime ) {
14
15 var resource_id = parseInt(param_calendar_id.replace("calendar_booking", ''));
16
17 if (isNaN(resource_id)) {
18 return ''; // FixIn: 10.9.5.2.
19 }
20
21 // console.log( _wpbc.bookings_in_calendar__get( resource_id ) ); // for debug
22
23 // 1. Get child booking resources or single booking resource that exist in dates : [1] | [1,14,15,17]
24 var child_resources_arr = wpbc_clone_obj(_wpbc.booking__get_param_value(resource_id, 'resources_id_arr__in_dates'));
25
26 // '2023-08-21'
27 var sql_date = wpbc__get__sql_class_date(new Date(my_thisDateTime));
28
29 var child_resource_id;
30 var merged_seconds;
31 var dots_count = 0;
32
33 var dots_in__resources = [];
34
35 // Loop all resources ID.
36 if (child_resources_arr !== null) {
37 for (child_resource_id of child_resources_arr) { // FixIn: 10.9.5.1.
38
39 // _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[12].booked_time_slots.merged_seconds = [ "07:00:11 - 07:30:02", "10:00:11 - 00:00:00" ]
40 // _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[2].booked_time_slots.merged_seconds = [ [ 25211, 27002 ], [ 36011, 86400 ] ]
41
42 if (false !== _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date)) {
43 merged_seconds = _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date)[child_resource_id].booked_time_slots.merged_seconds; // [ [ 25211, 27002 ], [ 36011, 86400 ] ]
44 } else {
45 merged_seconds = [];
46 }
47
48 if (0 === merged_seconds.length) {
49 return ''; // Day available
50 }
51
52 for (var i = 0; i < merged_seconds.length; i++) {
53 if (!wpbc_is_this_timeslot__full_day_booked(merged_seconds[i])) { // Check if this fully booked date. If yes, then do not count it
54 dots_count++;
55 }
56 }
57
58 dots_in__resources.push(dots_count);
59 dots_count = 0;
60 }
61 }
62 var dots_count_max = Math.max.apply( Math, dots_in__resources ); // Get maximum value in array [ 1, 5, 3] -> 5
63
64 var dot_content = '';
65 for ( var d = 0; d < dots_count_max; d++ ){
66 dot_content += '&centerdot;';
67 }
68
69 dot_content = ( '' !== dot_content ) ? '<div class="wpbc_time_dots">' + dot_content + '</div>' : '';
70
71 return dot_content;
72 }
73
74 /**
75 * Show Date Info at bottom of the Day Cell
76 *
77 * @param param_calendar_id 'calendar_booking1'
78 * @param my_thisDateTime 56567557757
79 * @returns {string}
80 */
81 function wpbc_show_date_info_bottom( param_calendar_id, my_thisDateTime ) {
82
83 var bottom_hint_arr = [];
84
85 // Cost Hint
86 if ( typeof (wpbc_show_day_cost_in_date_bottom) == 'function' ) {
87 var cost_hint = wpbc_show_day_cost_in_date_bottom( param_calendar_id, my_thisDateTime );
88 if ( '' !== cost_hint ) {
89 bottom_hint_arr.push( wpbc_show_day_cost_in_date_bottom( param_calendar_id, my_thisDateTime ) );
90 }
91 }
92
93 // Availability Hint // FixIn: 10.6.4.1.
94 var availability = wpbc_get_in_date_availability_hint( param_calendar_id, my_thisDateTime )
95 if ( '' !== availability ) {
96 bottom_hint_arr.push( availability );
97 }
98
99 var bottom_hint = bottom_hint_arr.join( '' );
100 return bottom_hint;
101 }
102
103 /**
104 * Get Availability Hint for in Day Cell
105 *
106 * @param param_calendar_id
107 * @param my_thisDateTime
108 * @returns {string}
109 */
110 function wpbc_get_in_date_availability_hint( param_calendar_id, my_thisDateTime ) { // FixIn: 10.6.4.1.
111
112 /*
113 var sql_date = wpbc__get__sql_class_date( new Date( my_thisDateTime ) ); // '2023-08-21'
114 var resource_id = parseInt( param_calendar_id.replace( "calendar_booking", '' ) ); // 1
115 var day_availability_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_date ); // obj
116
117 if ( 'undefined' !== typeof (day_availability_obj.day_availability) ) {
118 return '<strong>' + day_availability_obj.day_availability + '</strong> ' + 'available';
119 } else {
120 return '';
121 }
122 */
123
124 var resource_id = parseInt( param_calendar_id.replace( "calendar_booking", '' ) );
125
126 // console.log( _wpbc.bookings_in_calendar__get( resource_id ) ); // for debug
127
128 // 1. Get child booking resources or single booking resource that exist in dates : [1] | [1,14,15,17]
129 // var child_resources_arr = wpbc_clone_obj( _wpbc.booking__get_param_value( resource_id, 'resources_id_arr__in_dates' ) );
130
131 // '2023-08-21'
132 var sql_date = wpbc__get__sql_class_date( new Date( my_thisDateTime ) );
133
134 var hint__in_day__availability = '';
135
136 var get_for_date_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_date );
137
138 if ( false !== get_for_date_obj ){
139
140 if (
141 (undefined != get_for_date_obj[ 'summary' ])
142 && (undefined != get_for_date_obj[ 'summary' ].hint__in_day__availability)
143 ){
144 hint__in_day__availability = get_for_date_obj[ 'summary' ].hint__in_day__availability; // "5 available"
145 }
146
147 }
148
149 return hint__in_day__availability;
150 }
151
152
153 /**
154 * Hide Tippy tooltip on scroll, to prevent issue on mobile touch devices of showing tooltip at top left corner!
155 * @param evt
156 */
157 jQuery( window ).on( 'scroll', function ( event ){ //FixIn: 9.2.1.5 // FixIn: 9.4.3.3.
158 if ( 'function' === typeof( wpbc_tippy ) ){
159 wpbc_tippy.hideAll();
160 }
161 } );
162
163
164 /**
165 * Check if in booking form exist times fields for booking for specific time-slot
166 * @param resource_id
167 * @param form_elements
168 * @returns {boolean}
169 */
170 function wpbc_is_time_field_in_booking_form( resource_id, form_elements ){ // FixIn: 8.2.1.28.
171
172 var count = form_elements.length;
173 var start_time = false;
174 var end_time = false;
175 var duration = false;
176 var element;
177
178 /**
179 * Get from booking form 'rangetime', 'durationtime', 'starttime', 'endtime', if exists.
180 */
181 for ( var i = 0; i < count; i++ ){
182
183 element = form_elements[ i ];
184
185 // Skip elements from garbage
186 if ( jQuery( element ).closest( '.booking_form_garbage' ).length ){ // FixIn: 7.1.2.14.
187 continue;
188 }
189
190 if (
191 ( element.name != undefined )
192 && ( element.name.indexOf( 'hint' ) !== -1 ) // FixIn: 9.5.5.2.
193 ){
194 var my_element = element.name; //.toString();
195 if ( my_element.indexOf( 'rangetime' ) !== -1 ){ // Range Time
196
197 return true;
198 }
199 if ( (my_element.indexOf( 'durationtime' ) !== -1) ){ // Duration
200 duration = element.value;
201 }
202 if ( my_element.indexOf( 'starttime' ) !== -1 ){ // Start Time
203 start_time = element.value;
204 }
205 if ( my_element.indexOf( 'endtime' ) !== -1 ){ // End Time
206 end_time = element.value;
207 }
208 }
209 }
210
211 // Duration get Values
212 if ( ( duration !== false ) && ( start_time !== false ) ){ // we have Duration and Start time
213 return true;
214 }
215
216 if ( ( start_time !== false ) && ( end_time !== false ) ){ // we have End time and Start time
217 return true;
218 }
219
220 return false;
221 }
222
223 function wpbc_is_change_over_enabled_for_resource( resource_id ) {
224
225 if ( ( 'undefined' !== typeof resource_id ) && ( null !== resource_id ) ) {
226 var resource_change_over = _wpbc.calendar__get_param_value( resource_id, 'is_enabled_change_over' );
227 if ( '' !== resource_change_over ) {
228 return ( true === resource_change_over ) || ( 'true' === resource_change_over );
229 }
230 }
231
232 return true === _wpbc.get_other_param( 'is_enabled_change_over' );
233 }
234
235
236 /**
237 * Check if the selected date/time is already in the past compared to "today_arr".
238 *
239 * Behavior notes:
240 * - If "is_enabled_change_over" is enabled, always returns false (no restriction).
241 * - `sort_date_array[0]` is expected to be the earliest selected date (sorted ascending).
242 * - `today_arr` is expected to be: [YYYY, MM, DD, HH, mm] (strings or numbers).
243 * - `myTime` is expected to be "HH:MM" (24h).
244 *
245 * @param {string} myTime Time string in "HH:MM" format.
246 * @param {Array<Array<string|number>>} sort_date_array Array of date arrays; first element is used as date to check.
247 * @returns {boolean} True if selected date/time is in the past, otherwise false.
248 */
249 function wpbc_is_time_in_the_past_for_today(myTime, sort_date_array, resource_id) {
250
251 // FixIn: 10.14.10.2.
252 if ( true === wpbc_is_change_over_enabled_for_resource( resource_id ) ) {
253 return false;
254 }
255 var date_to_check = sort_date_array[0];
256 if ( parseInt( date_to_check[0] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[0] ) ) {
257 return true;
258 }
259 if (
260 (parseInt( date_to_check[0] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[0] )) &&
261 (parseInt( date_to_check[1] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[1] ))
262 ) {
263 return true;
264 }
265 if (
266 (parseInt( date_to_check[0] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[0] )) &&
267 (parseInt( date_to_check[1] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[1] )) &&
268 (parseInt( date_to_check[2] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[2] ))
269 ) {
270 return true;
271 }
272 if (
273 (parseInt( date_to_check[0] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[0] )) &&
274 (parseInt( date_to_check[1] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[1] )) &&
275 (parseInt( date_to_check[2] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[2] ))
276 ) {
277 var mytime_value = myTime.split( ":" );
278 mytime_value = parseInt( mytime_value[0] ) * 60 + parseInt( mytime_value[1] );
279
280 var current_time_value = parseInt( _wpbc.get_other_param( 'today_arr' )[3] ) * 60 + parseInt( _wpbc.get_other_param( 'today_arr' )[4] );
281
282 if ( current_time_value > mytime_value ) {
283 return true;
284 }
285 }
286 return false;
287 }
288
289 /**
290 * Validate a time string.
291 *
292 * Supported formats:
293 * - 24-hour time: "H:MM" or "HH:MM"
294 * Examples: "0:00", "09:30", "23:59", "24:00"
295 * Notes: "24:00" is allowed, but "24:01" is not.
296 *
297 * - 12-hour time: "H:MM AM/PM" (AM/PM is case-insensitive; spaces are optional)
298 * Examples: "9:30 AM", "09:30pm", "12:05 PM"
299 *
300 * @param {string} time_str Raw time string entered by the user.
301 * @returns {boolean} True if the string matches a valid supported time format.
302 */
303 function wpbc_is_valid_time_string(time_str) {
304
305 if ( typeof time_str !== 'string' ) {
306 return false;
307 }
308
309 const str = time_str.trim();
310 if ( str === '' ) {
311 return false;
312 }
313
314 // 1-2 digit hours, 2 digit minutes, optional AM/PM (case-insensitive).
315 const match = str.match( /^(\d{1,2}):(\d{2})(?:\s*([AaPp][Mm]))?$/ );
316 if ( ! match ) {
317 return false;
318 }
319
320 const hour = Number( match[1] );
321 const minute = Number( match[2] );
322 const ampm = match[3] ? match[3].toUpperCase() : null;
323
324 if ( ! Number.isInteger( hour ) || ! Number.isInteger( minute ) ) {
325 return false;
326 }
327
328 if ( minute < 0 || minute > 59 ) {
329 return false;
330 }
331
332 // 12-hour mode (AM/PM provided): hour must be 1..12.
333 if ( ampm ) {
334 return hour >= 1 && hour <= 12;
335 }
336
337 // 24-hour mode (no AM/PM): hour must be 0..24, but 24 only allowed with :00.
338 if ( hour < 0 || hour > 24 ) {
339 return false;
340 }
341 if ( hour === 24 && minute !== 0 ) {
342 return false;
343 }
344
345 return true;
346 }
347
348
349 //TODO: Continue Refactoring here 2018-04-21
350
351 //PS: This function from personal.js
352 function wpbc_is_this_time_selection_not_available( resource_id, form_elements ){
353
354 // Skip this checking if we are in the Admin panel at Add booking page
355 if ( ( location.href.indexOf( 'page=wpbc' ) > 0 ) && ( location.href.indexOf( 'tab=add-booking' ) > 0 ) ) {
356 return false;
357 }
358
359 var count = form_elements.length;
360 var start_time = false;
361 var end_time = false;
362 var duration = false;
363 var element;
364 var element_start = false;
365 var element_end = false;
366 var element_duration = false;
367 var element_rangetime = false;
368
369 /**
370 * Get from booking form 'rangetime', 'durationtime', 'starttime', 'endtime', if exists.
371 */
372 for ( var i = 0; i < count; i++ ){
373
374 element = form_elements[ i ];
375
376 // Skip elements from garbage
377 if ( jQuery( element ).closest( '.booking_form_garbage' ).length ){ // FixIn: 7.1.2.14.
378 continue;
379 }
380
381 if (
382 ( element.name != undefined )
383 && ( element.name.indexOf( 'hint' ) === -1 ) //FixIn: 9.5.5.2 // FixIn: 9.6.3.9.
384 ){
385 var my_element = element.name; //.toString();
386 if ( my_element.indexOf( 'rangetime' ) !== -1 ){ // Range Time
387 if ( element.value == '' ){ //FixIn: 7.0.Beta.19
388 var notice_message_id = wpbc_front_end__show_message__warning( element, _wpbc.get_message( 'message_check_required' ) );
389 return true;
390 }
391 var my_rangetime = element.value.split( '-' );
392 if ( my_rangetime.length > 1 ){
393 start_time = my_rangetime[ 0 ].replace( /(^\s+)|(\s+$)/g, "" ); // Trim
394 end_time = my_rangetime[ 1 ].replace( /(^\s+)|(\s+$)/g, "" );
395 element_rangetime = element;
396 }
397 }
398 if ( (my_element.indexOf( 'durationtime' ) !== -1) ){ // Duration
399 duration = element.value;
400 element_duration = element;
401 }
402 if ( my_element.indexOf( 'starttime' ) !== -1 ){ // Start Time
403 start_time = element.value;
404 element_start = element;
405 }
406 if ( my_element.indexOf( 'endtime' ) !== -1 ){ // End Time
407 end_time = element.value;
408 element_end = element;
409 }
410 }
411 }
412
413
414 // Duration get Values
415 if ( (duration !== false) && (start_time !== false) ){ // we have Duration and Start time so try to get End time
416
417 var mylocalstarttime = start_time.split( ':' );
418 var d = new Date( 1980, 1, 1, mylocalstarttime[ 0 ], mylocalstarttime[ 1 ], 0 );
419
420 var my_duration = duration.split( ':' );
421 my_duration = my_duration[ 0 ] * 60 * 60 * 1000 + my_duration[ 1 ] * 60 * 1000;
422 d.setTime( d.getTime() + my_duration );
423
424 var my_hours = d.getHours();
425 if ( my_hours < 10 ) my_hours = '0' + (my_hours + '');
426 var my_minutes = d.getMinutes();
427 if ( my_minutes < 10 ) my_minutes = '0' + (my_minutes + '');
428
429 // We are get end time
430 end_time = (my_hours + '') + ':' + (my_minutes + '');
431 if ( end_time == '00:00' ) end_time = '23:59';
432 }
433
434
435 if ( (start_time === false) || (end_time === false) ){ // We do not have Start or End time or Both of them, so do not check it
436
437 return false;
438
439 } else {
440
441 var valid_time = true;
442 if ( (start_time == '') || (end_time == '') ) valid_time = false;
443
444 if ( !wpbc_is_valid_time_string( start_time ) ) valid_time = false;
445 if ( !wpbc_is_valid_time_string( end_time ) ) valid_time = false;
446
447 if ( valid_time === true )
448 if (
449 (typeof(checkRecurentTimeInside) == 'function') &&
450
451 ( _wpbc.get_other_param( 'is_enabled_booking_recurrent_time' ) == true )
452 ){ // Recheck Time here !!!
453 valid_time = checkRecurentTimeInside( [ start_time, end_time ], resource_id );
454 } else {
455
456 if ( typeof(checkTimeInside) == 'function' ){
457 valid_time = checkTimeInside( start_time, true, resource_id );
458 }
459
460 if ( valid_time === true ){
461 if ( typeof(checkTimeInside) == 'function' ){
462 valid_time = checkTimeInside( end_time, false, resource_id );
463 }
464 }
465 }
466
467 if ( valid_time !== true ){
468 //return false; // do not show warning for setting pending days selectable, if making booking for time-slot // FixIn: 7.0.1.23.
469 if ( ( wpbc_is_change_over_enabled_for_resource( resource_id ) ) && (element_start !== false) && (element_end !== false) ){ // FixIn: 6.1.1.1.
470 wpbc_front_end__show_message__warning_under_element( '#date_booking' + resource_id, _wpbc.get_message( 'message_check_no_selected_dates' ) );
471 }
472 if ( element_rangetime !== false ){ wpbc_front_end__show_message__warning_under_element( element_rangetime, _wpbc.get_message( 'message_error_range_time' ) ); }
473 if ( element_duration !== false ){ wpbc_front_end__show_message__warning_under_element( element_duration, _wpbc.get_message( 'message_error_duration_time' ) ); }
474 if ( element_start !== false ){ wpbc_front_end__show_message__warning_under_element( element_start, _wpbc.get_message( 'message_error_start_time' ) ); }
475 if ( element_end !== false ){ wpbc_front_end__show_message__warning_under_element( element_end, _wpbc.get_message( 'message_error_end_time' ) ); }
476
477 return true;
478
479 } else {
480 return false;
481 }
482
483 }
484
485
486 }
487
488 function checkTimeInside( mytime, is_start_time, bk_type ){
489
490 var my_dates_str = document.getElementById( 'date_booking' + bk_type ).value; // GET DATES From TEXTAREA
491
492 if ( my_dates_str.indexOf( ' - ' ) != 0 ){
493
494 my_dates_str = my_dates_str.replace( ' - ', ', ' ); // FixIn: 10.2.3.2.
495 }
496
497 return checkTimeInsideProcess( mytime, is_start_time, bk_type, my_dates_str );
498 }
499
500 function checkRecurentTimeInside( my_rangetime, bk_type ){
501
502 var valid_time = true;
503 var my_dates_str = document.getElementById( 'date_booking' + bk_type ).value; // GET DATES From TEXTAREA
504 // recurrent time check for all days in loop
505
506 var date_array = my_dates_str.split( ", " );
507 if ( date_array.length == 2 ){ // This recheck is need for editing booking, with single day
508 if ( date_array[ 0 ] == date_array[ 1 ] ){
509 date_array = [ date_array[ 0 ] ];
510 }
511 }
512 var temp_date_str = '';
513 for ( var i = 0; i < date_array.length; i++ ){ // Get SORTED selected days array
514 temp_date_str = date_array[ i ];
515 if ( checkTimeInsideProcess( my_rangetime[ 0 ], true, bk_type, temp_date_str ) == false ) valid_time = false;
516 if ( checkTimeInsideProcess( my_rangetime[ 1 ], false, bk_type, temp_date_str ) == false ) valid_time = false;
517
518 }
519
520 return valid_time;
521 }
522
523 // Function check start and end time at selected days.
524 function checkTimeInsideProcess( mytime, is_start_time, bk_type, my_dates_str ){
525 var i, h, s, m; // FixIn: 9.1.5.1.
526
527 var date_array = my_dates_str.split( ',' );
528 date_array = date_array.map( function (s) {
529 return s.trim();
530 } );
531 if ( date_array.length == 2 ){ // This recheck is need for editing booking, with single day
532 if ( date_array[ 0 ] == date_array[ 1 ] ){
533 date_array = [ date_array[ 0 ] ];
534 }
535 }
536
537 var temp_elemnt;
538 var td_class;
539 var sort_date_array = [];
540 var work_date_array = [];
541 var times_array = [];
542 var is_check_for_time;
543
544 for ( var i = 0; i < date_array.length; i++ ){ // Get SORTED selected days array
545 temp_elemnt = date_array[ i ].split( "." );
546 sort_date_array[ i ] = [ temp_elemnt[ 2 ], temp_elemnt[ 1 ] + '', temp_elemnt[ 0 ] + '' ]; // [2009,7,1],...
547 }
548 sort_date_array.sort(); // SORT D a t e s
549 for ( i = 0; i < sort_date_array.length; i++ ){ // trnasform to integers
550 sort_date_array[ i ] = [ parseInt( sort_date_array[ i ][ 0 ] * 1 ), parseInt( sort_date_array[ i ][ 1 ] * 1 ), parseInt( sort_date_array[ i ][ 2 ] * 1 ) ]; // [2009,7,1],...
551 }
552
553 if ( is_start_time ) {
554 if ( wpbc_is_time_in_the_past_for_today( mytime, sort_date_array, bk_type ) ) {
555 return false;
556 }
557 }
558
559 // CHECK FOR BOOKING INSIDE OF S E L E C T E D DAY RANGE AND FOR TOTALLY BOOKED DAYS AT THE START AND END OF RANGE
560 work_date_array = sort_date_array;
561 for ( var j = 0; j < work_date_array.length; j++ ){
562 td_class = work_date_array[ j ][ 1 ] + '-' + work_date_array[ j ][ 2 ] + '-' + work_date_array[ j ][ 0 ];
563
564 if ( (j == 0) || (j == (work_date_array.length - 1)) ) is_check_for_time = true; // Check for time only start and end time
565 else is_check_for_time = false;
566
567
568 } ///////////////////////////////////////////////////////////////////////////////////////////////////////
569
570
571 // Check START OR END time for time no in correct fee range
572 if ( is_start_time ) work_date_array = sort_date_array[ 0 ];
573 else work_date_array = sort_date_array[ sort_date_array.length - 1 ];
574
575 td_class = work_date_array[ 1 ] + '-' + work_date_array[ 2 ] + '-' + work_date_array[ 0 ];
576
577 // Get dates and time from pending dates
578 //deleted
579 // Get dates and time from pending dates
580 //deleted
581
582
583 times_array.sort(); // SORT TIMES
584
585 var times_in_day = []; // array with all times
586 var times_in_day_interval_marks = []; // array with time interval marks 1- stsrt time 2 - end time
587
588
589 for ( i = 0; i < times_array.length; i++ ){
590 s = times_array[ i ][ 2 ]; // s = 2 - end time, s = 1 - start time
591 // Start close interval
592 if ( (s == 2) && (i == 0) ){
593 times_in_day[ times_in_day.length ] = 0;
594 times_in_day_interval_marks[ times_in_day_interval_marks.length ] = 1;
595 }
596 // Normal
597 times_in_day[ times_in_day.length ] = times_array[ i ][ 0 ] * 60 + parseInt( times_array[ i ][ 1 ] );
598 times_in_day_interval_marks[ times_in_day_interval_marks.length ] = s;
599 // End close interval
600 if ( (s == 1) && (i == (times_array.length - 1)) ){
601 times_in_day[ times_in_day.length ] = (24 * 60);
602 times_in_day_interval_marks[ times_in_day_interval_marks.length ] = 2;
603 }
604 }
605
606 // Get time from entered time
607 var mytime_value = mytime.split( ":" );
608 mytime_value = mytime_value[ 0 ] * 60 + parseInt( mytime_value[ 1 ] );
609
610 //alert('My time:'+ mytime_value + ' List of times: '+ times_in_day + ' Saved indexes: ' + start_time_checking_index + ' Days: ' + sort_date_array ) ;
611
612 var start_i = 0;
613 if ( start_time_checking_index != undefined )
614 if ( start_time_checking_index[ 0 ] != undefined )
615 if ( (!is_start_time) && (sort_date_array.length == 1) ){
616 start_i = start_time_checking_index[ 0 ];
617 /*start_i++;*/
618 }
619 i = start_i;
620
621 // Main checking inside a day
622 for ( i = start_i; i < times_in_day.length; i++ ){
623 times_in_day[ i ] = parseInt( times_in_day[ i ] );
624 mytime_value = parseInt( mytime_value );
625 if ( is_start_time ){
626 if ( mytime_value > times_in_day[ i ] ){
627 // Its Ok, lets Loop to next item
628 } else if ( mytime_value == times_in_day[ i ] ){
629 if ( times_in_day_interval_marks[ i ] == 1 ){
630 return false; //start time is begin with some other interval
631 } else {
632 if ( (i + 1) <= (times_in_day.length - 1) ){
633 if ( times_in_day[ i + 1 ] <= mytime_value ) return false; //start time is begin with next elemnt interval
634 else { // start time from end of some other
635 if ( sort_date_array.length > 1 )
636 if ( (i + 1) <= (times_in_day.length - 1) ) return false; // Its mean that we make end booking at some other day then this and we have some booking time at this day after start booking - its wrong
637 start_time_checking_index = [ i, td_class, mytime_value ];
638 return true;
639 }
640 }
641 if ( sort_date_array.length > 1 )
642 if ( (i + 1) <= (times_in_day.length - 1) ) return false; // Its mean that we make end booking at some other day then this and we have some booking time at this day after start booking - its wrong
643 start_time_checking_index = [ i, td_class, mytime_value ];
644 return true; // start time from end of some other
645 }
646 } else if ( mytime_value < times_in_day[ i ] ){
647 if ( times_in_day_interval_marks[ i ] == 2 ){
648 return false; // start time inside of some interval
649 } else {
650 if ( sort_date_array.length > 1 )
651 if ( (i + 1) <= (times_in_day.length - 1) ) return false; // Its mean that we make end booking at some other day then this and we have some booking time at this day after start booking - its wrong
652 start_time_checking_index = [ i, td_class, mytime_value ];
653 return true;
654 }
655 }
656 } else {
657 if ( sort_date_array.length == 1 ){
658
659 if ( start_time_checking_index != undefined )
660 if ( start_time_checking_index[ 2 ] != undefined )
661
662 if ( (start_time_checking_index[ 2 ] == times_in_day[ i ]) && (times_in_day_interval_marks[ i ] == 2) ){ // Good, because start time = end of some other interval and we need to get next interval for current end time.
663 } else if ( times_in_day[ i ] < mytime_value ) return false; // some interval begins before end of curent "end time"
664 else {
665 if ( start_time_checking_index[ 2 ] >= mytime_value ) return false; // we are select only one day and end time is earlythe starttime its wrong
666 return true; // if we selected only one day so evrything is fine and end time no inside some other intervals
667 }
668 } else {
669 if ( times_in_day[ i ] < mytime_value ) return false; // Some other interval start before we make end time in the booking at the end day selection
670 else return true;
671 }
672
673 }
674 }
675
676 if ( is_start_time ) start_time_checking_index = [ i, td_class, mytime_value ];
677 else {
678 if ( start_time_checking_index != undefined )
679 if ( start_time_checking_index[ 2 ] != undefined )
680 if ( (sort_date_array.length == 1) && (start_time_checking_index[ 2 ] >= mytime_value) ) return false; // we are select only one day and end time is earlythe starttime its wrong
681 }
682 return true;
683 }
684