1
I’m working with a grouping of indefinite size of arrays, where each array (child) has another grouping of indefinite times (with initial and final times) for the execution of a given task, in the example below there are only two groupings of times for each child array, but within the execution of the system there may be several, both for the number of schedules, and for the number of tasks.
The problem is... How can I verify that these times coincide in a "simpler" way without having to abuse recursive and loop repetitions? because in this system no task can be executed while another one is running.
No schedule may be repeated, nor may it begin in the period of another set of times (initial and final time), and if there is at least one coincident time, the check may stop.
The rule between schedules is similar to a "human" "professional", which logically can not be in two places at the same time.
Basically the check should stop when: ($horario_inicial_atual >= $horario_inicial_anterior OR $horario_inicial_atual <= $horario_final_anterior) AND ($horario_final_atual >= $horario_inicial_anterior || $horario_final_atual <= $horario_final_anterior)
array(2) {
[0]=>
array(2) {
[0]=>
array(2) {
["initial"]=>
string(5) "08:00"
["final"]=>
string(5) "12:00"
}
[1]=>
array(2) {
["initial"]=>
string(5) "14:00"
["final"]=>
string(5) "18:00"
}
}
[1]=>
array(2) {
[0]=>
array(2) {
["initial"]=>
string(5) "08:00"
["final"]=>
string(5) "12:00"
}
[1]=>
array(2) {
["initial"]=>
string(5) "14:00"
["final"]=>
string(5) "18:00"
}
}
}
Note: If this previous list is too complicated to be worked for this check, this format can also be used:
array(4) {
[0]=>
array(2) {
["initial"]=>
string(5) "08:00"
["final"]=>
string(5) "12:00"
}
[1]=>
array(2) {
["initial"]=>
string(5) "14:00"
["final"]=>
string(5) "18:00"
}
[2]=>
array(2) {
["initial"]=>
string(5) "08:00"
["final"]=>
string(5) "12:00"
}
[3]=>
array(2) {
["initial"]=>
string(5) "14:00"
["final"]=>
string(5) "18:00"
}
}
Obs 2: In case there is no escape from loops, which would be the best practice?
Obs 3: I can modify the array anyway, because it is only for verification, then it is discarded.
Note 4: I just need to know if there are coincident times or not, without more details, the important thing is to know if it is true or false.
There won’t be much to escape from loops. Where does this data come from? Perhaps you can treat them on the database layer, making your life easier at the time of checking the conditions.
– jlHertel
It comes directly from a user-created "calendar", this verification must occur before being saved to the bank.
– Rafael Alexandre