Calculating non-contiguous time periods