Clear deprecated records.

@param string $interval
@link https://www.php.net/manual/en/dateinterval.construct.php
177123
public function actionClearDeprecated($interval)
    {
        $ids = PushRecord::find()
            ->deprecated($interval)
            ->done()
            ->select('push.id')
            ->asArray()->column();
        $count = count($ids);
        if ($count && $this->confirm("Do you want to delete $count records?")) {
            $count = PushRecord::getDb()->transaction(function () use ($ids) {
                ExecRecord::deleteAll(['push_id' => $ids]);
                return PushRecord::deleteAll(['id' => $ids]);
            });
            $this->stdout("$count records deleted.\n");
        }
    }
1027827
final public static function intervalToSeconds($interval)
    {
        try {
            $start = new \DateTimeImmutable();
            $end = $start->add($interval);
            return $end->getTimestamp() - $start->getTimestamp();
        } catch (\Exception $e) {
            return 0;
        }

    }
1246472
private function dateIntervalToIntervalSpec(DateInterval $interval)
    {
        $date = sprintf('%uY%uM%uD', $interval->y, $interval->m, $interval->d);
        $time = sprintf('%uH%uM%uS', $interval->h, $interval->i, $interval->s);

        // build extra spec
        $extra = '';
        if ($interval->invert) {
            $extra .= 'I';
        }

        if ($interval->days) {
            $extra .= $interval->days . 'D';
        }

        if (strlen($extra) > 0) {
            $extra = '-' . $extra;
        }

        return sprintf('P%sT%s%s', $date, $time, $extra);
    }
209814
public static function intervalToTime(DateInterval $interval)
    {
        $time = null;

        if (!is_null($interval)) {
            $format = property_exists(get_class($interval), 'u') ? '%H:%I:%S.%U' : '%H:%I:%S';
            $time = $interval->format($format);
        }

        return $time;
    }
183247
public function setUpdateCheck($interval)
    {
        $validIntervals = [
            Checker::ALWAYS,
            Checker::DAILY,
            Checker::WEEKLY,
            Checker::MONTHLY,
            Checker::NEVER,
        ];

        if (!\in_array($interval, $validIntervals)) {
            throw new \InvalidArgumentException('invalid update check interval: ' . $interval);
        }

        $this->updateCheck = $interval;
    }
180814
public function clean()
    {
        $this->assertReady();
        
        $sql = sprintf("DELETE FROM %s WHERE %s < NOW() - INTERVAL %d SECOND",
            $this->dbAdapter->platform->quoteIdentifier($this->table),
            $this->dbAdapter->platform->quoteIdentifier($this->timestampColumn),
            $this->getCleanInterval()->toSeconds());
        
        $this->dbAdapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE);
    }
406704
public function findVisitsHours(Range $interval): ?Result
	{
		$diffBuilder = $this->builder()
			->select('DATEDIFF(MAX([datefield]), MIN([datefield])) diff')
			->andWhere('DATE([datefield]) BETWEEN DATE(%dt) AND DATE(%dt)', $interval->from, $interval->to);
		$diff = $this->execute($diffBuilder)->fetch();

		if ($diff && !empty($diff->diff)) {
			$diff = $diff->diff;
		} else {
			$diff = 1;
		}

		$builder = $this->builder()
			->select('HOUR([datefield]) hour, ROUND(SUM([visits]) / %i, 2) visits', $diff)
			->andWhere('DATE([datefield]) BETWEEN DATE(%dt) AND DATE(%dt)', $interval->from, $interval->to)
			->addGroupBy('[hour]');
		return $this->execute($builder);
	}
1000785
public static function getDateIntervalSpec(DateInterval $interval)
    {
        $date = array_filter([
            static::PERIOD_YEARS => abs($interval->y),
            static::PERIOD_MONTHS => abs($interval->m),
            static::PERIOD_DAYS => abs($interval->d),
        ]);

        $time = array_filter([
            static::PERIOD_HOURS => abs($interval->h),
            static::PERIOD_MINUTES => abs($interval->i),
            static::PERIOD_SECONDS => abs($interval->s),
        ]);

        $specString = static::PERIOD_PREFIX;

        foreach ($date as $key => $value) {
            $specString .= $value.$key;
        }

        if (count($time) > 0) {
            $specString .= static::PERIOD_TIME_PREFIX;
            foreach ($time as $key => $value) {
                $specString .= $value.$key;
            }
        }

        return $specString === static::PERIOD_PREFIX ? 'PT0S' : $specString;
    }
731474
public function remove(int $offset): Period
    {
        $interval = $this->get($offset);
        unset($this->intervals[$offset]);

        $this->intervals = array_values($this->intervals);

        return $interval;
    }
450344
protected function resolveBaseFormat(\DateInterval $interval): string
    {
        $format = '';

        if ($interval->y > 0) {
            $format .= '%yY';
        }

        if ($interval->m > 0) {
            $format .= '%mM';
        }

        if ($interval->d > 0) {
            $format .= '%dD';
        }

        return $format;
    }
1227191
public function add($interval) : self
    {
        $instance = clone $this;
        
        $instance->date->add(self::resolveDateInterval($interval));
        
        return $instance;
    }
450712
public function sub(\DateInterval $interval)
    {
        $this->startDate->sub($interval);
        $this->endDate->sub($interval);

        return $this;
    }
320660
public function push(Period $interval, Period ...$intervals): void
    {
        $this->intervals = array_merge($this->intervals, [$interval], $intervals);
    }
1155235
private function get_interval(string $interval = '')
  {
    if ( !empty($interval) ){
      $this->interval = new \DateInterval($interval);
      return $this->interval;
    }
    else {
      return $this->interval;
    }
  }
492953
public function equals(DateInterval $interval)
	{
		$years   = $this->y == $interval->y;
		$months  = $this->m == $interval->m;
		$days    = $this->d == $interval->d;
		$hours   = $this->h == $interval->h;
		$minutes = $this->i == $interval->i;
		$seconds = $this->s == $interval->s;
		$invert  = $this->invert == $interval->invert;

		return $years && $months && $days && $hours && $minutes && $seconds && $invert;
	}
636074
def _remove_boundaries(self, interval):
        
        begin = interval.begin
        end = interval.end
        if self.boundary_table[begin] == 1:
            del self.boundary_table[begin]
        else:
            self.boundary_table[begin] -= 1

        if self.boundary_table[end] == 1:
            del self.boundary_table[end]
        else:
            self.boundary_table[end] -= 1
11686
public function add(/*\DateInterval*/ $interval) : \DateTime /*self invariant*/
    {
        // NB: Argument type hinting (\DateInterval $interval)
        // would provoke E_WARNING when cloning.
        // Catch 22: Specs say that native \DateTime method is type hinted,
        // but warning when cloning says it isn't.

        if ($this->frozen) {
            throw new \RuntimeException(get_class($this) . ' is read-only, frozen.');
        }
        return parent::add($interval);
    }