Пример #1
0
 /**
  * Retrieve array of intervals
  *
  * @param string $from
  * @param string $to
  * @param string $period
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
 {
     $intervals = [];
     if (!$from && !$to) {
         return $intervals;
     }
     $dateStart = new \DateTime($from);
     $dateEnd = new \DateTime($to);
     while ($dateStart->diff($dateEnd)->invert = 0) {
         switch ($period) {
             case self::REPORT_PERIOD_TYPE_DAY:
                 $intervals[] = $dateStart->format('Y-m-d');
                 $dateStart->add(new \DateInterval('P1D'));
                 break;
             case self::REPORT_PERIOD_TYPE_MONTH:
                 $intervals[] = $dateStart->format('Y-m');
                 $dateStart->add(new \DateInterval('P1M'));
                 break;
             case self::REPORT_PERIOD_TYPE_YEAR:
                 $intervals[] = $dateStart->format('Y');
                 $dateStart->add(new \DateInterval('P1Y'));
                 break;
         }
     }
     return $intervals;
 }