calculate period