duration code with tests