Home Refactor/Optimalization #1
This commit is contained in:
		@@ -43,12 +43,12 @@ class Utilities
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * [generateGraphJson description]
 | 
			
		||||
	 * @param  string $type    [line/bar]
 | 
			
		||||
	 * @param  array  $data    [description]
 | 
			
		||||
	 * @param  array  $options [description]
 | 
			
		||||
	 * @return [type]          [description]
 | 
			
		||||
	 */
 | 
			
		||||
	* [generateGraphJson description]
 | 
			
		||||
	* @param  string $type    [line/bar]
 | 
			
		||||
	* @param  array  $data    [description]
 | 
			
		||||
	* @param  array  $options [description]
 | 
			
		||||
	* @return [type]          [description]
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
	function generateGraphJson(string $type = 'line', array $data = [], array $options = []){
 | 
			
		||||
		$array = [
 | 
			
		||||
@@ -91,4 +91,20 @@ class Utilities
 | 
			
		||||
		];
 | 
			
		||||
		return json_encode($array, JSON_PRETTY_PRINT);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function ago( $datetime )
 | 
			
		||||
	{
 | 
			
		||||
		$interval = date_create('now')->diff( $datetime );
 | 
			
		||||
		$suffix = ( $interval->invert ? ' ago' : '' );
 | 
			
		||||
		if ( $v = $interval->y >= 1 ) return self::pluralize( $interval->m, 'month' ) . $suffix;
 | 
			
		||||
		if ( $v = $interval->d >= 1 ) return self::pluralize( $interval->d, 'day' ) . $suffix;
 | 
			
		||||
		if ( $v = $interval->h >= 1 ) return self::pluralize( $interval->h, 'hour' ) . $suffix;
 | 
			
		||||
		if ( $v = $interval->i >= 1 ) return self::pluralize( $interval->i, 'minute' ) . $suffix;
 | 
			
		||||
		return self::pluralize( $interval->s, 'second' ) . $suffix;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function pluralize( $count, $text )
 | 
			
		||||
	{
 | 
			
		||||
		return $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}s" ) );
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user