Attempts to convert an int, string, or array to a DateTime object.

@param  string|int|array $value

@return bool|\DateTime
183606
protected function convert_to_date_time( $value ) {

		if ( $value instanceof \DateTimeInterface ) {
			return $value;
		}

		switch ( gettype( $value ) ) {
			case 'string' :
				return $this->convert_string( $value );
			case 'integer' :
				return $this->convert_integer( $value );
			case 'double' :
				return $this->convert_double( $value );
			case 'array' :
				return $this->convert_array( $value );
		}

		$this->error_code = Error\ErrorLoggerInterface::INVALID_TYPE_NON_DATE;

		return FALSE;
	}
1191726
public function formatDatetime($value)
	{
		return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), $this->dateFormat, $this->timeFormat);
	}
878912
public function buildTime($value)
    {
        if ($value instanceof \DateTime) {
            return $value->format(static::TIME_FORMAT);
        } elseif (is_int($value)) {
            $date = new \DateTime();
            $date->setTimestamp($value);

            return $date->format(static::TIME_FORMAT);
        } elseif (is_string($value)) {
            $date = new \DateTime($value);

            return $date->format(static::TIME_FORMAT);
        }
        throw new \InvalidArgumentException('Time value should be int, string or \DateTime');
    }
476636
protected static function formatValue($value)
    {
        if ($value instanceof \DateTime) {
            $value = $value->format(\DateTime::ISO8601);
        } elseif (\is_bool($value)) {
            $value = $value ? 'True' : 'False';
        } elseif (\is_array($value) || $value instanceof \IteratorAggregate) {
            $itValue = $value instanceof \IteratorAggregate ? $value->getIterator() : $value;
            $value = [];
            foreach ($itValue as $key => $arrayValue) {
                $value[$key] = static::formatValue($arrayValue);
            }
            $value = implode("\n  ", $value);
        }

        return (string) $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;
    }
990936
public function filter($value)
    {
        if ($value instanceof \DateTime) {
            return $value;
        }
        
        try {
            $datetime = new \DateTime($value);
        } catch (\Exception $exception) {
            return false;
        }
        
        return $datetime;
    }
859334
private static function propertyToArrayValue($value)
    {
        if (is_subclass_of($value, '\DTS\eBaySDK\Types\BaseType', false)) {
            return $value->toArray();
        }
        else if ($value instanceof \DateTime) {
            return $value->format('Y-m-d\TH:i:s.000\Z');
        } else {
            return $value;
        }
    }
1153954
public static function convertToPhp($value)
    {
        if (!is_array($value)) {
            return [];
        }

        // see DateType::convertToPHPValue()
        $convertor = function ($value) {
            try {
                return DateType::getDateTime($value);
            } catch (\InvalidArgumentException $e) {
                return null;
            }
        };

        return array_values(array_filter(array_map($convertor, $value)));
    }
543314
protected function encodeDateTime(DateTime $value = null) {
        return null === $value ? "" : $value->format(self::DATETIME_FORMAT);
    }
838321
public static function createFromInput($value)
    {
        $timestamp = strtotime($value);

        try {
            // trim java ms
            $value = preg_replace('`(\\.[0-9]{3})\\+`', '+', $value);

            $datetime = self::createFromFormat(self::DATE_FORMAT, $value);

            if ($timestamp != $datetime->getTimestamp()) {
                throw new ResponseCode("Invalid datetime with value '$value'", 422);
            }
        } catch (\Exception $exception) {
            throw new ResponseCode("Invalid datetime format with value '$value'", 422);
        }

        return $datetime;
    }
426475
protected function asDateTime($value)
    {
        if ($value instanceof Carbon) {
            // If this value is already a Carbon instance, we shall just return it as is.
            // This prevents us having to re-instantiate a Carbon instance when we know
            // it already is one, which wouldn't be fulfilled by the DateTime check.
            $return = $value;
        } elseif ($value instanceof DateTimeInterface) {
            // If the value is already a DateTime instance, we will just skip the rest of
            // these checks since they will be a waste of time, and hinder performance
            // when checking the field. We will just return the DateTime right away.
            $return = new Carbon(
                $value->format('Y-m-d H:i:s.u'),
                $value->getTimezone()
            );
        } elseif (is_numeric($value)) {
            // If this value is an integer, we will assume it is a UNIX timestamp's value
            // and format a Carbon object from this timestamp. This allows flexibility
            // when defining your date fields as they might be UNIX timestamps here.
            $return = Carbon::createFromTimestamp($value);
        } elseif ($this->isStandardDateFormat($value)) {
            // If the value is in simply year, month, day format, we will instantiate the
            // Carbon instances from that format. Again, this provides for simple date
            // fields on the database, while still supporting Carbonized conversion.
            $return = Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
        } else {
            // Finally, we will just assume this date is in the format used by default on
            // the database connection and use that format to create the Carbon object
            // that is returned back out to the developers after we convert it here.
            if (preg_match('/\.u$/', $this->getDateFormat()) && !preg_match('/\.[0-9]+$/', $value)) {
                $value = $value.'.000';
            }
            $return = Carbon::createFromFormat($this->getDateFormat(), $value);
        }

        if (!$return->local) {
            // Adpat to local
            $return->setTimezone(\date_default_timezone_get());
        }
        return $return;
    }
613105
public static function parseValue($value)
    {
        if ($value instanceof DateTimeInterface) {
            $value = $value->format('Y-m-d H:i:s');
        } elseif ($value instanceof DateTimeProperty) {
            $value = $value->storageVal($value->val());
        } elseif (is_string($value)) {
            $str = strtolower($value);
            if ($str === 'true') {
                $value = true;
            } elseif ($str === 'false') {
                $value = false;
            }
        }

        return $value;
    }
394745
private function upgradeDate(&$value)
    {
        if ($value instanceof \DateTime) {
            return $value;
        }

        $value = \DateTime::createFromFormat('Y-m-d', $value);

        return $value;
    }
1043198
public function dateIs(\DateTime $value)
    {
        $this->add(new Criterium(self::CRITERIUM_DATE_IS, $value));

        return $this;
    }
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;
    }
1134925
public static function toDateTime($value, DateTimeZone $dtz) : DateTime
    {
        // TODO : Figure out where to move. Can vary for different source objects
        $format = 'Y-m-d H:i:s';

        if (is_string($value)) {
            $val = strtotime($value);
            if (false === $val) {
                throw new InvalidArgumentException(sprintf('Unsupported datetime string provided: %s', $value));
            }

            return new DateTime(date($format, $val), $dtz);
        }

        if ($value instanceof Time) {
            $value = $value->format($format);

            return new DateTime($value, $dtz);
        }

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

        throw new InvalidArgumentException("Type [" . gettype($value) . "] is not supported for date/time");
    }
1305362
public function convertToDate($value) {

		foreach($this -> date_formats as $format) {

			if(false !== \DateTime :: createFromFormat($format, $value)) {

				$d = new DateTime($value);
				$d -> createFromFormat($format, $value);

				if($d && $d -> format($format) == $value) {

					$d -> saveFormat($format);
					return $d;
				}
			}
		}

		return $value;
	}