Struggling to develop a custom filter using Javascript, I aim to determine if two time ranges in millisecond getTime() format match. The first time range is retrieved from an object while the second comes from user input for filtering. Currently, my code checks if the second time range falls within the min and max values of the first time range. However, I want it to detect any overlap between the time ranges.
Javascript:
var filter_from = new Date();
filter_from.setHours(this.availability_from.split(/:/)[0]);
filter_from.setMinutes(this.availability_from.split(/:/)[1]);
filter_from = filter_from.getTime();
var filter_to = new Date();
filter_to.setHours(this.availability_from.split(/:/)[0]);
filter_to.setMinutes(this.availability_from.split(/:/)[1]);
filter_to = filter_to.getTime();
var a_from = new Date();
a_from.setHours((hits[i].availability.split("-")[0]).split(":")[0]);
a_from.setMinutes((hits[i].availability.split("-")[0]).split(":")[1]);
a_from = a_from.getTime();
var a_to = new Date();
a_to.setHours((hits[i].availability.split("-")[1]).split(":")[0])
a_to.setMinutes((hits[i].availability.split("-")[1]).split(":")[1])
a_to = a_to.getTime();
if (Math.min(filter_from, filter_to) <= Math.max(a_from, a_to) && Math.max(filter_from, filter_to) >= Math.min(a_from, a_to)) {
console.log("matched");
}
Would greatly appreciate any assistance with this perplexing challenge, thank you! :)