So I have block time and appointment time let’s say block time is
JavaScript
x
$block_start = "13:00"
$block_end = "15:00"
and the appointment time is
JavaScript
$appointment_start = "14:00"
$appointment_end = "15:00"
now I want to check if the appointment time is between block time and vice versa
my current code
JavaScript
$start_time = strtotime($block_time->time_from);
$end_time = strtotime($block_time->time_to);
if ($timeSlot_From >= $start_time && $timeSlot_To <= $end_time) {
$staff_obj['between_block_time'] = TRUE;
}
other conditions
condition 1
if appointment time is
JavaScript
$appointment_start = 13:00
$appointment_end = 16:00
and block time is
JavaScript
$block_start = 14:00
$block_end = 15:00
then also it should not allow booking
condition 2
if block time is
JavaScript
$block_start = 13:00
$block_end = 16:00
and appointment time is
JavaScript
$appointment_start = 14:00
$appointment_end = 15:00
condition 3
if appointment time is 13:00-14:00 and block time is 14:00-15:00 then appointment booking is allowed
Advertisement
Answer
So 2 times won’t collide if one starts after the other one ends OR one ends before the other one starts.
Snippet:
JavaScript
<?php
function isNoCollision($t1s, $t1e, $t2s, $t2e){
$t1s = getTimeInSeconds($t1s);
$t1e = getTimeInSeconds($t1e);
$t2s = getTimeInSeconds($t2s);
$t2e = getTimeInSeconds($t2e);
return $t1e <= $t2s || $t1s >= $t2e;
}
So your driver code would be like:
JavaScript
<?php
if(isNoCollision(..)){
// do something
}else{
// do something else
}