duration calculation