@param $period

@return array
@throws Exception
324949
protected function parsePeriod($period)
    {
        if (false !== strpos($period, '-')) {
            return $this->parsePeriodFromDates($period);
        }

        return $this->parsePeriodFromName($period);
    }
544859
protected function parsePeriodFromName($period)
    {
        $min = null;
        $max = null;

        $date = new DateTime('today', $this->getTimezoneFrom());

        switch ($period) {
            case 'today' :
                $max = clone $date;
                $min = clone $date;
                break;

            case 'yesterday' :
                $max = clone $date->modify('-1 day');
                $min = clone $date;
                break;

            case 'tomorrow' :
                $max = clone $date->modify('+1 day');
                $min = clone $date;
                break;

            case 'thisMonth' :
                $max = clone $date->modify('last day of this month');
                $min = clone $date->modify('first day of this month');
                break;

            case 'thisMonthToDate' :
                $max = clone $date;
                $min = clone $date->modify('first day of this month');
                break;

            case 'thisWeek' :
                $max = clone $date->modify('sunday this week');
                $min = clone $date->modify("monday this week");
                break;

            case 'thisWeekToDate' :
                $max = clone $date;
                $min = clone $date->modify("monday this week");
                break;

            case 'thisYear' :
                $max = clone $date->modify('last day of december this year');
                $min = clone $date->modify('first day of january this year');
                break;

            case 'thisYearToDate' :
                $max = clone $date;
                $min = clone $date->modify('first day of january this year');
                break;

            case 'lastMonth' :
                $max = clone $date->modify('last day of last month');
                $min = clone $date->modify('first day of this month');
                break;

            case 'lastWeek' :
                $max = clone $date->modify('sunday last week');
                $min = clone $date->modify("monday this week");
                break;

            case 'lastYear' :
                $max = clone $date->modify('last day of december last year');
                $min = clone $date->modify('first day of january this year');
                break;

            case 'total' :
                break;

            case 'untilToday' :
                $max = clone $date;
                break;

            default :
                if (preg_match('/^last(\d+)(?:Days)?$/u', $period, $found)) {
                    $days = $found[1];
                    $max  = clone $date;
                    $min  = clone $date->modify("-{$days} day");
                } elseif (preg_match('/^(?:before|-)(\d+)(?:Days)?$/u', $period, $found)) {
                    $days = $found[1];
                    $min  = clone $date->modify("-{$days} day");
                    $max  = clone $date;
                } else {
                    throw new Exception("Period {$period} not supported");
                }
        }

        $result = [
            'min' => $min,
            'max' => $max,
        ];

        return $result;
    }
733450
public function plusPeriod(Period $period) : ZonedDateTime
    {
        return ZonedDateTime::of($this->localDateTime->plusPeriod($period), $this->timeZone);
    }
385099
public function equals(PeriodInterface $period)
    {
        return
            $period instanceof static &&
            $this->begin->format('Y-m-d-H-i-s') === $period->getBegin()->format('Y-m-d-H-i-s')
        ;
    }
1006427
private function serializeException(\Exception $exception)
    {
        return [
            'message' => $exception->getMessage(),
            'code' => $exception->getCode(),
            'trace' => $exception->getTrace(),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'previous' => null !== $exception->getPrevious() ? $this->serializeException($exception->getPrevious()) : null,
        ];
    }
1302901
public function period($period)
    {
        if (in_array($period, $this->periods)) {
            $this->keys->visits = $this->keys->period($period);
        }

        return $this;
    }
