Skip to content

Options

The trans method is variadic and accepts multiple options. You can pass them as a list of arguments separated by commas.

php
use Serhii\Ago\TimeAgo;
use Serhii\Ago\Option;

$output = TimeAgo::trans('-30 seconds', Option::ONLINE);

echo $output; // "Online"

Here are more examples with different options:

php
use Serhii\Ago\Option;
use Serhii\Ago\TimeAgo;

echo TimeAgo::trans('yesterday'); // "1 day ago"
echo TimeAgo::trans('yesterday', Option::NO_SUFFIX); // "1 day"
echo TimeAgo::trans(time(), Option::ONLINE); // "Online"
echo TimeAgo::trans(time(), Option::JUST_NOW); // "Just now"

Available options

All options are available in Serhii\Ago\Option enum.

OptionDescription
ONLINEDisplay "Online" if date interval within 60 seconds. After 60 seconds output will be the same as usually "x time ago" format. Incompatible with option JUST_NOW.
NO_SUFFIXRemove suffix from date and have 5 minutes instead of 5 minutes ago.
JUST_NOWPrints Just now when time is within 1 minutes. For example instead of 34 seconds ago it will print Just now. Incompatible with option ONLINE.
UPCOMINGRemoves the suffix ago when the date is in the future. This option is enabled by default, there is no need to pass it. It's available for internal use.
RESET_CONFResets your configuration to default values. It's especially useful in testing when you need to reset the configuration to default values.