public function textualDateFilter($date)
    {
        if ( ! $date instanceof \DateTime) {
            throw new \InvalidArgumentException('Textual Date Filter expects input to be a instance of DateTime');
        }

        $now  = new \DateTime('now');
        $diff = $now->diff($date);

        $diffUnit          = $this->getHighestDiffUnitAndValue($diff);
        $temporalModifier  = ($diff->invert)? 'ago':'next';
        $translationString = $temporalModifier. '.' .$diffUnit['unit'];

        // Override yesterday and tomorrow
        if ($diffUnit['unit'] == 'd' && $diffUnit['value'] == 1) {
            $translationString = ($diff->invert)? 'date.yesterday':'date.tomorrow';
        }

        // Override "just.now"
        if ($diffUnit['unit'] == 'now') {
            $translationString = 'date.just_now';
        }

        return $this->translator->transChoice($translationString, $diffUnit['value'], array('%value%' => $diffUnit['value']), 'date');
    }
public function textualDateFilter($date)
    {
        if ( ! $date instanceof \DateTime) {
            throw new \InvalidArgumentException('Textual Date Filter expects input to be a instance of DateTime');
        }

        $now  = new \DateTime('now');
        $diff = $now->diff($date);

        $diffUnit          = $this->getHighestDiffUnitAndValue($diff);
        $temporalModifier  = ($diff->invert)? 'ago':'next';
        $translationString = $temporalModifier. '.' .$diffUnit['unit'];

        // Override yesterday and tomorrow
        if ($diffUnit['unit'] == 'd' && $diffUnit['value'] == 1) {
            $translationString = ($diff->invert)? 'date.yesterday':'date.tomorrow';
        }

        // Override "just.now"
        if ($diffUnit['unit'] == 'now') {
            $translationString = 'date.just_now';
        }

        return $this->translator->transChoice($translationString, $diffUnit['value'], array('%value%' => $diffUnit['value']), 'date');
    }
public function textualDateFilter ( $ date ) { if ( ! $ date instanceof \ DateTime ) { throw new \ InvalidArgumentException ( 'Textual Date Filter expects input to be a instance of DateTime' ) ; } $ now = new \ DateTime ( 'now' ) ; $ diff = $ now -> diff ( $ date ) ; $ diffUnit = $ this -> getHighestDiffUnitAndValue ( $ diff ) ; $ temporalModifier = ( $ diff -> invert ) ? 'ago' : 'next' ; $ translationString = $ temporalModifier . '.' . $ diffUnit [ 'unit' ] ; // Override yesterday and tomorrow if ( $ diffUnit [ 'unit' ] == 'd' && $ diffUnit [ 'value' ] == 1 ) { $ translationString = ( $ diff -> invert ) ? 'date.yesterday' : 'date.tomorrow' ; } // Override "just.now" if ( $ diffUnit [ 'unit' ] == 'now' ) { $ translationString = 'date.just_now' ; } return $ this -> translator -> transChoice ( $ translationString , $ diffUnit [ 'value' ] , array ( '%value%' => $ diffUnit [ 'value' ] ) , 'date' ) ; }
Converts dates into relative textual dates

Ex: x days ago, yesterday, tomorrow, in x days

@param \DateTime $date

@throws \InvalidArgumentException
@return string
Converts dates into relative textual dates