public function humanize($date, $config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'format' => '%B %d %Y',
            'relative' => false,
            'offset' => null,
        ));

        $format = $config->format;

        $diff = $this->_current_time->getDate(DATE_FORMAT_UNIXTIME) - $date->getDate(DATE_FORMAT_UNIXTIME);

        if ($config->relative) {
            $timeLeft = ($diff < 0) ? '-FUTURE' : '';

            $diff = abs($diff);

            if ($diff < 1) {
                return sprintf(AnTranslator::_('LIB-AN-DATE-MOMENT'), $diff);
            }

            if ($diff < 60) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-SECONDS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-SECOND'.$timeLeft), $diff);
            }

            $diff = round($diff / 60);

            if ($diff < 60) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-MINUTES'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-MINUTE'.$timeLeft), $diff);
            }

            $diff = round($diff / 60);
            if ($diff < 24) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-HOURS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-HOUR'.$timeLeft), $diff);
            }

            $diff = round($diff / 24);
            if ($diff < 7) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-DAYS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-DAY'.$timeLeft), $diff);
            }

            $diff = round($diff / 7);

            if ($diff < 4) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-WEEKS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-WEEK'.$timeLeft), $diff);
            }
        } elseif ($config->offset) {
            $date->addHours($config->offset);
        }

        return $date->getDate($format);
    }
public function humanize($date, $config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'format' => '%B %d %Y',
            'relative' => false,
            'offset' => null,
        ));

        $format = $config->format;

        $diff = $this->_current_time->getDate(DATE_FORMAT_UNIXTIME) - $date->getDate(DATE_FORMAT_UNIXTIME);

        if ($config->relative) {
            $timeLeft = ($diff < 0) ? '-FUTURE' : '';

            $diff = abs($diff);

            if ($diff < 1) {
                return sprintf(AnTranslator::_('LIB-AN-DATE-MOMENT'), $diff);
            }

            if ($diff < 60) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-SECONDS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-SECOND'.$timeLeft), $diff);
            }

            $diff = round($diff / 60);

            if ($diff < 60) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-MINUTES'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-MINUTE'.$timeLeft), $diff);
            }

            $diff = round($diff / 60);
            if ($diff < 24) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-HOURS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-HOUR'.$timeLeft), $diff);
            }

            $diff = round($diff / 24);
            if ($diff < 7) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-DAYS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-DAY'.$timeLeft), $diff);
            }

            $diff = round($diff / 7);

            if ($diff < 4) {
                return ($diff > 1) ? sprintf(AnTranslator::_('LIB-AN-DATE-WEEKS'.$timeLeft), $diff) : sprintf(AnTranslator::_('LIB-AN-DATE-WEEK'.$timeLeft), $diff);
            }
        } elseif ($config->offset) {
            $date->addHours($config->offset);
        }

        return $date->getDate($format);
    }
public function humanize ( $ date , $ config = array ( ) ) { $ config = new AnConfig ( $ config ) ; $ config -> append ( array ( 'format' => '%B %d %Y' , 'relative' => false , 'offset' => null , ) ) ; $ format = $ config -> format ; $ diff = $ this -> _current_time -> getDate ( DATE_FORMAT_UNIXTIME ) - $ date -> getDate ( DATE_FORMAT_UNIXTIME ) ; if ( $ config -> relative ) { $ timeLeft = ( $ diff < 0 ) ? '-FUTURE' : '' ; $ diff = abs ( $ diff ) ; if ( $ diff < 1 ) { return sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-MOMENT' ) , $ diff ) ; } if ( $ diff < 60 ) { return ( $ diff > 1 ) ? sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-SECONDS' . $ timeLeft ) , $ diff ) : sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-SECOND' . $ timeLeft ) , $ diff ) ; } $ diff = round ( $ diff / 60 ) ; if ( $ diff < 60 ) { return ( $ diff > 1 ) ? sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-MINUTES' . $ timeLeft ) , $ diff ) : sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-MINUTE' . $ timeLeft ) , $ diff ) ; } $ diff = round ( $ diff / 60 ) ; if ( $ diff < 24 ) { return ( $ diff > 1 ) ? sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-HOURS' . $ timeLeft ) , $ diff ) : sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-HOUR' . $ timeLeft ) , $ diff ) ; } $ diff = round ( $ diff / 24 ) ; if ( $ diff < 7 ) { return ( $ diff > 1 ) ? sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-DAYS' . $ timeLeft ) , $ diff ) : sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-DAY' . $ timeLeft ) , $ diff ) ; } $ diff = round ( $ diff / 7 ) ; if ( $ diff < 4 ) { return ( $ diff > 1 ) ? sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-WEEKS' . $ timeLeft ) , $ diff ) : sprintf ( AnTranslator :: _ ( 'LIB-AN-DATE-WEEK' . $ timeLeft ) , $ diff ) ; } } elseif ( $ config -> offset ) { $ date -> addHours ( $ config -> offset ) ; } return $ date -> getDate ( $ format ) ; }
Return a human friendly format of the date.

@param AnDate $date
@param array $config Optional array to pass format

@return string
Return a human friendly format of the date .