Parse the given date and time into a DateTime object.

@param  DateTimeInterface|string $time A date/time string or a DateTime object.
@throws InvalidArgumentException If the date/time value is invalid.
@return DateTimeImmutable
425565
private function parseDateTime($time)
    {
        if (is_string($time)) {
            try {
                $time = new DateTimeImmutable($time);
            } catch (Exception $e) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid date/time value: %s',
                    $e->getMessage()
                ), $e->getCode(), $e);
            }
        }

        if ($time instanceof DateTime) {
            try {
                $time = DateTimeImmutable::createFromMutable($time);
            } catch (Exception $e) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid date/time value: %s',
                    $e->getMessage()
                ), $e->getCode(), $e);
            }
        }

        if ($time instanceof DateTimeImmutable) {
            $time = $time->setTimezone(static::$now->getTimezone());
        } else {
            throw new InvalidArgumentException('Invalid date/time for the presenter.');
        }

        return $time;
    }
1174025
protected static function expectDateTime($date)
    {
        if (!$date instanceof DateTime && !$date instanceof DateTimeInterface) {
            throw new InvalidArgumentException(
                'Expected null, string, DateTime or DateTimeInterface, '.
                (is_object($date) ? get_class($date) : gettype($date)).' given'
            );
        }
    }
113278
public static function createFromFormat($format, $time, $object = null)
    {
        if ($object !== null) {
            $dt = parent::createFromFormat($format, $time, $object);
        } else {
            $dt = parent::createFromFormat($format, $time);
        }

        $lastErrors = parent::getLastErrors();

        if ($dt instanceof \DateTimeInterface) {
            return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimezone());
        }

        throw new \InvalidArgumentException(implode(PHP_EOL, $lastErrors['errors']));
    }
1040939
public static function fromNative(DateTimeInterface $dateTime): DateTime
    {
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');
        $timezone = $dateTime->getTimezone();

        return new static(
            Date::create($year, $month, $day),
            Time::create($hour, $minute, $second),
            Timezone::create($timezone)
        );
    }
1159250
public static function parse($time = null, $timezone = null)
    {
        if ($time instanceof Carbon) {
            return new static(
                $time->toDateTimeString(),
                $timezone ?: $time->getTimezone()
            );
        }

        if (!is_int($time)) {
            $time = static::translateTimeString($time);
        }

        return new static($time, $timezone);
    }
623209
public function dateString(string $time): string
    {
        return date($this->dateFormat, ctype_digit($time) ? $time : strtotime($time));
    }
1280481
private static function getFixedImmutableTimeFromConfiguredTimestamp($time, $timeZone = null)
    {
        $date = new \DateTimeImmutable(sprintf('@%d', self::$timestamp));
        if ('now' !== $time) {
            $date = $date->modify($time);
        }
        if (null !== $timeZone) {
            $date = $date->setTimezone($timeZone);
        }

        if (false === $date) {
            throw new \RuntimeException('An error happened creating the immutable date');
        }

        return $date;
    }
935337
public static function newFromTimeString($timeString)
	{
        try {
    		$dateTime = new DateTime($timeString);
        } catch(\Exception $e) {
            throw new InvalidArgumentException('Time string must be valid, see DateTime for documentation');
        }
		return new self($dateTime->format('G'), $dateTime->format('i'));
	}
593137
public static function fromNativeDateTime(\DateTime $time)
    {
        $hour   = \intval($time->format('G'));
        $minute = \intval($time->format('i'));
        $second = \intval($time->format('s'));

        return static::fromNative($hour, $minute, $second);
    }
822998
private function getFormattedTimestamp($dateTime) {
    if (!is_object($dateTime)) {
      if (is_string($dateTime)) {
        $dateTime = new DateTime($dateTime);
      } else {
        throw new Exception("Invalid date value.");
      }
    } else {
      if (!($dateTime instanceof DateTime)) {
        throw new Exception("Invalid date value.");
      }
    }
    
    return $dateTime->format(DATE_ISO8601);  
  }
1274141
protected function normalizeDateTime($value)
    {
        try {
            if (is_int($value)) {
                //timestamp
                $value = new DateTime("@$value");
            } elseif (!$value instanceof DateTime) {
                $value = new DateTime($value);
            }
        } catch (\Exception $e) {
            throw new InvalidArgumentException('Invalid date string provided', $e->getCode(), $e);
        }

        return $value;
    }
63171
public static function parse($datetime, $timezone = null) {
        $monthName = array_map(function ($value) {
            return ' ' . $value . ' ';
        }, self::$monthYear);
        $monthValue = array_map(function ($value) {
            return '-' . $value . '-';
        }, range(1,12));
        $datetime = str_replace($monthName, $monthValue, $datetime);

        $parse = date_parse($datetime);
        if($parse['error_count'] == 0){
            list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
            list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);

            $timezone = self::createTimeZone($timezone);
            $datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
            return new static($datetime);
        }
        else{
            throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
        }
    }
202823
public function withTime(LocalTime $time) : LocalDateTime
    {
        if ($time->isEqualTo($this->time)) {
            return $this;
        }

        return new LocalDateTime($this->date, $time);
    }
105228
public function changeTime( Time $time )
      : DateTime
   {

      return $this->setTime( $time->getHour(), $time->getMinute(), $time->getSecond() );

   }
824373
private static function _createDateTime($time = null, $tz = null): \DateTimeImmutable
    {
        if (!isset($time)) {
            $time = 'now';
        }
        if (!isset($tz)) {
            $tz = date_default_timezone_get();
        }
        try {
            $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz));
            return self::_roundDownFractionalSeconds($dt);
        } catch (\Exception $e) {
            throw new \RuntimeException(
                "Failed to create DateTime: " .
                     self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
        }
    }
656745
public function addTime($time)
    {
        foreach ((array) $time as $value) {
            // only accept valid times (HH:mm)
            if ( ! preg_match('#([01][0-9]|2[0-3]):[0-5][0-9]#', $value)) {
                throw new InvalidArgumentException('Time must be valid: HH:mm.');
            }

            $this->times[] = $value;
        }

        return $this;
    }
52940
public function time($time)
    {
        if ($time instanceof Carbon) {
            $time = $time->timestamp;
        }

        $this->timestamp = $time;

        return $this;
    }