A method for calculating residence times