Saves the Nth previous period. Creates the statistic entry
if it does not exist, otherwise overwrites the previous value.

@param int $n nth previous period to save

@return bool
327077
public function savePeriod($n = 1)
    {
        if (!$this->shouldBeCaptured() || $n < 1) {
            return false;
        }

        // compute the period in question
        $period = $this->nthPreviousPeriod($n);

        // compute the value for that time period
        $value = $this->computeValue($period);

        // generate the start date for the period
        $d = date('Y-m-d', $period[ 'start' ]);

        // save the value
        $stat = new Statistic([$this->key(), $d]);
        if (!$stat->exists()) {
            $stat = new Statistic();

            return $stat->create([
                'metric' => $this->key(),
                'day' => $d,
                'val' => $value, ]);
        } else {
            return $stat->set('val', $value);
        }
    }
1172323
public function save() {
        $this->invoke(self::BEFORE_SAVE, [$this]);
        if ($this->isNewRecord) {
            $row = $this->insert();
        } else {
            $row = $this->update();
        }
        $this->invoke(self::BEFORE_SAVE, [$this]);
        return $row;
    }
1064710
public function right($n)
    {
        if ($n < 0 || $n > $this->size()) {
            return new MString($this->text);
        }

        $pos = $n * -1;
        $result = substr($this->text, $pos);

        if ($result === false) {
            return null;
        }

        return new MString($result);
    }
965426
public static function createWithRecurrences(TimePoint $start, TimeInterval $interval, $recurrences, $options = 0)
    {
        $cur = $start;
        if ($options & DatePeriod::EXCLUDE_START_DATE) {
            $recurrences = $recurrences + 1;
        }
        for ($i = 0; $i < $recurrences; $i++) {
            $cur = $cur->add($interval);
        }
        return new self($start, $interval, $cur, $options);
    }
777506
public function save($trace = false)
    {
        $retval = false;

        if ($this->isNew() && !$this->contains('nb_catalog_item_order')) {
            $last_sibling_id = $this->db->getQueryAsSingleField(
                'nb_catalog_item_id',
                'SELECT nb_catalog_item_id
                   FROM nb_catalog_item
                  WHERE nb_catalog_id=%cat_id$d
                    AND nb_catalog_item_level=1
                    AND nb_catalog_item_next_sibling IS NULL',
                array(
                    'cat_id' => $this->getCatalogId()
                )
            );
            $next_order = $this->db->getQueryAsSingleField(
                'next_order',
                'SELECT ifnull(next_order, def) + 1 AS next_order
                   FROM (SELECT max(nb_catalog_item_order) AS next_order, def
                           FROM nb_catalog_item ci1
                          RIGHT OUTER JOIN (SELECT 0 AS def FROM dual) ci2
                             ON nb_catalog_id=%cat_id$d
                        ) AS t',
                array(
                    'cat_id' => $this->getCatalogId()
                )
            );
            $this->setOrder($next_order);
            if ($retval = parent::save($trace)) {
                if (is_numeric($last_sibling_id)) {
                    $this->db->executeUpdate(
                        'UPDATE nb_catalog_item ci
                            SET ci.nb_catalog_item_next_sibling = %next_sibling$d
                          WHERE ci.nb_catalog_item_id=%item_id$d',
                        array(
                            'item_id' => $last_sibling_id,
                            'next_sibling' => $next_order
                        ), true
                    );
                }
            }
        } else {
            $retval = parent::save($trace);
        }

        return $retval;
    }
169462
public function save() : bool
    {
        if (!$this->isTableNameSet()) {
            return false;
        }
        $pkName = $this->primaryKey;
        if ((int) $this->$pkName > 0) {
            $this->updateEntry();
        } else {
            $this->createEntry();
        }
        return true;
    }
946843
public function setN($n)
    {
        if (is_int($n) || (gettype($n) === 'string' && Format::isVariableRef($n))) {
            $this->n = $n;
        } else {
            $msg = "The n attribute must be an integer or a variable reference, '" . gettype($n) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
891689
public function doTransform($n = null)
    {
        // get the last Transformation Matrix
        $nb = count($this->_transf);
        if ($nb) {
            $m = $this->_transf[$nb-1];
        } else {
            $m = array(1,0,0,1,0,0);
        }

        // if no transform, get the Identity Matrix
        if (!$n) {
            $n = array(1,0,0,1,0,0);
        }

        // create the new Transformation Matrix
        $this->_transf[] = array(
            $m[0]*$n[0]+$m[2]*$n[1],
            $m[1]*$n[0]+$m[3]*$n[1],
            $m[0]*$n[2]+$m[2]*$n[3],
            $m[1]*$n[2]+$m[3]*$n[3],
            $m[0]*$n[4]+$m[2]*$n[5]+$m[4],
            $m[1]*$n[4]+$m[3]*$n[5]+$m[5]
        );
    }
192437
public function saveToFile($FileName = null)
    {
        if (! is_null($FileName)) {
            $this->FileName = $FileName;
        }

        if (($this->_openSHPFile(true)) && ($this->_openSHXFile(true)) && ($this->_createDBFFile())) {
            $this->_saveHeaders();
            $this->_saveRecords();
            $this->_closeSHPFile();
            $this->_closeSHXFile();
            $this->_closeDBFFile();
        } else {
            return false;
        }
    }
885844
public function fib($n)
    {
        if ($n < 3) return 1;
        $k = $n / 2;
        $a = $this->fib($k + 1);
        $b = $this->fib($k);
        if ($n % 2 == 1) {
            return $a * $a + $b * $b;
        } else {
            return $b * (2 * $a - $b);
        }
    }
1070146
public function advance($t, $n) {
        for ($i = 0; $i < $n; $i++) {
            $t = $this->next($t);
        }
        return $t;
    }
1233916
public function chop($n)
    {
        if ($n >= $this->size()) {
            $this->text = "";
            return;
        }

        $result = substr($this->text, 0, strlen($this->text) - $n);

        if ($result !== false) {
            $this->text = $result;
        }
    }
586014
public function resize($n)
    {
        return new self(function ($rng, $size) use ($n) {
            return $this->call($rng, $n);
        });
    }
1213660
public function skip(int $n): self
    {
        return new self(new Limit($this->getIterator(), $n), $this->type);
    }
365154
protected function beforeSave()
	{
		if(parent::beforeSave())
		{
			if($this->isNewRecord)
				$this->create_time=time();
			return true;
		}
		else
			return false;
	}
321295
public function leave(int $n = 1) : self
    {
        if ($n < 0) {
            throw new InvalidArgumentException('Cannot leave less than 0 samples.');
        }

        return $this->splice($n, $this->numRows());
    }
752219
public function protectedPrepMontgomery($x, $n)
    {
        $lhs = new BigInteger();
        $lhs->value = array_merge($this->protectedArrayRepeat(0, count($n)), $x);
        $rhs = new BigInteger();
        $rhs->value = $n;
        list ($temp) = $lhs->divide($rhs);
        return $temp->value;
    }