@param string $date

@return null|string
971102
protected function getFormatedDate($date)
    {
        if (! is_null($date)) {
            if (! ($date instanceof Carbon)) {
                $date = Carbon::parse($date);
            }

            $date = $date->timezone($this->getTimezone())->format($this->getFormat());
        }

        return $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));
        }
    }
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
593443
protected function _date($date = null) {
		if ($date === null || !$date instanceof \DateTimeInterface) {
			return '';
		}
		$datePieces = [];
		$datePieces[] = $date->format('Y');
		// JavaScript uses 0-indexed months, so we need to subtract 1 month from PHP's output
		$datePieces[] = (int)($date->format('m')) - 1;
		$datePieces[] = (int)$date->format('d');
		$datePieces[] = (int)$date->format('H');
		$datePieces[] = (int)$date->format('i');
		$datePieces[] = (int)$date->format('s');

		return 'new Date(' . implode(', ', $datePieces) . ')';
	}
527298
public static function getDateTimeFromRfc($date) {

		// various date formats
		$formats = array(
				'RFC2822' => \DateTime::RFC2822,	// Fri, 06 Nov 2015 09:23:05 +0100
				'RFC2046' => 'D, d M Y H:i:s O T',	// Fri, 06 Nov 2015 09:23:05 +0100 (CET)
				'CUSTOM1' => 'D, j M Y H:i:s O',	// Fri, 6 Feb 2015 09:23:05 +0100
				'CUSTOM2' => 'd M Y H:i:s O',		// 06 Nov 2015 09:23:05 +0100
				'RSS2'    => 'D, d M Y H:i:s T');	// Tue, 10 May 2016 15:33:54 GMT
		
		// tries each date format
		foreach ($formats as $format) {

			$datetime = \DateTime::createFromFormat($format, $date, new \DateTimeZone(BASE_TIMEZONE));

			if (is_a($datetime, '\DateTime')) {
				return $datetime;
			}

		}

		return NULL;

	}
670964
public function getPostsByDate($date)
    {
        if (false === array_key_exists($date, $this->dateIndex)) {
            return [];
        }

        $postNames = $this->dateIndex[$date];

        return $this->getPostsByName($postNames);
    }
646222
public static function LocalDate2OLE($date = null)
	{
		if (!isset($date)) {
			return "\x00\x00\x00\x00\x00\x00\x00\x00";
		}

		// factor used for separating numbers into 4 bytes parts
		$factor = pow(2, 32);

		// days from 1-1-1601 until the beggining of UNIX era
		$days = 134774;
		// calculate seconds
		$big_date = $days*24*3600 + gmmktime(date("H",$date),date("i",$date),date("s",$date),
											 date("m",$date),date("d",$date),date("Y",$date));
		// multiply just to make MS happy
		$big_date *= 10000000;

		$high_part = floor($big_date / $factor);
		// lower 4 bytes
		$low_part = floor((($big_date / $factor) - $high_part) * $factor);

		// Make HEX string
		$res = '';

		for ($i = 0; $i < 4; ++$i) {
			$hex = $low_part % 0x100;
			$res .= pack('c', $hex);
			$low_part /= 0x100;
		}
		for ($i = 0; $i < 4; ++$i) {
			$hex = $high_part % 0x100;
			$res .= pack('c', $hex);
			$high_part /= 0x100;
		}
		return $res;
	}
1353977
public function getDate($date, string $pattern = "Y-m-d")
    {
        if (!$date) {
            $this->data['ano'] = date("Y");
            $this->data['mes'] = date("m");
            $this->data['dia'] = date("d");
        } else {
            $this->prepareDate($date);
        }

        if($this->erro) {
            return null;
        } else {
            $originalDate = $this->data['ano'] . '-' . $this->data['mes'] . '-' . $this->data['dia'];
            return date($pattern, strtotime($originalDate));
        }
    }
203428
public static function convertDate($date)
    {
        if (\is_int($date)) {
            $timestamp = $date;
        } else {
            $timestamp = \strtotime($date);
        }
        $string = \date('Y-m-d\TH:i:s\Z', $timestamp);

        return $string;
    }
