@param string $date

@return \DateTimeImmutable|null
@throws \Exception
183710
public static function parseDateMDYReadable(string $date): ?\DateTimeImmutable
    {
        $date = str_replace('  ', ' ', $date);

        if (preg_match('~[a-zA-z]+ \d+, \d{4}~', $date)) {
            return new \DateTimeImmutable($date, new \DateTimeZone('UTC'));
        }

        return null;
    }
511482
protected function inputDate( $date, $format = null )
    {
        if ( ! $date instanceof DateTime )
        {
            if ( $date instanceof BaseDateTime )
            {
                $date = DateTime::createFromFormat(
                    DateTime::ISO8601,
                    $date->format( DateTime::ISO8601 )
                );
            }

            if ( is_int( $date ) )
            {
                $date = new DateTime( '@' . $date );
            }
            else if ( empty( $format ) )
            {
                $date = new DateTime( $date );
            }
            else
            {
                $date = DateTime::createFromFormat( $format, $date );
            }
        }

        return $date;
    }
75615
public static function modifyDate($date, array $params = [])
    {
        if (empty($date)) {
            return null;
        }
        $params['config'] = Helper::getValue($params['config'], []);
        if (!empty($params['locale'])) {
            $params['config']['locale'] = $params['locale'];
        }
        $dateTime = DateTime::set($date, null, $params['config']);
        if (isset($params['timezone'])) {
            $dateTime->convertTimezone($params['timezone']);
        }
        return $dateTime->format(Helper::getValue($params['format']));
    }
1147923
public static function freeze($date = null)
    {
        self::$freeze = false;
        self::$freezeDate = $date ? new DateTime($date) : self::now();
        self::$freeze = true;
    }
237060
final public static function asSql($date)
    {
        if (!empty($date)) {
            if ($date instanceof \DateTimeInterface) {
                return $date->format('Y-m-d H:i:sO');
            } else {
                return self::asDateTime($date)->format('Y-m-d H:i:sO');
            }
        } else {
            return null;
        }
    }
323899
public function getDate($date = null, $format = 'Y-m-d H:i:s')
    {
        if (strlen($date) < 0) {
            $date = date('d-m-Y H:i:s');
        }

        $timeStamp = new DateTime($date);
        return $timeStamp->format($format);
    }
295888
protected static function makeDate($date = null)
    {
        if (is_string($date)) {
            $date = new DateTime($date);
        } elseif (is_numeric($date)) {
            $date = new DateTime('@'.$date);
        }

        return self::isDate($date) ? $date : null;
    }
1070023
public function writeDate($date)
    {
        if ($this->writeObjectReference($date)) {
            return $this;
        }

        if ($date instanceof DateTime) {
            $dateString = $date->format('U') * 1000;
        } elseif ($date instanceof Zend_Date) {
            $dateString = $date->toString('U') * 1000;
        } else {
            require_once 'Zend/Amf/Exception.php';
            throw new Zend_Amf_Exception('Invalid date specified; must be a string DateTime or Zend_Date object');
        }

        $this->writeInteger(0x01);
        // write time to stream minus milliseconds
        $this->_stream->writeDouble($dateString);
        return $this;
    }
1178589
protected function getMongoIdFromDate($date)
	{
		static $inc = 0;
		if ($date instanceof \DateTime) {
			$timestamp = $date->getTimestamp();
		} else if (is_int($date)) {
			$timestamp = $date;
		} else {
			$timestamp = strtotime($date);
		}
		if (empty($timestamp)) {
			return null;
		}
		$ts = pack('N', $timestamp);
		$m = substr(md5(gethostname()), 0, 3);
		$pid = pack('n', posix_getpid());
		$trail = substr(pack('N', $inc++), 1, 3);
		$bin = sprintf('%s%s%s%s', $ts, $m, $pid, $trail);
		$id = '';
		for ($i = 0; $i < 12; $i++ ) {
			$id .= sprintf('%02x', ord($bin[$i]));
		}
		return new \MongoId($id);
	}
174504
public function getTargetFromDate($date)
    {
        if (!preg_match('/^\d{4,14}$/', $date)) {
            throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].');
        }

        // what we need to append to the date according to the possible date string lengths
        $dateStrlenToAppend = [
            14 => '',
            12 => '00',
            10 => '0000',
            8 => '000000',
            6 => '01000000',
            4 => '0101000000',
        ];

        if (!isset($dateStrlenToAppend[strlen($date)])) {
            throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].');
        }

        $target = $date . $dateStrlenToAppend[strlen($date)];

        $dateTime = \DateTime::createFromFormat('YmdHis', $target);

        if ($dateTime === false) {
            throw new \InvalidArgumentException('Invalid date. Format is YYYY[MM[DD[HH[II[SS]]]]].');
        }

        return $dateTime->format('YmdHis');
    }
734661
public static function formatDate($date)
    {
        $format = DateTime::ATOM;
        if ($date instanceof DateTime) {
            $d = $date->format($format);
        } elseif (is_numeric($date)) {
            $d = date($format, $date);
        } else {
            $d = (string) $date;
        }
        return $d;
    }
649239
public static function inFuture($date, $time = null)
    {
        if (is_null($time)) {
            $time = self::time();
        }
        if (!is_int($date)) {
            $date = self::strtotime($date);
        }

        return $time < $date;
    }
497613
public function getDateTime(string $date, string $pattern = "Y-m-d H:i:s")
    {
        if (!$date)
            $this->data = date($pattern);
        else
            $this->prepareDateTime($date);

        if($this->erro || !isset($this->data['ano']) || !isset($this->data['mes']) || !isset($this->data['dia'])) {
            return null;
        } else {
            $strtoTime = "";
            if (isset($this->data['h']) && $this->data['h'] > 11) {
                $this->data['h'] -= 12;
                $strtoTime = "+12hours";
            }

            $originalDate = $this->data['ano'] . '-' . $this->data['mes'] . '-' . $this->data['dia'] . " " . ($this->data['h'] ?? 0) . ":" . ($this->data['i'] ?? 0) . ":" . ($this->data['s'] ?? 0);
            return date($pattern, strtotime($originalDate . $strtoTime));
        }
    }
219998
private function parse($date, $timezone = null)
    {
        if (!($date instanceof \DateTime)) {
            if (false === strtotime($date)) {
                throw new \Exception('Invalid date not parsed.');
            }

            if (!$timezone) {
                $timezone = $this->timezoneSource;
            }

            $date = new \DateTime($date, new \DateTimeZone($timezone));
        }

        return $date;
    }
620986
protected function sanitizeDateForIntl($date)
    {
        if (!($date instanceof DateTime)) {
            return $date;
        }
        if (version_compare(phpversion(), '5.3.4', '<')) {
            return $date->getTimestamp();
        }

        return $date;
    }
535651
static protected function regex($date)
    {
      if(!preg_match('/^' . self::PATTERN . '$/', $date, $matches))
        throw new InvalidArgumentException(__METHOD__ . '; Invalid date, no match with pattern (' . $date . ')');
        
      return $matches;
    }
709889
protected function valueToDateTime($date)
    {
        if (!$date instanceof \DateTime) {
            $date = is_int($date) ? \DateTime::createFromFormat('U', $date) : new \DateTime((string)$date);
        }
        
        return $date;
    }