libmid: calculate time correctly