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(DateTime $futureTime, DateTime $pastTime, bool $backwards, array $options): array
Calculate the data needed to format a relative difference string.
Parameters
-
DateTime
$futureTime The time from the future.
-
DateTime
$pastTime The time from the past.
-
bool
$backwards Whether or not the difference was backwards.
-
array
$options An array of options.
Returns
array
_options() ¶ protected
_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
dateAgoInWords() ¶ public
dateAgoInWords(DatetimeInterface $date, array $options = []): string
Format a into a relative date string.
Parameters
-
DatetimeInterface
$date The date to format.
-
array
$options optional Array of options.
Returns
string
See 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
string
See Also
timeAgoInWords() ¶ public
timeAgoInWords(DateTimeInterface $time, array $options = []): string
Format a into a relative timestring.
Parameters
-
DateTimeInterface
$time The time instance to format.
-
array
$options optional Array of options.
Returns
string