The code demonstrates running program limitted time by following going over endtime expressed in seconds since midnight, so might fail for playing just midnight (add check that endtime is less than 24*60*60 if you want to be sure).
Exciting action :) of the program is that it shows remaining time in position moving left and right as you push left and right arrow keys.