On this page
Class RelativeTimeFormatter
Helper class for formatting relative dates & times.
Method Summary
_diffData() protected
Calculate the data needed to format a relative difference string.
_options() protected
Build the options for relative date formatting.
dateAgoInWords() public
Format a into a relative date string.
diffForHumans() public
Get the difference in a human readable format.
timeAgoInWords() public
Format a into a relative timestring.
Method Detail
_diffData() protected
_diffData(string|int $futureTime, string|int $pastTime, bool $backwards, array<string, mixed> $options): array
Calculate the data needed to format a relative difference string.
Parameters
string|int$futureTime-
The timestamp from the future.
string|int$pastTime-
The timestamp from the past.
bool$backwards-
Whether the difference was backwards.
array<string, mixed>$options-
An array of options.
Returns
array_options() protected
_options(array<string, mixed> $options, string $class): array<string, mixed>
Build the options for relative date formatting.
Parameters
array<string, mixed>$options-
The options provided by the user.
string$class-
The class name to use for defaults.
Returns
array<string, mixed>dateAgoInWords() public
dateAgoInWords(Cake\I18n\I18nDateTimeInterface $date, array<string, mixed> $options = []): string
Format a into a relative date string.
Parameters
Cake\I18n\I18nDateTimeInterface$date-
The date to format.
array<string, mixed>$options optional-
Array of options.
Returns
stringSee Also
diffForHumans() public
diffForHumans(Cake\Chronos\ChronosInterface $date, Cake\Chronos\ChronosInterface|null $other = null, bool $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 optional-
The datetime to compare against.
bool$absolute optional-
Removes time difference modifiers ago, after, etc.
Returns
stringSee Also
timeAgoInWords() public
timeAgoInWords(Cake\I18n\I18nDateTimeInterface $time, array<string, mixed> $options = []): string
Format a into a relative timestring.
Parameters
Cake\I18n\I18nDateTimeInterface$time-
The time instance to format.
array<string, mixed>$options optional-
Array of options.
Returns
stringSee Also
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.I18n.RelativeTimeFormatter.html