Parse a value and a unit and returns the seconds (or an Error instance in case of errors).

@param int|mixed $value
@param int|mixed $unit
@param bool $required

@throws UserMessageException

@return int|null|Error
191545
public function joinTimeWindow($value, $unit, $required = false)
    {
        if (is_int($value)) {
            $v = $value;
        } elseif (is_string($value) && trim($value) !== '' && is_numeric(trim($value))) {
            $v = (int) $value;
        } else {
            $v = null;
        }
        if ($v === null) {
            if ($required) {
                throw new UserMessageException(t('The value of the time window is missing'));
            }
            $result = null;
        } elseif ($v <= 0) {
            throw new UserMessageException(t('The value of the time window must be greater than zero'));
        } else {
            if (is_int($unit)) {
                $u = $unit;
            } elseif (is_string($unit) && trim($unit) !== '' && is_numeric(trim($unit))) {
                $u = (int) $unit;
            } else {
                $u = null;
            }
            if ($u === null || !array_key_exists($u, $this->getTimeWindowUnits())) {
                throw new UserMessageException(t('The value of the time window units is not valid'));
            }
            $result = $u * $v;
            if (!is_int($result)) {
                throw new UserMessageException(t('The value of the time window units is too big'));
            }
        }

        return $result;
    }
147515
public function validate($value)
    {
        return is_bool($value) ? Ok::unit() : Error::unit([ Error::NON_BOOL ]);
    }
416095
public function validateUnit($type, $unit, $validUnits = null) {
        return ($this->findUnit($type, $unit, $validUnits) !== false);
    }
800069
public static function secondsTo($unit, $seconds)
    {
        $method = $unit.'ToSeconds';

        return  (float) $seconds / (float) self::$method();
    }
504201
public function convertTime(string $unit, float $value)
    {
        if ($unit === 'seconds') {
            return $value;
        }

        if ($unit === 'minutes') {
            return $value * (60);
        }

        if ($unit === 'hours') {
            return $value * (3600);
        }

        if ($unit === 'days') {
            return $value * (86400);
        }

        if ($unit === 'weeks') {
            return $value * (7 * 86400);
        }

        if ($unit === 'months') {
            return $value * (30 * 86400);
        }

        if ($unit === 'years') {
            return $value * (365 * 86400);
        }

        throw new \Exception('Wrong frequencies');
    }
346568
public function validateValue($value)
    {
        list($domain, $ip) = explode('/', $value, 2);
        if (($error = (new DomainValidator())->validateValue($domain)) !== null) {
            return $error;
        }
        if ($ip !== null && ($error = (new IpValidator())->validateValue($ip)) !== null) {
            return $error;
        }

        return null;
    }
878684
public static final TimeUnit parseWorkUnits(BigInteger value)
   {
      TimeUnit result = TimeUnit.HOURS;

      if (value != null)
      {
         switch (value.intValue())
         {
            case 1:
            {
               result = TimeUnit.MINUTES;
               break;
            }

            case 3:
            {
               result = TimeUnit.DAYS;
               break;
            }

            case 4:
            {
               result = TimeUnit.WEEKS;
               break;
            }

            case 5:
            {
               result = TimeUnit.MONTHS;
               break;
            }

            case 7:
            {
               result = TimeUnit.YEARS;
               break;
            }

            default:
            case 2:
            {
               result = TimeUnit.HOURS;
               break;
            }
         }
      }

      return (result);
   }
1300924
protected function _validate_timestamp($value, $parameters)
    {
        $timestamp = is_numeric($value) ? (int)$value : strtotime($value);
        if ($timestamp === false) {
            return null;
        }

        if (isset($parameters[0])) {
            if ($parameters[0] === 'start') {
                /** @noinspection SummerTimeUnsafeTimeManipulationInspection */
                return (int)($timestamp / 86400) * 86400;
            } elseif ($parameters[0] === 'end') {
                /** @noinspection SummerTimeUnsafeTimeManipulationInspection */
                return (int)($timestamp / 86400) * 86400 + 86399;
            } else {
                return strtotime(date($parameters[0], $timestamp));
            }
        }

        return $timestamp;
    }
