Add unit tests.

But we could be unlucky, right? before and after could be one millisecond away; in that case, the returned time would not match one of them.