Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/util/date/helper.php
<?php

class AnUtilDateHelper extends KObject
{
	/**
	 * Load socialengine 
	 * @return 
	 */
	public function __construct()
	{
		KFactory::get('lib.joomla.language')->load( 'com_socialengine' );
	}
	
	/**
	 * Print a date in a human friendly way
	 * @return String
	 * @param $date AnUtilDate
	 * @param $options Object[optional]
	 */
	public function toString($date, $options=array())
	{
		$options  = array_merge(array('format'=>'%B %d %Y', 'relative'=>true), $options);
		$format   = $options['format'];
		$relative = $options['relative'];
		if ( $relative ) {
			$diff = KFactory::tmp('lib.anahita.type.date')->getDate(DATE_FORMAT_UNIXTIME) - $date->getDate(DATE_FORMAT_UNIXTIME);
			if ($diff < 1 )
				return sprintf(JText::_('AN-SE-DATE-MOMENT'), $diff);
				
			if ($diff < 60)
				return ( $diff > 1 ) ? sprintf(JText::_('AN-SE-DATE-SECONDS'), $diff) : sprintf(JText::_('AN-SE-DATE-SECOND'), $diff);
			
			$diff = round($diff/60);
			
			if ($diff<60)
				return ( $diff > 1 ) ? sprintf(JText::_('AN-SE-DATE-MINUTES'), $diff) : sprintf(JText::_('AN-SE-DATE-MINUTE'), $diff);
				
			$diff = round($diff/60);
			if ($diff<24)				
				return ( $diff > 1 ) ? sprintf(JText::_('AN-SE-DATE-HOURS'), $diff) : sprintf(JText::_('AN-SE-DATE-HOUR'), $diff);
				
			$diff = round($diff/24);
			if ($diff<7)
				return ( $diff > 1 ) ? sprintf(JText::_('AN-SE-DATE-DAYS'), $diff) : sprintf(JText::_('AN-SE-DATE-DAY'), $diff);
				
			$diff = round($diff/7);
			if ($diff<4)
				return ( $diff > 1 ) ? sprintf(JText::_('AN-SE-DATE-WEEKS'), $diff) : sprintf(JText::_('AN-SE-DATE-WEEK'), $diff);
				
			return $date->getDate($format);
		} else {
			return $date->getDate($format);
		}
		
	}
}
Return current item: Anahita Social Engine