1342484
public function toDateTime($date)
    {
        if ($date instanceof \DateTimeInterface) {
            return $date;
        }

        if (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $date)) {
            return \DateTime::createFromFormat('Y-m-d', $date);
        }

        return \DateTime::createFromFormat($this->db->getQuery(true)->getDateFormat(), $date);
    }
1025564
public static function formatDate($date, $format = 'Y-m-d')
    {
        if (!$date) {
            return null;
        }
        $date = new DateTime($date);
        return $date->format($format);
    }
563795
public function parse($date) {
        if(is_int($date) || is_double($date) || (is_string($date) && preg_match('@^[0-9]+$@', $date))) {
            return (double)$date;
        } elseif($date instanceof Date) {
            return $date->getEpoch();
        } elseif(is_null($date)) {
            return false;
        } else {
            $date = trim(Assert::isString($date));
        }
        $date = $this->parseHoursMinutes($date);
        if(preg_match('@^[0-9]+$@', $date)) {
            return (int)$date;
        }
        $date = $this->stripTimezone($date);
        $date = $this->stripRange($date);

        if(preg_match('@^(\d{4}-\d{2}-\d{2} )?24:00(:00)?$@', trim($date), $matches)) {
            if(isset($matches[1]) && strlen($matches[1]) > 0) {
                $date = strtotime($matches[1]);
            } else {
                $date = time();
            }
            return mktime(0, 0, 0, date('n', $date), date('j', $date) + 1, date('Y', $date));

        }
        //change a/p to am/pm
        $date = preg_replace('@(^|[^a-z])(a|p)([^a-z]|$)@i', '\\1\\2m\\3', $date);
        //Add a colon from 315am,1215 am
        $date = preg_replace('@(^|[^0-9])(\d{1,2})(\d{2})\s*(am|pm)@i', '\\1\\2:\\3\\4', $date);

        //Fix for dashes instead of slashes
        $date = preg_replace('@(\d{2})-(\d{2})-(\d{4})@', '\\1/\\2/\\3', $date);
        //Fix for dots instead of slashes
        $date = preg_replace('@(\d{2})\.(\d{2})\.(\d{4})@', '\\1/\\2/\\3', $date);

        //Fix for UK/euro Version
        if(in_array(Formatter::getDefault()->getDateFormat(), array(Formatter::DATE_FORMAT_UK, Formatter::DATE_FORMAT_EURO))) {
            //Switch the d/m/Y to the US format m/d/Y to be able to parse
            $date = preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\\2/\\1/\\3', $date);
        }
        switch(strtolower($date)) {
            case '9999-12-31':
                return 253402232400;
                break;
            case '0000-00-00':
                return 0;
                break;
            case '0000-00-00 00:00:00':
                return 0;
                break;
            case '24:00:00':
            case '24:00':
                return mktime(0, 0, 0, date('n'), date('j') + 1, date('Y'));
                break;
            case 'thanksgiving':
                $firstDay = mktime(0, 0, 0, 11, 1);
                $add = 26 - date('w', $firstDay);
                if($add < 22) {
                    $add += 7;
                }
                return mktime(0, 0, 0, 11, $add);
                break;
            default:
                return strtotime($date);
        }
    }
321237
public function compareDate($date = null)
    {
        $start    = $this->createDateUTC($this->toDateString());
        $end      = $this->createDateUTC($date ? $date->toDateString() : date(static::DATE_STR));
        $interval = $end->diff($start);

        return (int)($interval->format('%r') . (bool)$interval->format('%a'));
    }
299720
private function getTimeDrift(string $date) :? int
    {
        $now = new \DateTime();
        $now->format(\DateTime::RFC1123);

        try {
            $realDate = new DateTime($date);
        } catch (\Exception $e) {
            return null;
        }

        return (int)\abs($now->getTimestamp() - $realDate->getTimestamp());
    }
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;
    }
742471
public function guessDateFormat(string $date) : ? string
    {
        foreach ($this->dateFormats as $format) {
            $test = \DateTime::createFromFormat($format, $date);
            if ($test instanceof \DateTime) {
                $this->lastGuessedFormat = $format;

                return $format;
            }
        }

        return null;
    }
152185
protected function getLogOrFail($date)
    {
        $log = null;

        try {
            $log = $this->logViewer->get($date);
        }
        catch (LogNotFoundException $e) {
            abort(404, $e->getMessage());
        }

        return $log;
    }