fix time calculation bug