Return value for a given period.

@param string $key Counter key.
@param \DatePeriod $period Date period.
@return \Krucas\Counter\Contracts\Value|array|null
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;
    }
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;
  }
1193835
public function queryTrimLog($period)
    {
        $qb = $this->createQueryBuilder();
        $qb->delete($this->getTableName())
             ->where('date < :date')
             ->setParameter('date', $period, Type::DATETIME);

        return $qb;
    }
245857
public function ordinal(string $key, string $period = null): string
    {
        $number = $this->$key;
        $result = $this->translate('ordinal', [
            ':number' => $number,
            ':period' => $period,
        ]);

        return strval($result === 'ordinal' ? $number : $result);
    }
223572
static function prevMonth($key = null) {
        $prev = self::todayIfNull(date('Y') . '-' . date('M') . '-01') - 24 * 3600;
        $ret  = [
            'y' => (int)date('Y', $prev),
            'm' => (int)date('m', $prev),
        ];
        return $key ? Arr::get($ret, $key) : $ret;
    }
1035553
public function periodByDateAndByOrganizationId($date, $organizationId, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }
    
    return $this->Period->setConnection($databaseConnectionName)
      ->where('start_date', '<=', $date)
      ->where('end_date', '>=', $date)
      ->whereNotIn('month', array(0,13))
      ->where('organization_id', '=', $organizationId)
      ->first();
  }
245945
public function period(string $period)
    {
        if (!in_array($period, Constants::PERIODS)) {
            throw new InvalidPeriodException('Request period is not valid. Valid values are defined in \Barryvanveen\Lastfm\Constants::PERIODS.');
        }

        $this->query = array_merge($this->query ?? [], ['period' => $period]);

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

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

            $values = array();

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

            return $values;
        }

        return new Exists(false);
    }
682101
public function getForRange($key, \DateTime $start, \DateTime $end)
    {
        if (!$this->hasForRange($key, $start, $end)) {
            return null;
        }

        return $this->data[$this->keyForRange($key, $start, $end)];
    }
1328211
public function sameValueAs(Period $period)
	    {
	        return $this->start == $period->start && $this->end == $period->end;
	    }
882639
public function get(int $offset): Period
    {
        $period = $this->intervals[$offset] ?? null;
        if (null !== $period) {
            return $period;
        }

        throw new InvalidIndex(sprintf('%s is an invalid offset in the current sequence', $offset));
    }
1254624
public function getDay(): Period
    {
        $datepoint = $this->setTime(0, 0);

        return new Period($datepoint, $datepoint->add(new DateInterval('P1D')));
    }
905678
public function indexOf(Period $interval)
    {
        foreach ($this->intervals as $offset => $period) {
            if ($period->equals($interval)) {
                return $offset;
            }
        }

        return false;
    }
1041969
public function plusPeriod(Period $period) : LocalDate
    {
        return $this
            ->plusYears($period->getYears())
            ->plusMonths($period->getMonths())
            ->plusDays($period->getDays());
    }
374617
public function getDateTime($key)
    {
        $value = $this->get($key);
        if ($value === null) {
            return null;
        }

        return new \DateTime($value);
    }
1302901
public function period($period)
    {
        if (in_array($period, $this->periods)) {
            $this->keys->visits = $this->keys->period($period);
        }

        return $this;
    }
1327782
public function plusPeriod(Period $period) : LocalDateTime
    {
        $date = $this->date->plusPeriod($period);

        if ($date === $this->date) {
            return $this;
        }

        return new LocalDateTime($date, $this->time);
    }