\Cake\I18nRelativeTimeFormatter

Helper class for formatting relative dates & times.

Summary

Methods
Properties
Constants
diffForHumans()
timeAgoInWords()
dateAgoInWords()
No public properties found
No constants found
_diffData()
_options()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

diffForHumans()

diffForHumans(\Cake\Chronos\ChronosInterface  $date, \Cake\Chronos\ChronosInterface|null  $other = null, boolean  $absolute = false) : string

Get the difference in a human readable format.

Parameters

\Cake\Chronos\ChronosInterface $date

The datetime to start with.

\Cake\Chronos\ChronosInterface|null $other

The datetime to compare against.

boolean $absolute

removes time difference modifiers ago, after, etc

Returns

string —

The difference between the two days in a human readable format

timeAgoInWords()

timeAgoInWords(\DateTimeInterface  $time, array  $options = array()) : string

Format a into a relative timestring.

Parameters

\DateTimeInterface $time

The time instance to format.

array $options

Array of options.

Returns

string —

Relative time string.

dateAgoInWords()

dateAgoInWords(\DateTimeInterface  $date, array  $options = array()) : string

Format a into a relative date string.

Parameters

\DateTimeInterface $date

The date to format.

array $options

Array of options.

Returns

string —

Relative date string.

_diffData()

_diffData(integer|string  $futureTime, integer|string  $pastTime, boolean  $backwards, array  $options) : array

Calculate the data needed to format a relative difference string.

Parameters

integer|string $futureTime

The timestamp from the future.

integer|string $pastTime

The timestamp from the past.

boolean $backwards

Whether or not the difference was backwards.

array $options

An array of options.

Returns

array —

An array of values.

_options()

_options(array  $options, string  $class) : array

Build the options for relative date formatting.

Parameters

array $options

The options provided by the user.

string $class

The class name to use for defaults.

Returns

array —

Options with defaults applied.