src/mako/utility/Humanizer.php
public function time(DateTimeInterface $dateTime, string $dateFormat = 'Y-m-d, H:i', string $clockFormat = ', H:i'): string
	{
		$diff = time() - $dateTime->getTimestamp();

		if($diff < 0)
		{
			// Our date is in the future

			$diff = abs($diff);

			if($diff < 120)
			{
				return $this->i18n->get('humanizer.in_minute');
			}
			elseif($diff < 3600)
			{
				return $this->i18n->get('humanizer.in_minutes', [$diff / 60]);
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d'))
			{
				return $this->i18n->get('humanizer.today') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d', time() + (60 * 60 * 24)))
			{
				return $this->i18n->get('humanizer.tomorrow') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
		}
		else
		{
			// Our date is in the past

			if($diff < 120)
			{
				return $this->i18n->get('humanizer.minute_ago');
			}
			elseif($diff < 3600)
			{
				return $this->i18n->get('humanizer.minutes_ago', [$diff / 60]);
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d'))
			{
				return $this->i18n->get('humanizer.today') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d', time() - (60 * 60 * 24)))
			{
				return $this->i18n->get('humanizer.yesterday') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
		}

		// None of the above so just return the default date format

		return $dateTime->format($dateFormat);
	}
public function time(DateTimeInterface $dateTime, string $dateFormat = 'Y-m-d, H:i', string $clockFormat = ', H:i'): string
	{
		$diff = time() - $dateTime->getTimestamp();

		if($diff < 0)
		{
			// Our date is in the future

			$diff = abs($diff);

			if($diff < 120)
			{
				return $this->i18n->get('humanizer.in_minute');
			}
			elseif($diff < 3600)
			{
				return $this->i18n->get('humanizer.in_minutes', [$diff / 60]);
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d'))
			{
				return $this->i18n->get('humanizer.today') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d', time() + (60 * 60 * 24)))
			{
				return $this->i18n->get('humanizer.tomorrow') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
		}
		else
		{
			// Our date is in the past

			if($diff < 120)
			{
				return $this->i18n->get('humanizer.minute_ago');
			}
			elseif($diff < 3600)
			{
				return $this->i18n->get('humanizer.minutes_ago', [$diff / 60]);
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d'))
			{
				return $this->i18n->get('humanizer.today') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
			elseif($dateTime->format('Y-m-d') === date('Y-m-d', time() - (60 * 60 * 24)))
			{
				return $this->i18n->get('humanizer.yesterday') . (!empty($clockFormat) ? $dateTime->format($clockFormat) : '');
			}
		}

		// None of the above so just return the default date format

		return $dateTime->format($dateFormat);
	}
public function time ( DateTimeInterface $ dateTime , string $ dateFormat = 'Y-m-d, H:i' , string $ clockFormat = ', H:i' ) : string { $ diff = time ( ) - $ dateTime -> getTimestamp ( ) ; if ( $ diff < 0 ) { // Our date is in the future $ diff = abs ( $ diff ) ; if ( $ diff < 120 ) { return $ this -> i18n -> get ( 'humanizer.in_minute' ) ; } elseif ( $ diff < 3600 ) { return $ this -> i18n -> get ( 'humanizer.in_minutes' , [ $ diff / 60 ] ) ; } elseif ( $ dateTime -> format ( 'Y-m-d' ) === date ( 'Y-m-d' ) ) { return $ this -> i18n -> get ( 'humanizer.today' ) . ( ! empty ( $ clockFormat ) ? $ dateTime -> format ( $ clockFormat ) : '' ) ; } elseif ( $ dateTime -> format ( 'Y-m-d' ) === date ( 'Y-m-d' , time ( ) + ( 60 * 60 * 24 ) ) ) { return $ this -> i18n -> get ( 'humanizer.tomorrow' ) . ( ! empty ( $ clockFormat ) ? $ dateTime -> format ( $ clockFormat ) : '' ) ; } } else { // Our date is in the past if ( $ diff < 120 ) { return $ this -> i18n -> get ( 'humanizer.minute_ago' ) ; } elseif ( $ diff < 3600 ) { return $ this -> i18n -> get ( 'humanizer.minutes_ago' , [ $ diff / 60 ] ) ; } elseif ( $ dateTime -> format ( 'Y-m-d' ) === date ( 'Y-m-d' ) ) { return $ this -> i18n -> get ( 'humanizer.today' ) . ( ! empty ( $ clockFormat ) ? $ dateTime -> format ( $ clockFormat ) : '' ) ; } elseif ( $ dateTime -> format ( 'Y-m-d' ) === date ( 'Y-m-d' , time ( ) - ( 60 * 60 * 24 ) ) ) { return $ this -> i18n -> get ( 'humanizer.yesterday' ) . ( ! empty ( $ clockFormat ) ? $ dateTime -> format ( $ clockFormat ) : '' ) ; } } // None of the above so just return the default date format return $ dateTime -> format ( $ dateFormat ) ; }
Returns a human friendly representation of the time.

@param  \DateTimeInterface $dateTime    DateTime object
@param  string             $dateFormat  Default date format
@param  string             $clockFormat Default clock format
@return string
Returns a human friendly representation of the time .