I have 3 date / time input boxes on a form and the user cannot select any times within half an hour of each other.
I’ve converted all values to epoch format using a Javascript implementation of strtotime, but not sure how to recursively check that any of the times are actually half an hour apart.
I can hand code all checks, but it would be cleaner to write a recursive function (especially if there were theoretically more than 3 time slots).
Did some Google research but no luck.
Any suggestions on implementing this in Javascript or Jquery.
Thanks.
Sort the times, then look at adjacent members and check whether they’re within 30 minutes (1800 seconds) of each other.
EDIT: I hesitate to bother posting example code at all, but if your times are in an array named
times:times.sort(); for (i = 0; i < times.length-1, i++) { if (times[i+1] - times[i] < 1800) { return false; } return true; }