protected function _ago($timestamp, $current_time=null)
	{
		// Store the current time
		if (is_null($current_time))
		{
			// Get now
			$current_time = new self('now');
			$current_time = strtotime($current_time);
		}

		// Determine the difference, between the time now and the timestamp
		$difference = $current_time - $timestamp;

		// Set the periods of time
		$periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');

		// Set the number of seconds per period
		$lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);

		// Determine which period we should use, based on the number of seconds lapsed.
		// If the difference divided by the seconds is more than 1, we use that. Eg 1 year / 1 decade = 0.1, so we move on
		// Go from decades backwards to seconds
		for ($val = count($lengths) - 1; ($val >= 0) && (($number = $difference / $lengths[$val]) <= 1); $val--)
		{
			// Do nothing...
		}

		// Ensure the script has found a match
		if ($val < 0)
		{
			$val = 0;
		}

		// Determine the minor value, to recurse through
		$new_time = $current_time - ($difference % $lengths[$val]);

		// Set the current value to be floored
		$number = floor($number);

		// If required create a plural
		if ($number != 1)
		{
			$periods[$val] .= 's';
		}

		// Return text
		$text = sprintf("%d %s ", $number, $periods[$val]);

		// Ensure there is still something to recurse through, and we have not found 1 minute and 0 seconds.
		if (($val >= 1) && (($current_time - $new_time) > 0))
		{
			$text .= $this->_ago($new_time, $current_time);
		}

		return $text;
	}
protected function _ago($timestamp, $current_time=null)
	{
		// Store the current time
		if (is_null($current_time))
		{
			// Get now
			$current_time = new self('now');
			$current_time = strtotime($current_time);
		}

		// Determine the difference, between the time now and the timestamp
		$difference = $current_time - $timestamp;

		// Set the periods of time
		$periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');

		// Set the number of seconds per period
		$lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);

		// Determine which period we should use, based on the number of seconds lapsed.
		// If the difference divided by the seconds is more than 1, we use that. Eg 1 year / 1 decade = 0.1, so we move on
		// Go from decades backwards to seconds
		for ($val = count($lengths) - 1; ($val >= 0) && (($number = $difference / $lengths[$val]) <= 1); $val--)
		{
			// Do nothing...
		}

		// Ensure the script has found a match
		if ($val < 0)
		{
			$val = 0;
		}

		// Determine the minor value, to recurse through
		$new_time = $current_time - ($difference % $lengths[$val]);

		// Set the current value to be floored
		$number = floor($number);

		// If required create a plural
		if ($number != 1)
		{
			$periods[$val] .= 's';
		}

		// Return text
		$text = sprintf("%d %s ", $number, $periods[$val]);

		// Ensure there is still something to recurse through, and we have not found 1 minute and 0 seconds.
		if (($val >= 1) && (($current_time - $new_time) > 0))
		{
			$text .= $this->_ago($new_time, $current_time);
		}

		return $text;
	}
protected function _ago ( $ timestamp , $ current_time = null ) { // Store the current time if ( is_null ( $ current_time ) ) { // Get now $ current_time = new self ( 'now' ) ; $ current_time = strtotime ( $ current_time ) ; } // Determine the difference, between the time now and the timestamp $ difference = $ current_time - $ timestamp ; // Set the periods of time $ periods = array ( 'second' , 'minute' , 'hour' , 'day' , 'week' , 'month' , 'year' , 'decade' ) ; // Set the number of seconds per period $ lengths = array ( 1 , 60 , 3600 , 86400 , 604800 , 2630880 , 31570560 , 315705600 ) ; // Determine which period we should use, based on the number of seconds lapsed. // If the difference divided by the seconds is more than 1, we use that. Eg 1 year / 1 decade = 0.1, so we move on // Go from decades backwards to seconds for ( $ val = count ( $ lengths ) - 1 ; ( $ val >= 0 ) && ( ( $ number = $ difference / $ lengths [ $ val ] ) <= 1 ) ; $ val -- ) { // Do nothing... } // Ensure the script has found a match if ( $ val < 0 ) { $ val = 0 ; } // Determine the minor value, to recurse through $ new_time = $ current_time - ( $ difference % $ lengths [ $ val ] ) ; // Set the current value to be floored $ number = floor ( $ number ) ; // If required create a plural if ( $ number != 1 ) { $ periods [ $ val ] .= 's' ; } // Return text $ text = sprintf ( "%d %s " , $ number , $ periods [ $ val ] ) ; // Ensure there is still something to recurse through, and we have not found 1 minute and 0 seconds. if ( ( $ val >= 1 ) && ( ( $ current_time - $ new_time ) > 0 ) ) { $ text .= $ this -> _ago ( $ new_time , $ current_time ) ; } return $ text ; }
Calculate how long ago a date was

@param   number  $timestamp  Date to convert
@return  string
Calculate how long ago a date was