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\DateTimeCake\I18n\Date $date, array<string, mixed> $options = []): string
Format a into a relative date string.
Parameters
-
Cake\I18n\DateTimeCake\I18n\Date
$date The date to format.
-
array<string, mixed>
$options optional Array of options.
Returns
string
See Also
diffForHumans() ¶ public
diffForHumans(Cake\Chronos\ChronosDateDateTimeInterface $first, Cake\Chronos\ChronosDateDateTimeInterface|null $second = null, bool $absolute = false): string
Get the difference in a human readable format.
Parameters
-
Cake\Chronos\ChronosDateDateTimeInterface
$first The datetime to start with.
-
Cake\Chronos\ChronosDateDateTimeInterface|null
$second optional The datetime to compare against.
-
bool
$absolute optional Removes time difference modifiers ago, after, etc.
Returns
string
See Also
timeAgoInWords() ¶ public
timeAgoInWords(Cake\I18n\DateTimeCake\I18n\Date $time, array<string, mixed> $options = []): string
Format a into a relative timestring.
Parameters
-
Cake\I18n\DateTimeCake\I18n\Date
$time The time instance to format.
-
array<string, mixed>
$options optional Array of options.
Returns
string