Returns a fitting object (e.g. date or database object) if available.
@param $value
@return mixed The resulting object.
321678
function MapValue($value)
    {
        if ($value === null)
            return $value;
        
        if ($this->IsRelatedObject($value) || $this->IsDatabaseObject($value))
            return $value;
        
        else if (!is_object($value) && !is_array($value))
        {
            if ($this->relatedSchema)
                return $this->relatedSchema->CreateInstance($value);
            else
                return $this->type->FromDBString((string)$value);
        }

        //no more object types mappable.
        throw new \InvalidArgumentException('Invalid argument for fieldmapper. Object could not be mapped');
    }
536743
public static function VALUE($value = '')
    {
        $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);

        if (!is_numeric($value)) {
            $numberValue = str_replace(
                PHPExcel_Shared_String::getThousandsSeparator(),
                '',
                trim($value, " \t\n\r\0\x0B" . PHPExcel_Shared_String::getCurrencyCode())
            );
            if (is_numeric($numberValue)) {
                return (float) $numberValue;
            }

            $dateSetting = PHPExcel_Calculation_Functions::getReturnDateType();
            PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);

            if (strpos($value, ':') !== false) {
                $timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($value);
                if ($timeValue !== PHPExcel_Calculation_Functions::VALUE()) {
                    PHPExcel_Calculation_Functions::setReturnDateType($dateSetting);
                    return $timeValue;
                }
            }
            $dateValue = PHPExcel_Calculation_DateTime::DATEVALUE($value);
            if ($dateValue !== PHPExcel_Calculation_Functions::VALUE()) {
                PHPExcel_Calculation_Functions::setReturnDateType($dateSetting);
                return $dateValue;
            }
            PHPExcel_Calculation_Functions::setReturnDateType($dateSetting);

            return PHPExcel_Calculation_Functions::VALUE();
        }
        return (float) $value;
    }
273087
public static function getDateTime($value) : DateTimeInterface
    {
        $datetime  = false;
        $exception = null;

        if ($value instanceof DateTimeInterface) {
            return $value;
        } elseif ($value instanceof UTCDateTime) {
            $datetime = $value->toDateTime();
            $datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));
        } elseif (is_numeric($value)) {
            $value         = (float) $value;
            $seconds       = (int) $value;
            $microseconds  = abs(round($value - $seconds, 6));
            $microseconds *= 1000000;

            $datetime = static::craftDateTime($seconds, (int) $microseconds);
        } elseif (is_string($value)) {
            try {
                $datetime = new DateTime($value);
            } catch (Throwable $e) {
                $exception = $e;
            }
        }

        if ($datetime === false) {
            throw new InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"' . $value . '"' : gettype($value)), 0, $exception);
        }

        return $datetime;
    }
1146307
public function hydrate($value)
    {
        if ($value instanceof \stdClass) {
            $value = clone $value;
            foreach ($value as $name => $propertyValue) {
                $value->$name = $this->hydrate($propertyValue);
            }

            return $value;
        }

        if (is_array($value)) {
            return array_map(function ($itemValue) {
                return $this->hydrate($itemValue);
            }, $value);
        }

        if (is_string($value)) {
            if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(.*)$/', $value, $matches)) {
                if (strlen($matches[1]) === 0) {
                    return $this->dateTimeSerializer->deserialize($value, $this->dateSchema);
                }

                return $this->dateTimeSerializer->deserialize($value, $this->schema);
            }
        }

        return $value;
    }
629261
public function filter($value)
    {
	    if (is_string($value))
	        return new DateTime('@'.strtotime($value));
	    if ($value instanceof DateTime)
		    return $value;
	    if (is_int($value))
		    return new DateTime('@'.$value);
	    return null;
    }
945563
public function typeCast($value)
    {
        if ($value === null) {
            return $value;
        }
        
        switch ($this->type) {
            case 'string':
            case 'text':
            case 'binary':
            default:
                return $value;
            case 'integer':
                return $this->valueToInteger($value);
            case 'float':
                return (float)$value;
            case 'datetime':
            case 'timestamp':
                return $this->stringToTime($value);
            case 'time':
                return $this->stringToDummyTime($value);
            case 'date':
                return $this->valueToDate($value);
            case 'boolean':
                return $this->valueToBoolean($value);
            default:
                return $value;
        }
    }
