Parses a source value as a boolean value.

@param mixed $value
@return DateTime|null
503506
protected function interpretAsDate($value)
    {
        if (null === $value || 0 === $value || '' === $value) {
            return null;
        }

        if ($value instanceof DateTime) {
            return $value;
        }

        if (is_string($value)) {
            return new Carbon($value);
        }

        if (is_numeric($value)) {
            return Carbon::createFromTimestamp($value);
        }

        throw new UnexpectedValueException("Expecting null or date");
    }
426571
protected function parseValue($value, $field = '')
    {
        unset($field);
        if (is_string($value)) {
            $value = strpos($value, ':') === 0 && $this->query->isBind(substr($value, 1)) ? $value : $this->connection->quote($value);
        } elseif (is_array($value)) {
            $value = array_map([$this, 'parseValue'], $value);
        } elseif (is_bool($value)) {
            $value = $value ? '1' : '0';
        } elseif (is_null($value)) {
            $value = 'null';
        }
        return $value;
    }
1307086
public function filterBoolean($value)
    {
        if ($value === null) {
            return null;
        }
        $booleanFormat = [
            $this->booleanFormat[0] => false, $this->booleanFormat[1] => true,
            'false'                 => false, 'true' => true,
            '0'                     => false, '1' => true,
            ''                      => false,
        ];
        $map = [];
        foreach ($booleanFormat as $label => $key) {
            $label = mb_strtolower($label, 'UTF-8');
            $map[$label] = $key;
            if (mb_strlen($label, 'UTF-8') > 1) {
                $map[mb_substr($label, 0, 1, 'UTF-8')] = $key;
            }
        }
        $value = mb_strtolower($value, 'UTF-8');

        return !isset($map[$value]) ? null : (int)$map[$value];
    }
1338494
protected function getBoolFromStringBool($value)
    {
        if (!($value == 'true' || $value == 'false')) {
            $this->throwException(sprintf('Expected "true" or "false" but got %s', $value));
        }

        return $value === 'true' ? true : false;
    }
948466
protected function interpretAsBoolean($value)
    {
        if (is_bool($value)) {
            return $value;
        }

        if (is_numeric($value)) {
            return $value != 0;
        }

        if (is_string($value)) {

            $value = trim($value);

            if ('' === $value || preg_match('#^n|no|f|false|nee|off|disabled|inactive&#', trim($value))) {
                return false;
            }

            return true;
        }

        if (is_array($value) || $value instanceof Collection) {
            return count($value) > 0;
        }

        return (bool) $value;
    }
108556
private function toDateTimeObject($value)
    {
        $datetime = null;
        
        switch (true) {
            case $value instanceof \DateTime:
                $datetime = new DateTime($value->format(\DateTime::RFC3339));
                break;
            case is_numeric($value):
                $datetime = new DateTime(sprintf('@%d', $value));
                break;
            case is_string($value):
                $datetime = new DateTime($value);
                break;
        }
        
        return $datetime;
    }
391452
protected static function parseValue($value)
    {
        if ($value instanceof \DateTime) {
            return 'new \\DateTime(' . \var_export($value->format('c'), true) . ')';
        }

        if (!\is_string($value)) {
            return \var_export($value, true);
        }

        if (\preg_match('/%([a-zA-Z0-9_:\\\]+)(?::(.*))?%/', $value, $matches)) {
            $function = $matches[1];

            if (!\function_exists($function)) {
                return $value;
            }

            if (!isset($matches[2])) {
                return $function . '()';
            }

            $args = \explode(',', $matches[2]);
            foreach ($args as &$a) {
                $a = static::parseConstant(\trim($a));
            }

            return $function . '(' . \implode(', ', $args) . ')';
        }

        return static::parseConstant($value);
    }
1352445
public static function toBoolean($value)
    {
        if (is_string($value)) {
            if ($value === 'true') {
                $value = true;
            } else {
                $value = false;
            }
        } elseif (is_bool($value) === false) {
            $value = false;
        }

        return $value;
    }
