public function timeAgoInWords($dateTime, array $options = [])
    {
        $element = null;
        $options += [
            'element' => null,
            'timezone' => null
        ];
        $options['timezone'] = $this->_getTimezone($options['timezone']);
        if ($options['timezone']) {
            $dateTime = $dateTime->timezone($options['timezone']);
            unset($options['timezone']);
        }

        if (!empty($options['element'])) {
            $element = [
                'tag' => 'span',
                'class' => 'time-ago-in-words',
                'title' => $dateTime
            ];

            if (is_array($options['element'])) {
                $element = $options['element'] + $element;
            } else {
                $element['tag'] = $options['element'];
            }
            unset($options['element']);
        }
        $relativeDate = (new Time($dateTime))->timeAgoInWords($options);

        if ($element) {
            $relativeDate = sprintf(
                '<%s%s>%s</%s>',
                $element['tag'],
                $this->templater()->formatAttributes($element, ['tag']),
                $relativeDate,
                $element['tag']
            );
        }

        return $relativeDate;
    }
public function timeAgoInWords($dateTime, array $options = [])
    {
        $element = null;
        $options += [
            'element' => null,
            'timezone' => null
        ];
        $options['timezone'] = $this->_getTimezone($options['timezone']);
        if ($options['timezone']) {
            $dateTime = $dateTime->timezone($options['timezone']);
            unset($options['timezone']);
        }

        if (!empty($options['element'])) {
            $element = [
                'tag' => 'span',
                'class' => 'time-ago-in-words',
                'title' => $dateTime
            ];

            if (is_array($options['element'])) {
                $element = $options['element'] + $element;
            } else {
                $element['tag'] = $options['element'];
            }
            unset($options['element']);
        }
        $relativeDate = (new Time($dateTime))->timeAgoInWords($options);

        if ($element) {
            $relativeDate = sprintf(
                '<%s%s>%s</%s>',
                $element['tag'],
                $this->templater()->formatAttributes($element, ['tag']),
                $relativeDate,
                $element['tag']
            );
        }

        return $relativeDate;
    }
public function timeAgoInWords ( $ dateTime , array $ options = [ ] ) { $ element = null ; $ options += [ 'element' => null , 'timezone' => null ] ; $ options [ 'timezone' ] = $ this -> _getTimezone ( $ options [ 'timezone' ] ) ; if ( $ options [ 'timezone' ] ) { $ dateTime = $ dateTime -> timezone ( $ options [ 'timezone' ] ) ; unset ( $ options [ 'timezone' ] ) ; } if ( ! empty ( $ options [ 'element' ] ) ) { $ element = [ 'tag' => 'span' , 'class' => 'time-ago-in-words' , 'title' => $ dateTime ] ; if ( is_array ( $ options [ 'element' ] ) ) { $ element = $ options [ 'element' ] + $ element ; } else { $ element [ 'tag' ] = $ options [ 'element' ] ; } unset ( $ options [ 'element' ] ) ; } $ relativeDate = ( new Time ( $ dateTime ) ) -> timeAgoInWords ( $ options ) ; if ( $ element ) { $ relativeDate = sprintf ( '<%s%s>%s</%s>' , $ element [ 'tag' ] , $ this -> templater ( ) -> formatAttributes ( $ element , [ 'tag' ] ) , $ relativeDate , $ element [ 'tag' ] ) ; } return $ relativeDate ; }
Formats a date into a phrase expressing the relative time.

### Additional options

- `element` - The element to wrap the formatted time in.
Has a few additional options:
- `tag` - The tag to use, defaults to 'span'.
- `class` - The class name to use, defaults to `time-ago-in-words`.
- `title` - Defaults to the $dateTime input.

@param int|string|\DateTime|\Cake\Chronos\ChronosInterface $dateTime UNIX timestamp, strtotime() valid string or DateTime object
@param array $options Default format if timestamp is used in $dateString
@return string Relative time string.
@see \Cake\I18n\Time::timeAgoInWords()
Formats a date into a phrase expressing the relative time .