src/Utility/DTZone.php
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");
    }
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");
    }
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" ) ; }
Convert a given value to DateTime instance

@throws \InvalidArgumentException when cannot convert to \DateTime
@param mixed $value Value to convert (string, Time, DateTime, etc)
@param \DateTimeZone $dtz DateTimeZone instance
@return \DateTime
Convert a given value to DateTime instance