<commit_before><?php
/**
 * $Id$
 *
 * @author <NAME>, 2007-2008 <<EMAIL>>
 */

/**
 * Converts a SQL timestamp to a text string representing how long ago this timestamp occured
 *
 * @param $sql_time SQL timestamp
 * @return text string representing how long ago this timestamp occured
 */
function ago($sql_time)
{
	if (function_exists('agoOverride')) {
		return agoOverride($sql_time);
	}

	$old_time = strtotime($sql_time);
	$curr_time = time();

	if ($curr_time >= $old_time) {
		return shortTimePeriod($curr_time - $old_time).' ago';
	} else {
		return shortTimePeriod($old_time - $curr_time).' in the future';
	}
}

/**
 * Returns the age (in years)
 * Does not take into account timezone offset differences
 *
 * @param $sql_time sql timestamp representing day of birth
 * @return number of years old
 */
function age($sql_time)
{
	if (!$sql_time) return false;

	$age = date_diff($sql_time, 'now', 2, true);
	return $age['years'];
}

/**
 * Calculates difference between two dates
 *
 * @param $t1 oldest timestamp (or datetime)
 * @param $t2 newer timestamp (or datetime)
 * @param $precision how exact? (year,month,day,hour,minute,second)
 * @param $arr set to true to return result as a array with precision as index, default is text string
 */
function date_diff($t1, $t2, $precision = 6, $arr = false)
{
	if (preg_match('/\D/', $t1) && ($t1 = strtotime($t1)) === false) return false;
	if (preg_match('/\D/', $t2) && ($t2 = strtotime($t2)) === false) return false;

	if ($t1 > $t2) list($t1, $t2) = array($t2, $t1);

	$diffs = array(
		'year' => 0, 'month' => 0, 'day' => 0,<commit_msg>PHP 5.3 has built in function date_diff, this fixes a function name collision<commit_after><?php
/**
 * $Id$
 *
 * @author <NAME>, 2007-2008 <<EMAIL>>
 */

/**
 * Converts a SQL timestamp to a text string representing how long ago this timestamp occured
 *
 * @param $sql_time SQL timestamp
 * @return text string representing how long ago this timestamp occured
 */
function ago($sql_time)
{
	if (function_exists('agoOverride')) {
		return agoOverride($sql_time);
	}

	$old_time = strtotime($sql_time);
	$curr_time = time();

	if ($curr_time >= $old_time) {
		return shortTimePeriod($curr_time - $old_time).' ago';
	} else {
		return shortTimePeriod($old_time - $curr_time).' in the future';
	}
}

/**
 * Returns the age (in years)
 * Does not take into account timezone offset differences
 *
 * @param $sql_time sql timestamp representing day of birth
 * @return number of years old
 */
function age($sql_time)
{
	if (!$sql_time) return false;

	$age = date_diff2($sql_time, 'now', 2, true);
	return $age['years'];
}

/**
 * Calculates difference between two dates
 *
 * @param $t1 oldest timestamp (or datetime)
 * @param $t2 newer timestamp (or datetime)
 * @param $precision how exact? (year,month,day,hour,minute,second)
 * @param $arr set to true to return result as a array with precision as index, default is text string
 */
function date_diff2($t1, $t2, $precision = 6, $arr = false)
{
	if (preg_match('/\D/', $t1) && ($t1 = strtotime($t1)) === false) return false;
	if (preg_match('/\D/', $t2) && ($t2 = strtotime($t2)) === false) return false;

	if ($t1 > $t2) list($t1, $t2) = array($t2, $t1);

	$diffs = array(
		'year' => 0, 'month' => 0, 'day' => 0,
{'fraction_non_alphanumeric': 0.16053921568627452, 'fraction_numerical': 0.018995098039215685, 'mean_word_length': 4.2491961414791, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7650429', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1119, 'n_words': 365}