371327
public function ContextsContainDate( $date )
	{
		if ( is_string( $date ) )
			$date = DateTime::createFromFormat( "!Y-m-d", $date );

		if ( ! is_a( $date, 'DateTime' ) )
		{
			throw new Exception( 'Date parameter passes to ContextsFilter::ContextsContainDate is not a string or DateTime object' );
		}

		$filtered = array_filter( $this->contexts, function ( $context ) use( $date ) {
			// The context may be invalid in which case exclude
			if ( ! isset( $context['period'] ) || ! isset( $context['period']['startDate'] ) || ! isset( $context['period']['endDate'] ) ) return false;

			$startDate = DateTime::createFromFormat( "!Y-m-d", $context['period']['startDate'] );
			if ( ! $context['period']['is_instant'] && $startDate >= $date ) return false;

			$endDate   = DateTime::createFromFormat( "!Y-m-d", $context['period']['endDate'] );
			return $context['period']['is_instant'] ? $endDate == $date : $endDate >= $date;
		} );

		return new ContextsFilter( $this->instance, $filtered );
	}
312823
public function getTimeperiod()
    {
        foreach (array_keys(self::$time_periods) as $time_period) {
            if (!is_null($this->spans($time_period))) {
                return $time_period;
            }
        }

        return;
    }
170278
protected function getForPeriod($key, \DatePeriod $period)
    {
        $ranges = $this->getRanges($period);

        if (count($ranges) > 0) {
            if (count($ranges) == 1 && !($ranges[0] instanceof DateRange)) {
                return new DateValue($ranges[0], $this->repository->getFor($key, $ranges[0]));
            }

            $values = array();

            /** @var \Krucas\Counter\DateRange $range */
            foreach ($ranges as $range) {
                $values[] = new RangeValue(
                    $range,
                    $this->repository->getForRange($key, $range->getStartDate(), $range->getEndDate())
                );
            }

            return $values;
        }

        return null;
    }
1193353
private function getExceptionData($exception)
    {
        $data = [];

        $data['enviroment'] = env('APP_ENV');
        $data['host'] = Request::server('SERVER_NAME');
        $data['method'] = Request::method();
        $data['fullUrl'] = Request::fullUrl();
        $data['exception'] = $exception->getMessage();
        $data['error'] = $exception->getTraceAsString();
        $data['line'] = $exception->getLine();
        $data['file'] = $exception->getFile();
        $data['class'] = get_class($exception);
        $data['storage'] = [
            'SERVER' => Request::server(),
            'GET' => Request::query(),
            'POST' => $_POST,
            'FILE' => Request::file(),
            'OLD' => Request::hasSession() ? Request::old() : [],
            'COOKIE' => Request::cookie(),
            'SESSION' => Request::hasSession() ? Session::all() : [],
            'HEADERS' => Request::header(),
        ];

        $data['storage'] = array_filter($data['storage']);

        $count = $this->config['count'];
        $lines = file($data['file']);
        $data['exegutor'] = [];

        for ($i = -1 * abs($count); $i <= abs($count); $i++) {
            $data['exegutor'][] = $this->getLineInfo($lines, $data['line'], $i);
        }
        $data['exegutor'] = array_filter($data['exegutor']);

        // to make symfony exception more readable
        if ($data['class'] == 'Symfony\Component\Debug\Exception\FatalErrorException') {
            preg_match("~^(.+)' in ~", $data['exception'], $matches);
            if (isset($matches[1])) {
                $data['exception'] = $matches[1];
            }
        }

        return $data;
    }
154400
public function &get($idSite, $period)
    {
        if (!isset($this->data[$idSite][$period])) {
            $this->data[$idSite][$period] = $this->defaultRow;
        }
        return $this->data[$idSite][$period];
    }
