Validate cron expression

@param $cronExpression
@return bool
494002
public function validateCronExpression($cronExpression)
    {
        try {
            $schedule = Mage::getModel('cron/schedule');
            /* @var $schedule Mage_Cron_Model_Schedule */
            $schedule->setCronExpr($cronExpression);
        } catch (Exception $e) {
            return false;
        }
        return true;
    }
34726
public function setCronExpr($expr)
    {
        if ($expr == 'always') {
            $this->setData('cron_expr', $expr);
        } else {
            parent::setCronExpr($expr);
        }
        return $this;
    }
286939
public static function validate($value)
    {
        if (!is_array($value)) {
            return false;
        }
        if (isset($value['from']) && IdentityValidator::validate($value['from']) === false) {
            return false;
        }
        if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
            return false;
        }
        if (!isset($value['topics']) || !is_array($value['topics'])) {
            return false;
        }
        foreach ($value['topics'] as $topic) {
            if (IdentityValidator::validate($topic) === false) {
                return false;
            }
        }
        if (!isset($value['payload'])) {
            return false;
        }
        if (HexValidator::validate($value['payload']) === false) {
            return false;
        }
        if (!isset($value['priority'])) {
            return false;
        }
        if (QuantityValidator::validate($value['priority']) === false) {
            return false;
        }
        if (!isset($value['ttl'])) {
            return false;
        }
        if (isset($value['ttl']) && QuantityValidator::validate($value['ttl']) === false) {
            return false;
        }
        return true;
    }
515744
public function getCron(string $alias): ?EdgarEzCron
    {
        if ($cron = $this->repository->getCron($alias)) {
            return $cron;
        }

        $crons = $this->getCrons();
        if (isset($crons[$alias])) {
            $cron = new EdgarEzCron();
            $cron->setAlias($alias);
            $cron->setExpression($crons[$alias]['expression']);
            $cron->setArguments($crons[$alias]['arguments']);
            $cron->setPriority($crons[$alias]['priority']);
            $cron->setEnabled($crons[$alias]['enabled']);

            return $cron;
        }

        return null;
    }
1259388
public function getCronLastExecution()
    {

        $date = $this->escapeHtml($this->helper->getDateLastCronRun('ddg_automation_importer'));

        if (! $date) {
            $date = '<span class="message message-error">No cron found</span>';
        }
        return $date;
    }
342050
public function checkCronJobsExists() {
		if ($this->isOsWindows()) {
			return true;
		}

		$apacheUser = $this->getWebSrvUser();
		if (empty($apacheUser)) {
			return false;
		}

		$cronjobsList = $this->_modelConfigInstaller->getListCronJobsCreation();
		if (empty($cronjobsList)) {
			return true;
		}

		$output = [];
		$exitCode = -1;
		$cmd = 'crontab -u ' . $apacheUser . ' -l 2>/dev/null';
		exec($cmd, $output, $exitCode);
		if ($exitCode !== 0) {
			return false;
		}

		if (empty($output)) {
			return false;
		}

		foreach ($cronjobsList as $cmd => $time) {
			if (empty($cmd)) {
				continue;
			}

			if (count(preg_grep('/^[^#]+' . preg_quote($cmd, '/') . '$/', $output)) == 0) {
				return false;
			}
		}

		return true;
	}
341197
public static function getRunDates($time, $count = 10)
    {
        try {
            $cron = CronExpression::factory($time);
            $dates = $cron->getMultipleRunDates($count);
        } catch (\Exception $e) {
            return array();
        }
        return $dates;
    }
882226
protected function cron_execute() {

        try {
            $this->restore_response();
            $previous = $this->recentresponse;
            $this->fetch();
            $this->restore_response(true);
            $current = $this->recentresponse;
            $changes = $this->compare_responses($previous, $current);
            $notifications = $this->cron_notifications($changes);
            $this->cron_notify($notifications);
            $this->cron_mtrace('done');
        } catch (checker_exception $e) {
            $this->cron_mtrace('FAILED!');
        }
    }
571383
func Cron(expression string) CronSchedule {
	expr := cronexpr.MustParse(expression)
	return CronSchedule{
		Expression: expr,
	}
}
670085
public function isBefore($index)
	    {
	        if ($index instanceof Period) {
	            return $this->end <= $index->start;
	        }

	        return $this->end <= self::validateDateTime($index);
	    }
1045138
public static function checkAndRunTasks($tasks)
    {
        $date = date('Y-m-d H:i:s');
        foreach ($tasks as $t) {
            /**
             * @var TaskInterface $t
             */
            if (TaskInterface::TASK_STATUS_ACTIVE != $t->getStatus()) {
                continue;
            }

            try {
                $cron = CronExpression::factory($t->getTime());

                if ($cron->isDue($date)) {
                    self::runTask($t);
                }
            } catch (\Exception $e) {
                echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
            }
        }
    }
