fix a bug in Time API and add some tests