DaysAgo ¶
Converter dates in a user-friendly format
Install ¶
- Add to
composer.json
[json]
"require": {
"sfedosimov/yii2-daysago": "*"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/sfedosimov/yii2-daysago.git"
}
],
Run
composer update
Add to config Yii2:
'i18n' => [
'translations' => [
// .....
'daysago*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@sfedosimov/daysago/messages',
'sourceLanguage' => 'ru',
],
// .....
],
],
Usage ¶
Like Class ¶
use sfedosimov\daysago\DaysAgo;
// ...
// make([date, format], [date, format]);
echo (new DaysAgo())->make('30.09.1998');
// 2 месяца и 5 дней
// if you language='en-US' - 2 months and 5 days
(new DaysAgo())->make(['02-12-2015', 'd-m-Y'], ['02-12-2015', 'd-m-Y']);
// сегодня
// today
echo (new DaysAgo())->make(['01-06-2010', 'd-m-Y'], ['05.12.2015']);
// 5 лет, 6 месяцев и 4 дня назад
// 5 years, 6 months and 4 days
Like Component ¶
Add to config Yii2:
'components' => [
// .....
'daysago' => [
'class' => 'sfedosimov\daysago\DaysAgo',
'format_in' => 'd-m-Y',
'past_prefix' => ''
'past_postfix' => ' прошло' // ago
'future_prefix' => ''
'future_postfix' => ''
],
// .....
]
Use:
echo Yii::$app->daysago->make('05.12.2015');
// 5 лет, 6 месяцев и 4 дня прошло
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.