<?php

function fn_ago_tc($aql)
{	
	$list = $aql->Consume(2);
	
	//print_r($list[0]);
	$duration = "s";
	$duration = $list[0]->value;
	
	//print_r($list[1]);
	$points = $list[1]->value;
	if (!is_array($points))
	{
		$points = array($points);
	}
	
	$ct = strtotime('now');
	
	foreach($points as $px)
	{
		$dt = strtotime($px->value);
		$diff = $ct - $dt;
		switch($duration)
		{
			case 'd':
				$px->value = $diff / (60*60*24);
				break;
			case 'h':
				$px->value = $diff / (60*60);
				break;
			case 'm':
				$px->value = $diff / 60;
				break;
			default:
				$px->value = $diff;
				break;
		}		
		$px->rawvalue = $px->value;
		$px->fullvalue = $px->value;		
		$px->type = "NUMBER";
		
	}
		
	array_push($aql->stack,$list[1]);
}

?>