Calculating sleep time