Caluclate sleep time correctly