479281
protected function valueRetriever($value)
    {
        if ($this->useAsCallable($value)) {
            return $value;
        }

        return function ($item) use ($value) {

            return ArrayHelper::dataGet($item, $value);
        };
    }
570158
public function stringify($value): string
    {
        if ($value instanceof \DateTimeInterface) {
            return $value->format('Y-m-d');
        }

        if (is_array($value)) {
            return self::ARRAY_VALUE;
        }

        if (is_object($value) && !method_exists($value, '__tostring')) {
            return self::OBJECT_VALUE;
        }

        return (string)$value;
    }
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;
    }
347890
private function getValue($value)
    {
        switch ($this->attributes['type']) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'collection':
                return new Collection(json_decode($value, true));
            case 'object':
                return json_decode($value);
            case 'array':
                return json_decode($value, true);
            default:
                return $value;
        }
    }
312598
protected function getDateTimestamp($value)
    {
        if ($value instanceof DateTimeInterface) {
            return $value->getTimestamp();
        }

        if ($this->isTestingRelativeDateTime($value)) {
            $date = $this->getDateTime($value);

            if (! is_null($date)) {
                return $date->getTimestamp();
            }
        }

        return strtotime($value);
    }
609888
protected function castValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        if ($this->isElementOfDate() && $this->isDateCastable()) {
            return $this->fromDateTime($value);
        }

        switch ($this->getCast()) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return $this->fromJson($value, true);
            case 'array':
            case 'json':
                return $this->fromJson($value);
            case 'collection':
                return new Collection($this->fromJson($value));
            case 'comma':
                return $this->fromCommaSeparated($value);
            default:
                return $value;
        }
    }
1373038
public function dbTypecastValue($value)
    {
        if ($value === null) {
            return null;
        }

        switch ($this->type) {
            case Schema::TYPE_BIT:
                return decbin($value);
            case Schema::TYPE_BINARY:
                return is_string($value) ? new PdoValue($value, \PDO::PARAM_LOB) : $value;
            case Schema::TYPE_TIMESTAMP:
            case Schema::TYPE_DATETIME:
                return \Yii::$app->formatter->asDatetime($value, 'yyyy-MM-dd HH:mm:ss');
            case Schema::TYPE_DATE:
                return \Yii::$app->formatter->asDate($value, 'yyyy-MM-dd');
            case Schema::TYPE_TIME:
                return \Yii::$app->formatter->asTime($value, 'HH:mm:ss');
            case Schema::TYPE_JSON:
                return new JsonExpression($value, $this->dbType);
            case Schema::TYPE_COMPOSITE:
                return new CompositeExpression($value, $this->dbType, $this);
        }

        return $this->typecast($value);
    }
564333
private function objectParam($value)
    {
        if ($value instanceof \stdClass) {
            throw new \InvalidArgumentException(
                'Values of type `\stdClass` are interpreted as structs and must define their types.'
            );
        }

        if ($value instanceof ValueInterface) {
            return [
                $this->typeObject($value->type()),
                $value->formatAsString()
            ];
        }

        if ($value instanceof Int64) {
            return [
                $this->typeObject(self::TYPE_INT64),
                $value->get()
            ];
        }

        throw new \InvalidArgumentException(sprintf(
            'Unrecognized value type %s. ' .
            'Please ensure you are using the latest version of google/cloud or google/cloud-spanner.',
            get_class($value)
        ));
    }
348198
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof Value) {
            throw new TransformationFailedException(
                sprintf('Expected a %s, got %s instead', Value::class, gettype($value))
            );
        }

        if (null === $value->date) {
            return null;
        }

        return $value->date->getTimestamp();
    }
155309
public function transform($value)
    {
        $parts = array(
            'date' => null,
            'time' => null,
        );
        if ( $value ) {
            $parts['date'] = new \DateTime($value->format('Y-m-d'));
            $parts['time'] = new \DateTime($value->format('H:i:s'));
        }
        return $parts;
    }
490700
public function filter($value) {
        if($value === null)
            return null;

        try {
            $sourceDT = new DateTime($value);
            $targetTZ = new DateTimeZone($this->options["timezone"] ? $this->options["timezone"] : date_default_timezone_get());
            $targetDT = $sourceDT;
            $targetDT->setTimeZone($targetTZ);

            return $targetDT->format($this->options["format"]);
        }
        catch(Exception $e) {
            return false;
        }
    }