you do this check and extract a duration in two places. extract it to a common method/variable?