can you please put in comments explaining what exactly is going on throughout, since this is very difficult to read and understand
For instasnce why the  (date.getMinutes() % 15) - 15 == -1 ? For what exact reason is this being done and then compared to 1?