Input date

@param string $date
@param string $format
@return \DateTime
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;
    }
1025564
public static function formatDate($date, $format = 'Y-m-d')
    {
        if (!$date) {
            return null;
        }
        $date = new DateTime($date);
        return $date->format($format);
    }
1338805
public static function sql2date($date, $format = '%d/%m/%Y')
    {
        if (empty($date)) {
            return null;
        }
        $dt = new self();
        $dt->set_date($date);
        
        return $dt->format($format);
    }
640913
public function format($format)
    {
        try {
            return $this->getDateObject()->format($format);
        } catch (\Exception $e) {
            throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_FORMAT, [$format]);
        }
    }
197298
public static function toFormat($date, $format, $local = false)
    {
        if (is_string($date)) {
            $date = new static($date);
        }

        return $date->format($format, $local);
    }
336099
public static function format(
        UTCDateTime $date,
        string $format = 'd/m/Y H:i:s'
    ): string {
        return self::get($date)->format($format);
    }
34560
public function setPublishedTo( $date, $format = null )
    {
        $this->publishedTo = empty( $date ) ? null : $this->inputDate( $date, $format );
        return $this;
    }
677607
public static function date($format = "Y-m-d H:i:s", $time = null)
    {
        $time = ($time !== null ? $time : time());

        if (!is_numeric($time)) {
            $time = static::toUnix($time);
        }

        return date($format, $time);
    }
984912
public static function DateTime ($value, $format) {
		try {
			return (new \DateTime($value))->format($format) === $value;
		} catch (\Exception $e) {
			return false;
		}
	}
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
1261474
protected static function createDateTime(string $date, string $format = 'Y-m-d H:i:s'): \DateTime
    {
        return \DateTime::createFromFormat($format, $date);
    }
523241
public static function Validate($date, $format = DATEFORMAT::YMD, $separator = "/")
	{
		$timestamp = DateUtil::TimeStampFromStr($date, $format);
		$dateCheck = DateUtil::FormatDate($timestamp, $format, $separator, true);

		$date = $date . substr('--/--/---- 00:00:00', strlen($date));

		$timestamp2 = DateUtil::TimeStampFromStr($dateCheck, $format);
		return ($timestamp == $timestamp2) && ($date == $dateCheck);
	}
696386
public function format($date, $format = 'iso8601', $validate = true)
    {
        $result = null;
        try {
            if ($validate) {
                $format = $this->validateFormat($format);
            }
            $result = $this->parse($date)->format($format);
        } catch (\Exception $e) {
        }

        return $result;
    }
47769
protected function dateFormatter($dateTime, $format)
    {
        if (is_numeric($dateTime)) {
            return gmdate($format, (int) $dateTime);
        }

        if (is_string($dateTime)) {
            $dateTime = new \DateTime($dateTime);
        }

        if ($dateTime instanceof \DateTimeInterface) {
            static $utc;
            if (!$utc) {
                $utc = new \DateTimeZone('UTC');
            }
            return $dateTime->setTimezone($utc)->format($format);
        }

        throw new \InvalidArgumentException('Date/Time values must be either '
            . 'be a string, integer, or DateTime object');
    }
1061622
public function formatDateTime($date, $format = true)
    {
        $result = '';
        if (is_a($date, '\\DateTime')) {
            if ($format === true) {
                $format = $this->dateFormat;
                if (!$format) {
                    $formats = $this->getDefaultDateTimeFormats();
                    reset($formats);
                    $format = key($formats);
                }
            }
            $dh = Core::make('helper/date');
            /* @var $dh \Concrete\Core\Localization\Service\Date */
            switch ($format) {
                case ':shortDate:shortTime:':
                    $result = $dh->formatDateTime($date, false, false);
                    break;
                case ':shortDate:longTime:':
                    $result = $dh->formatDateTime($date, false, true);
                    break;
                case ':longDate:shortTime:':
                    $result = $dh->formatDateTime($date, true, false);
                    break;
                case ':longDate:longTime:':
                    $result = $dh->formatDateTime($date, true, true);
                    break;
                case ':shortDate:':
                    $result = $dh->formatDate($date, false);
                    break;
                case ':longDate:':
                    $result = $dh->formatDate($date, true);
                    break;
                case ':shortTime:':
                    $result = $dh->formatTime($date, false);
                    break;
                case ':longTime:':
                    $result = $dh->formatTime($date, true);
                    break;
                default:
                    $result = $dh->formatCustom($format, $date);
            }
        }

        return $result;
    }
947818
public static function date2str($date, $format = '%d/%m/%Y')
    {
        $dt = new self();
        if (!$dt->set_date($date)) {
            return '';
        }
        
        return $dt->format($format);
    }
80215
public static function fromString($date, $format = \DateTime::ATOM)
    {
        $dateTime = \DateTime::createFromFormat($format, $date);

        $err = \DateTime::getLastErrors();
        if ($err['error_count'] > 0) {
            throw new \InvalidArgumentException(sprintf('%s', implode(', ', $err['errors'])));
        }

        return self::fromDateTime($dateTime);
    }