23325
public static function getDatesForPeriod($period)
    {
        /*
         * Type of period is incorrect?
         * Nothing to do
         */
        if (!(new DatePeriod())->isCorrectType($period)) {
            return null;
        }

        $dateStart = null;
        $dateEnd = null;

        switch ($period) {
            case DatePeriod::LAST_WEEK:
                $thisWeekStart = new DateTime('this week');

                $dateStart = clone $thisWeekStart;
                $dateEnd = clone $thisWeekStart;

                $dateStart->sub(new DateInterval('P7D'));
                $dateEnd->sub(new DateInterval('P1D'));

                break;
            case DatePeriod::THIS_WEEK:
                $dateStart = new DateTime('this week');

                $dateEnd = clone $dateStart;
                $dateEnd->add(new DateInterval('P6D'));

                break;
            case DatePeriod::NEXT_WEEK:
                $dateStart = new DateTime('this week');
                $dateStart->add(new DateInterval('P7D'));

                $dateEnd = clone $dateStart;
                $dateEnd->add(new DateInterval('P6D'));

                break;
            case DatePeriod::LAST_MONTH:
                $dateStart = new DateTime('first day of last month');
                $dateEnd = new DateTime('last day of last month');

                break;
            case DatePeriod::THIS_MONTH:
                $lastMonth = self::getDatesForPeriod(DatePeriod::LAST_MONTH);
                $nextMonth = self::getDatesForPeriod(DatePeriod::NEXT_MONTH);

                if (null !== $lastMonth) {
                    $dateStart = $lastMonth->getEndDate();
                    $dateStart->add(new DateInterval('P1D'));
                }

                if (null !== $nextMonth) {
                    $dateEnd = $nextMonth->getStartDate();
                    $dateEnd->sub(new DateInterval('P1D'));
                }

                break;
            case DatePeriod::NEXT_MONTH:
                $dateStart = new DateTime('first day of next month');
                $dateEnd = new DateTime('last day of next month');

                break;
            case DatePeriod::LAST_YEAR:
            case DatePeriod::THIS_YEAR:
            case DatePeriod::NEXT_YEAR:
                $dateStart = new DateTime();
                $dateEnd = new DateTime();

                $yearPeriod = [
                    DatePeriod::LAST_YEAR,
                    DatePeriod::NEXT_YEAR,
                ];

                if (in_array($period, $yearPeriod, true)) {
                    $yearDifference = 1;

                    if (DatePeriod::LAST_YEAR === $period) {
                        $yearDifference *= -1;
                    }

                    $modifyString = sprintf('%s year', $yearDifference);
                    $dateStart->modify($modifyString);
                    $dateEnd->modify($modifyString);
                }

                $year = $dateStart->format('Y');
                $dateStart->setDate($year, 1, 1);
                $dateEnd->setDate($year, 12, 31);

                break;
        }

        /*
         * Start or end date is unknown?
         * Nothing to do
         */
        if (null === $dateStart || null === $dateEnd) {
            return null;
        }

        $dateStart->setTime(0, 0);
        $dateEnd->setTime(23, 59, 59);

        return new DatePeriod($dateStart, $dateEnd);
    }
158238
public function get_lists($timeperiod) {
        $lists = array();
        foreach ($this->get_all_lists() as $list) {
            $object = $this->get_list($list);
            if ($object->get_time_period() == $timeperiod) {
                $lists[] = $list;
            }
        }

        return $lists;
    }
447099
public function gap(Period $period)
	    {
	        if ($this->overlaps($period)) {
	            throw new LogicException('Both Period objects should not overlaps');
	        }

	        if ($period->start > $this->start) {
	            return new self($this->end, $period->start);
	        }

	        return new self($period->end, $this->start);
	    }
67399
public function includes(PeriodInterface $period, $strict = true)
    {
        if (true === $strict) {
            return $this->getBegin() <= $period->getBegin() && $this->getEnd() >= $period->getEnd();
        }

        return
            $this->includes($period, true) ||
            $period->includes($this, true) ||
            $this->contains($period->getBegin()) ||
            $this->contains($period->getEnd())
        ;
    }
760603
public function getPeriods()
  {
    $periods = array();

    $this->Period->byOrganization($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function($Period) use (&$periods)
    {
      array_push($periods, array('id'=> $Period->id, 'month' => $this->Lang->get('decima-accounting::period-management.' . $Period->month), 'startDate'=>$Period->start_date, 'endDate'=>$Period->end_date));
    });

    return $periods;
  }
952139
public function getExampleReport($idSite, $period, $date, $segment = false)
    {
        $table = DataTable::makeFromSimpleArray(array(
            array('label' => 'My Label 1', 'nb_visits' => '1'),
            array('label' => 'My Label 2', 'nb_visits' => '5'),
        ));

        return $table;
    }