Fix bug: duration was reversed

Calculate the duration using previous first, then current