Returns the start and end timestamps for the nth-previous period
since the current period. 0 will return the current period.

@param int $n

@return array period: [ start, end ]
489851
public function nthPreviousPeriod($n = 0)
    {
        $n = max(0, $n);

        // determine the interval string
        $interval = $this->interval($this->granularity());

        // calculate the start of the current period
        $start = $this->startOfDay(strtotime('this '.$interval));

        // go back N periods
        $i = $n;
        while ($i > 0) {
            $start = $this->startOfDay(strtotime('-1 '.$interval, $start));
            --$i;
        }

        // the end will be the start + 1 period - 1 second
        $end = $this->endOfDay(strtotime('+1 '.$interval, $start) - 1);

        return [
            'start' => $start,
            'end' => $end, ];
    }
1187033
public function skip($n)
    {
        $start = $this->currentPosition;

        $ret = @fseek($this->stream, $n, SEEK_CUR);
        if ($ret === -1) {
            return -1;
        }

        $this->currentPosition = ftell($this->stream);

        if ($start > $this->currentPosition) {
            $skipped = $start - $this->currentPosition;
        } else {
            $skipped = $this->currentPosition - $start;
        }

        return $skipped;
    }
714742
public function getDuration()
    {
        $start = $this->getStarted();

        if (empty($start)) {
            return 0;
        }

        $end = $this->getFinished();

        if (empty($end)) {
            $end = new \DateTime();
        }

        return $end->getTimestamp() - $start->getTimestamp();
    }
1352691
private function getTimePeriodField(): array
    {
        return [
            $this->translator->trans(/** @Desc("Last week") */ 'search.last_week', [], 'search') => 'P0Y0M7D',
            $this->translator->trans(/** @Desc("Last month") */ 'search.last_month', [], 'search') => 'P0Y1M0D',
            $this->translator->trans(/** @Desc("Last year") */ 'search.last_year', [], 'search') => 'P1Y0M0D',
            $this->translator->trans(/** @Desc("Custom range") */ 'search.custom_range', [], 'search') => 'custom_range',
        ];
    }
83276
public function getMonitorPeriod($name = null)
    {
        if ($name) {
            if (isset($this['monitor'], $this['monitor'][$name], $this['monitor'][$name]['period']) &&
                    strlen(trim($this['monitor'][$name]['period']))) {
                return $this['monitor'][$name]['period'];
            }
        }

        if (isset($this['monitor'], $this['monitor']['default'], $this['monitor']['default']['period']) &&
                strlen(trim($this['monitor']['default']['period']))) {
            return $this['monitor']['default']['period'];
        }

        return '25h';
    }
1119997
protected function get_next_range(\DateTimeImmutable $next) {

        $start = $next->getTimestamp();
        $end = $next->add($this->periodicity())->getTimestamp();
        return [
            'start' => $start,
            'end' => $end,
            'time' => $start
        ];
    }
996900
private function getCurrentTime()
    {
        list ($msec, $sec) = explode(" ", microtime());
        return (float)$msec + (float)$sec;
    }
1321532
public function getPeriods2()
  {
    $periods = array();

    $this->Period->byOrganizationWithYear($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function($Period) use (&$periods)
    {
      // array_push($periods, array('value'=> $Period->id, 'label' => $this->Lang->get('decima-accounting::period-management.' . $Period->month) . ' ' . $Period->year->year));
      array_push($periods, array('value'=> $Period->id, 'label' => $this->Lang->get('decima-accounting::period-management.' . $Period->month) . ' ' . $Period->year));
    });

    return $periods;
  }
497504
public function last($n = 1) {
		if ($this->_count - $n < 0) {
			return NULL;
		}
		return $this->_stack[$this->_count - $n];
	}
382858
public function getNextBytes($n)
	{
		$s = "";
		$nRem = $n;
		while ($nRem > 0)
		{
			if ($this->_outputPos == 64)
				$this->nextOutput();
			$nCopy = min(64 - $this->_outputPos, $nRem);
			$s .= substr($this->_output, $this->_outputPos, $nCopy);

			$nRem -= $nCopy;
			$this->_outputPos += $nCopy;
		}
		return $s;
	}
13415
public function getSigFigs($n)
    {
        $n = ltrim($n, '0+-');
        $dp = strpos($n, '.'); // decimal position
        if ($dp === false) {
            $sigfigs = strlen(rtrim($n, '0'));
        } else {
            $sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
            if ($dp !== 0) {
                $sigfigs--;
            }
        }
        return $sigfigs;
    }
643398
protected function num($n)
    {
        if (!is_numeric($n)) {
            return $n;
        }
        $broken_number = explode('.', (string)$n);
        if (isset($broken_number[1])) {
            return number_format($broken_number[0], 0, ',', '.').','.$broken_number[1];
        }
        return number_format($broken_number[0], 0, ',', '.');
    }
1175653
public function boundaries(): ?Period
    {
        $period = reset($this->intervals);
        if (false === $period) {
            return null;
        }

        return $period->merge(...$this->intervals);
    }
795893
public static function lastMonthRange()
    {
        $begin = mktime(0, 0, 0, date('m') - 1, 1, date('Y'));
        $end = mktime(23, 59, 59, date('m') - 1, date('t', $begin), date('Y'));

        return [$begin, $end];
    }
661945
public static function getCurrentTimestamp()
    {
        $database = self::getDatabase();
        $sql = 'SELECT CURRENT_TIMESTAMP';
        return $database->query($sql)->fetch(\PDO::FETCH_NUM)[0];
    }
884095
public function getNLastFiles($n)
    {
        $finder = new Finder();
        $finder->files()->name(
            $this->filter
        )->in(
            $this->mdPath
        )->sortByModifiedTimeDesc();
        return $finder->getNFirst($n);
    }
796622
public static function getPeriodToFrequency()
    {
        return array(
            Schedule::PERIOD_NEVER => Piwik::translate('General_Never'),
            Schedule::PERIOD_DAY   => Piwik::translate('General_Daily'),
            Schedule::PERIOD_WEEK  => Piwik::translate('General_Weekly'),
            Schedule::PERIOD_MONTH => Piwik::translate('General_Monthly'),
        );
    }