prevent integer overflow in calculating duration