public function initPeriods(array $periods, $type = DateIntervalsConsts::HOURS)
 {
     $periodsArr = [];
     foreach ($periods as &$period) {
         $period = (int) $period;
     }
     $uniquePeriods = array_unique($periods, SORT_NUMERIC);
     foreach ($uniquePeriods as $uniquePeriod) {
         $periodName = NumbersToWords::numberToNumberName($uniquePeriod);
         $name = "period" . ucfirst($periodName);
         ${$name} = new PeriodData();
         switch ($type) {
             case DateIntervalsConsts::HOURS:
                 ${$name}->setPeriod(new \DateInterval("PT" . ConvertTime::convertHoursToSeconds($uniquePeriod) . "S"));
                 break;
         }
         $periodsArr[] = ${$name};
     }
     return $periodsArr;
 }
 protected function calculateResidualPeriod(PeriodData $periodData, \DateInterval $leftover)
 {
     $currentPeriod = $periodData->getPeriod();
     $periodSeconds = ConvertTime::convertIntervalToSeconds($currentPeriod);
     $leftoverSeconds = ConvertTime::convertIntervalToSeconds($leftover);
     $diff = $periodSeconds - $leftoverSeconds;
     if ($diff < 0) {
         throw new OccurrencesException("Time is enough, residual period is not required.");
     }
     return new \DateInterval("PT" . $diff . "S");
 }