creates representation of human readable date in the past

@param string $date
@param bool $html
@return String
515601
public function formatTimeAgoForHumans($date, $html = true)
    {
        $value = Carbon::createFromTimeStamp(strtotime($date))->diffForHumans();
        return ($html) ? $this->decorate($value, $date) : $value;
    }
156415
public function matchDate($date)
    {
        return $this->matchPart(
            $date,
        $this->formatRegex[$this->format][self::STRDATE]
        );
    }
1169297
public function date($date=null)
    {
        if(is_null($date)) {
            $date = $this->created_at;
        }
        return String::date($date);
    }
1222286
public function prettyDate($date, $format = null)
    {
        if (is_string($date)) {
            $date = new \DateTime($date);
        }

        if (null !== $format) {
            return $this->dateFormatter->prettyDate($date, $format);
        }

        return $this->dateFormatter->prettyDate($date);
    }
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) . ')';
	}
993587
public static function lastUpdated($date, $withTime = true): string
    {
        $objDate = self::parse($date);
        $date = self::parse($objDate)->format('Y-m-d');
        $days = self::parse(Date('Y-m-d'))->diffInDays(self::parse($date));

        if ($days == 0) {
            $msg = 'today';
        } elseif ($days == 1) {
            $msg = 'yesterday';
        } elseif ($days > 1 && $days < 7) {
            $msg = $objDate->format('l');
        } elseif ($days >= 7 && $days < 32) {
            $msg = $days . ' days ago';
            $withTime = false;
        } elseif ($days >= 32 && $days < 365) {
            $months = self::parse(Date('Y-m-d'))->diffInMonths($objDate);
            $msg = $months . (($months > 1) ? ' months ' : ' month ') . 'ago';
            $withTime = false;
        } else {
            $years = self::parse(Date('Y-m-d'))->diffInYears($objDate);
            $msg = $years . (($years > 1) ? ' years ' : ' year ') . 'ago';
            $withTime = false;
        }

        return ($withTime) ? $msg . ' at ' . $objDate->format('g:ia') : $msg;
    }
837196
public function datefromApi($date, $std = false) {
         $object = \DateTime::createFromFormat(API::API_DATE_FORMAT, $date);
      
          if ($std) {
            return getdate($object->getTimestamp());
          }

          return $object;
        }
1346450
public function textualDateFilter($date)
    {
        if ( ! $date instanceof \DateTime) {
            throw new \InvalidArgumentException('Textual Date Filter expects input to be a instance of DateTime');
        }

        $now  = new \DateTime('now');
        $diff = $now->diff($date);

        $diffUnit          = $this->getHighestDiffUnitAndValue($diff);
        $temporalModifier  = ($diff->invert)? 'ago':'next';
        $translationString = $temporalModifier. '.' .$diffUnit['unit'];

        // Override yesterday and tomorrow
        if ($diffUnit['unit'] == 'd' && $diffUnit['value'] == 1) {
            $translationString = ($diff->invert)? 'date.yesterday':'date.tomorrow';
        }

        // Override "just.now"
        if ($diffUnit['unit'] == 'now') {
            $translationString = 'date.just_now';
        }

        return $this->translator->transChoice($translationString, $diffUnit['value'], array('%value%' => $diffUnit['value']), 'date');
    }
1266620
public static function frenchDateToEnglish($date)
	{
		$date = mb_strtolower($date);
		$date = ucwords($date);

		$frenchDays  = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'];
		$englishDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
		$date        = str_replace($frenchDays, $englishDays, $date);

		$frenchMonths  = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
		$englishMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		$date          = str_replace($frenchMonths, $englishMonths, $date);

		return $date;
	}
79299
public function format(bool $date = true, bool $context = true) : string
    {
        $return = $context ? $this->context : [];

        $isAssociative = array_keys($return) !== range(0, count($return) - 1);
        if (!$isAssociative) {
            $return['Context'] = json_encode($return);
        }

        $return = ['Message' => $this->message] + $return;
        $return = $date ? (['Date' => $this->date->format('Y-m-d H:i:s')] + $return) : $return;

        return '[' .
            implode(
                '] [',
                array_map(
                    function (
                        $v,
                        $k
                    ) {
                        return sprintf(
                            '%s: %s',
                            ucfirst(strtolower((string) $k)),
                            is_array($v) ? json_encode($v) : $v
                        );
                    },
                    $return,
                    array_keys($return)
                )
            ) .
            ']';
    }
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');
    }
380021
public function date($date)
    {
        if (! $date instanceof DateTime) {
            $date = new DateTime($date);
        }

        $this->executionYear = $date->format('Y');

        return $this->at("{$date->format('i')} {$date->format('H')} {$date->format('d')} {$date->format('m')} *");
    }
811973
function (date) {
            var totalMonthDays = dp.getDaysCount(date),
                firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
                lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
                daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
                daysFromNextMonth = 6 - lastMonthDay + this.d.loc.firstDay;

            daysFromPevMonth = daysFromPevMonth < 0 ? daysFromPevMonth + 7 : daysFromPevMonth;
            daysFromNextMonth = daysFromNextMonth > 6 ? daysFromNextMonth - 7 : daysFromNextMonth;

            var startDayIndex = -daysFromPevMonth + 1,
                m, y,
                html = '';

            for (var i = startDayIndex, max = totalMonthDays + daysFromNextMonth; i <= max; i++) {
                y = date.getFullYear();
                m = date.getMonth();

                html += this._getDayHtml(new Date(y, m, i))
            }

            return html;
        }
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;
    }
1338813
private static function cast(Date $date = null)
	{
		if (!is_null($date))
		{
			$date = new DateTime($date);
		}

		return $date;
	}
166149
protected function date_format($date)
    {
        if (empty($date)) {
            return null;
        }

        if (!is_object($date) || !is_a($date, 'DateTime')) {
            try {
                $timestamp = rcube_utils::strtotime($date);
                $date      = new DateTime("@".$timestamp);
            }
            catch (Exception $e) {
                return null;
            }
        }

        return $date->format('d-M-Y H:i:s O');
    }
1057442
protected function normalizeDate($date)
    {
        $date = str_replace(array('/', '|'), '-', $date);

        if (empty($date)) {
            return date('Y-m-d H:i:s');
        } else if (ctype_digit($date)) {
            return date('Y-m-d H:i:s', $date);
        }

        return $date;
    }