347982
public function isValid()
    {
        $now = new \DateTime('now', new \DateTimeZone('UTC'));
        $timestamp = clone $this->timestamp;

        return $timestamp->add(new \DateInterval($this->validFor)) >= $now;
    }
1198988
public function isDue()
    {
        $expression = $this->getExpression();
        $cron = CronExpression::factory($expression);
        return $cron->isDue();
    }
775458
public function getScheduleDelay()
    {
        $value = $this->getSchedule();
        if (null === $value) {
            return -1;
        }

        $object = CronExpression::factory($value);

        $format = 'Y-m-d H:i:s';
        $timeFirst = strtotime($object->getNextRunDate()->format($format));
        $timeSecond = strtotime(date($format));

        return (int) $timeFirst - $timeSecond;
    }
512732
public function validateDni(ExecutionContextInterface $context)
    {
        $dni = $this->getDni();

        if(0 === preg_match('/^\d{8}[a-zA-Z]{1}$/', $dni) & 0 === preg_match('/^[XYZ]{1}\d{7}[a-zA-Z0-9]{1}$/', $dni) & 0 === preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $dni)  & strlen($dni)>0){
            $context->addViolationAt('dni', 'Formato incorrecto');
            return;
        }

        //DNI & NIE
        if(preg_match('/^\d{8}[a-zA-Z]{1}$/', $dni) || preg_match('/^[XYZ]{1}\d{7}[a-zA-Z0-9]{1}$/', $dni)){
            //Posibles valores para la letra final
            $letters = array(
                0 => 'T', 1 => 'R', 2 => 'W', 3 => 'A', 4 => 'G', 5 => 'M',
                6 => 'Y', 7 => 'F', 8 => 'P', 9 => 'D', 10 => 'X', 11 => 'B',
                12 => 'N', 13 => 'J', 14 => 'Z', 15 => 'S', 16 => 'Q', 17 => 'V',
                18 => 'H', 19 => 'L', 20 => 'C', 21 => 'K',22 => 'E'
            );

            //Comprobar si es un DNI
            if (preg_match('/^\d{8}[a-zA-Z]{1}$/', $dni))
            {
                if (strtoupper($dni[strlen($dni) - 1]) != $letters[((int) substr($dni, 0, strlen($dni) - 1)) % 23]){
                    $context->addViolationAt('dni', 'dni.invalid.number');
                    return;
                }
            }
            //Comprobar si es un NIE
            else if (preg_match('/^[XYZ]{1}\d{7}[a-zA-Z0-9]{1}$/', $dni))
            {
                //Comprobar letra
                if (strtoupper($dni[strlen($dni) - 1]) !=$letters[((int) substr($dni, 1, strlen($dni) - 2)) % 23]){
                    $context->addViolationAt('dni', 'nie.invalid.number');
                    return;
                }
            }
        }
        //CIF
        if(preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $dni)){
            $sum = 0;
            for ($i=2; $i<strlen($dni)-1; $i+=2) {
                $sum += substr($dni, $i, 1);
            }

            for ($i=1; $i<strlen($dni)-1; $i+=2) {
                $t = substr($dni, $i, 1) * 2;
                $sum += ($t>9)?($t-9):$t;
            }

            $control = 10 - ($sum % 10);

            if ( !(substr($dni, 8, 1) == $control || strtoupper(substr($dni, 8, 1)) == substr('JABCDEFGHI', $control, 1 ))){
                $context->addViolationAt('dni', 'cif.invalid');

                return;
            }
        }

    }
96512
private function validateRegex(): bool
    {
        $isValid = \preg_match($this->options['pattern'], $this->value) ? true : false;
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_REGEX_PATTERN_NOT_MATCH);
        }
        return $isValid;
    }
343398
public static CronConstraint ensureEitherDayOfYearOrMonth() {
        return new CronConstraint("Both, a day-of-year AND a day-of-month or day-of-week, are not supported.") {
            private static final long serialVersionUID = 520379111876897579L;

            @Override
            public boolean validate(Cron cron) {
                CronField dayOfYearField = cron.retrieve(CronFieldName.DAY_OF_YEAR);
                if (dayOfYearField != null && !(dayOfYearField.getExpression() instanceof QuestionMark)) {
                    return cron.retrieve(CronFieldName.DAY_OF_WEEK).getExpression() instanceof QuestionMark
                            && cron.retrieve(CronFieldName.DAY_OF_MONTH).getExpression() instanceof QuestionMark;
                }

                return true;
            }
        };
    }