Fixed time delay function and added test.

@campanawanna Can you check this and see if you think my change is correct and that the test is correct too. I'm not 100% confident that it is doing what I thought it should be doing.