calculate start and end period