1198624
private static function _parseTwoDateTimeStrings($value)
    {
        $dateStrings = explode(',', $value);
        if (count($dateStrings) !== 2)
            return null;

        $timestamps = [];

        foreach ($dateStrings as $dateString) {
            $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d \d\d:\d\d:\d\d$/', $dateString);
            if ($result !== 1)
                return null;
            $timestamp = strtotime($dateString);
            if ($timestamp === false)
                return null;

            $timestamps[] = $timestamp;
        }
        return $timestamps;
    }
821699
private function getValue($value)
    {
        if ($value === null) {
            return null;
        }

        if ($value instanceof String_ || $value instanceof LNumber || $value instanceof DNumber) {
            return $value->value;
        } elseif ($value instanceof ConstFetch) {
            $value = (string)$value->name;
            if ($value === 'null') {
                return null;
            } elseif ($value === 'true') {
                return true;
            } elseif ($value === 'false') {
                return false;
            }

            return $value;
        } elseif ($value instanceof Array_) {
            return $this->getArray($value);
        }

        return null;
    }
1112871
public function getNodeByValue($value): ?Node {
        if (!$this->containsValue($value)) {
            return null;
        }
        $tmp = $this->getHead();
        while ($tmp !== null) {
            $val = $tmp->getValue();
            if (Comparator::equals($val, $value)) {
                //if the value is found then return it
                return $tmp;
            }
            $tmp = $tmp->getNext();
        }
        return null;
    }
1231895
protected function phpTypecastValue($value)
    {
        if ($value === null) {
            return null;
        }

        switch ($this->type) {
            case Schema::TYPE_BOOLEAN:
                switch (strtolower($value)) {
                    case 't':
                    case 'true':
                        return true;
                    case 'f':
                    case 'false':
                        return false;
                }
                return (bool) $value;
            case Schema::TYPE_BIT:
                return bindec($value);
            case Schema::TYPE_BINARY:
                return is_string($value) && strncmp($value, '\\x', 2) === 0 ? pack('H*', substr($value, 2)) : $value;
            case Schema::TYPE_JSON:
                return json_decode($value, true);
            case Schema::TYPE_TIMESTAMP:
            case Schema::TYPE_TIME:
            case Schema::TYPE_DATE:
            case Schema::TYPE_DATETIME:
                return new \DateTime($value);
            case Schema::TYPE_COMPOSITE:
                return $this->phpTypecastComposite($value);
        }

        return $this->typecast($value);
    }
962231
protected function valueBool($value)
	{
		if ($value !== false && empty($value)) return Yii::$app->formatter->nullDisplay;
		return Yii::$app->formatter->asBoolean($value);
	}
1183025
protected function _toBoolean($value)
    {
        $value = strtolower((string)$value);
        $result = ($value != 'false')
                && ($value != 'off')
                && !empty($value);

        return $result;
    }
629290
public static function canCastToDateTime($value)
    {
        if ($value instanceof \DateTime) {
            return true;
        } elseif (is_numeric($value)) {
            $value = (float)$value;
            return $value >= 0;
        } elseif (is_string($value)) {
            return $value !== '';
        } elseif (is_object($value)) {
            return method_exists($value, '__toString') && ((string)$value) !== '';
        }
        return false;
    }
588720
public static function castToDateTime($value)
    {
        if ($value instanceof \DateTime) {
            return clone $value;
        }
        if (is_numeric($value)) {
            $date = new \DateTime();
            $date->setTimestamp((int)$value);
        } elseif (is_string($value) || (is_object($value) && method_exists($value, '__toString'))) {
            $date = date_create((string)$value);
            if ($date === false) {
                $date = null;
            }
        } else {
            $date = null;
        }
        return $date;
    }
786816
public function isValueValidType($value)
    {
        switch ($this->getType()) {
            case self::TYPE_BOOLEAN:
                $isValid = is_bool($value);
                break;
            case self::TYPE_DATE:
            case self::TYPE_DATETIME:
                $isValid = is_object($value) and get_class($value) == 'DateTime';
                break;
            case self::TYPE_NUMBER:
                $isValid = is_numeric($value);
                break;
            case self::TYPE_STRING:
                $isValid = is_string($value);
                break;
            default:
                $isValid = false;
        }

        return $isValid;
    }