fixed the bug that calculates wrong time.

The test is not full and cannot detect this bug. So the test was
also fixed.