Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/type/date/date.php
<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Engine™
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.anahitapolis.com
 */

class AnTypeDate extends KDate implements AnDomainTypeInterface
{		
	/**
	 * Factory method
	 * 
	 * @param array $options
	 * @return AnTypeDate
	 */	
	static public function factory($options=array())
	{
		static $clone;
		
		if (!$clone )
			$clone	= new AnTypeDate();
		
		$default = array('date'=>gmdate( 'Y-m-d H:i:s' ));
		
		$options = array_merge($default, $options);
		
		$instance = clone $clone;
		
		$instance->setDate($options['date']);
		
		return $instance;
	}
	
	/**
	 * 
	 * @return 
	 * @param $options Object
	 */
    protected function _initialize(array $options)
    {
        $defaults = array(
            'date'  => gmdate( 'Y-m-d H:i:s' )
        );
		
        return array_merge($defaults, $options);
    }
	
	/**
	 * 
	 * @return 
	 * @param $date Object
	 * @param $format Object[optional]
	 */
	public function setDate($date, $format = DATE_FORMAT_ISO )
	{			
		if ( is_array($date) ) {			
			foreach($date as $key=>$value) {				
				$this->$key = $value;
			}			
		} else {
			parent::setDate($date, $format);	
		}
			
	}
	
	/**
	 * 
	 * @return 
	 * @param $date Object
	 */
	public function compare(KDate $date)
	{
		$thisTimestamp = $this->getTimestamp();
		$dateTimestamp = $date->getTimestamp();
		if ( $thisTimestamp == $dateTimestamp )
			return 0;
		else if ( $thisTimestamp < $dateTimestamp )
			return -1;
		else 
			return 1;
	}
	
	function modify($str) 
	{
		$date = clone $this;
		$date->setDate(strtotime($str, $this->getDate(DATE_FORMAT_UNIXTIME)));
		return $date;
	}
		
	/**
	 * 
	 * @return 
	 */
	public function __toString()
	{	
		return KFactory::get('lib.anahita.util.date.helper')->toString($this);
	}

	public function serialize()
	{
		return array('date' => $this->getDate('%Y-%m-%d %H:%M:%S'));
	}	
}
Return current item: Anahita Social Engine