Date/time converter into "n time ago" format. Supports Russian and English languages.
Default language is English. Optionally you can set the language in your application by calling set()
method and passing a flag 'ru' or 'en';
Serhii\Ago\Lang::set('ru');
For outputting post publishing date or something else you can just pass the date to method ago()
. It will count the interval between now and given date and returns needed format. Internally given date will be parsed by strtotime()
PHP's function.
Serhii\Ago\Time::ago('now - 10 seconds'); // output: 10 seconds ago
As the seconds argument ago
method excepts array of options. Here is an example of passed options.
Time::ago('yesterday', ['no-suffix']); // output: 1 day
Option name | Description |
---|---|
online | Display "Online" if date interval within 60 seconds. After 60 seconds output will be the same as usually "x time ago" format. |
no-suffix | Remove suffix from date and have "5 minutes" instead of "5 minutes ago". |
upcoming | Without this option passed time will be subtracted from current time, but with this option it will take given time and subtract current time. It is useful if you need to display a counter for some date in future. Suffix will be also removed. |
composer require serhii/ago