126584
private static function _parseDateString($value)
    {
        $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d$/', $value);
        if ($result !== 1)
            return null;
        $timestamp = strtotime($value);
        if ($timestamp === false)
            return null;

        return $timestamp;
    }
234638
private static function fromInterval($value)
    {
        if (is_null($value)) {
            return null;
        }
        $res = preg_match(
            "/(?P<sign>\-)?(?:(?P<years>\d+) years? ?)?(?:(?P<months>\d+) mons? ?)?(?:(?P<days>\d+) days? ?)?" .
            "(?:(?P<h>\d+):(?P<m>\d+):(?P<s>\d+))?(?:\.(?P<ms>\d+))?/",
            $value,
            $match
        );
        if (!$res) {
            throw new Exception('Malformed interval');
        }
        $match += ['years' => 0, 'months' => 0, 'days' => 0, 'h' => 0, 'm' => 0, 's' => 0];

        $res = $match['years'] * 31557600
            + $match['months'] * 2592000
            + $match['days'] * 86400
            + $match['h'] * 3600
            + $match['m'] * 60
            + $match['s'];

        if (!empty($match['ms'])) {
            $res = floatval($res) + floatval($match['ms'] / intval('1' . str_repeat('0', strlen($match['ms']))));
        }

        if (isset($match['sign']) && $match['sign'] == '-') {
            $res *= -1;
        }

        return $res;
    }
378069
public function required($value)
    {
        if (!is_null($value) && $value !== '') {
            return $value;
        }

        throw new Exceptions\RequiredValueMissingException($this->v_type, $this->v_key);
    }
540973
protected function parseScope($value)
    {
        switch ($value) {
            case 'singleton':
                return Configuration::SCOPE_SINGLETON;
            case 'prototype':
                return Configuration::SCOPE_PROTOTYPE;
            case 'session':
                return Configuration::SCOPE_SESSION;
            default:
                throw new InvalidObjectConfigurationException('Invalid scope "' . $value . '"', 1167574991);
        }
    }
733751
private static function _parseDateTimeString($value)
    {
        $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d \d\d:\d\d:\d\d$/', $value);
        if ($result !== 1)
            return null;
        $timestamp = strtotime($value);
        if ($timestamp === false)
            return null;

        return $timestamp;
    }
1239243
protected function validator($value)
    {
        $convertValue = $this->widgetToValue($value);

        if ((null === $convertValue) && $this->mandatory) {
            $translator = $this->getEnvironment()->getTranslator();

            $message = empty($this->label)
                ? $translator->translate('ERR.mdtryNoLabel')
                : \sprintf(
                    $translator->translate('ERR.mandatory'),
                    $this->strLabel
                );

            $this->addError($message);
        }

        return $convertValue;
    }
1297323
public function marshal($value)
    {
        if ($value === null || $value === '') {
            return null;
        }
        if (is_string($value) && $this->_useLocaleParser) {
            return $this->_parseValue($value);
        }
        if (is_numeric($value)) {
            return (float)$value;
        }
        if (is_string($value) && preg_match('/^[0-9,. ]+$/', $value)) {
            return $value;
        }

        return null;
    }
1126306
public function validateRequired($value)
    {
        // Check for file!
        if (true === is_array($value) && true === array_key_exists('tmp_name', $value)) {
            // At least it was uploaded its valid in meaning of "required" <= NOT EMPTY
            $valid = ($value['error'] < UPLOAD_ERR_PARTIAL);
        } else {
            // Plain value ...
            $valid = (!is_null($value) && (is_array($value) || is_object($value) || (strlen($value) > 0)));
        }

        return $valid;
    }
462769
public function every($unit = null, $value = null): self
    {
        if (null === $unit || !isset($this->fieldsPosition[$unit])) {
            return $this;
        }

        $value = (1 === (int) $value) ? '*' : '*/' . $value;

        return $this->spliceIntoPosition($this->fieldsPosition[$unit], $value)
                    ->applyMask($unit);
    }