yii2-daysago DaysAgo - Converter dates in a user-friendly format

DaysAgo

  1. Install
  2. Usage

Converter dates in a user-friendly format

Install

  1. Add to composer.json
[json]
"require": {
    "sfedosimov/yii2-daysago": "*"
},

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/sfedosimov/yii2-daysago.git"
    }
],
  1. Run composer update

  2. 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 дня прошло
0 0
2 followers
0 downloads
Yii Version: 2.0
License: MIT
Category: Date and Time
Developed by: sfedosimov
Created on: Dec 8, 2015
Last updated: 2 years ago

Related Extensions