Calculate sunrise, set times, twilights, wait for any such events, and poll whether it is day or night.