PHPackages                             meysampg/yii2-intldatebehavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. meysampg/yii2-intldatebehavior

AbandonedYii2-extension

meysampg/yii2-intldatebehavior
==============================

Automatic Change Date System of an ActiveRecord After finding It

v1.1.1(9y ago)37.8k1MITPHP

Since Nov 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/meysampg/yii2-intldatebehavior)[ Packagist](https://packagist.org/packages/meysampg/yii2-intldatebehavior)[ RSS](/packages/meysampg-yii2-intldatebehavior/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Yii2 IntlDateBehavior
=====================

[](#yii2-intldatebehavior)

🟥⚠️ *THIS PACKAGE IS ABANDONED. PLEASE SELECT ANOTHER PACKAGE OR FORK THIS REPOSITORY AND INFORM ME ON p.g.meysam \[at\] gmail \[dot\] com TO REFFER TO YOUR PACKAGE IN PACKAGIST* ⚠️🟥

**Automatic Change Date System of an ActiveRecord After finding It.** Actually it converts date and time system just on representation and keep your model clean. So if you need a converter for change time and save it on DB, you can use [IntlDate](https://github.com/meysampg/intldate) trait ;).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require meysampg/yii2-intldatebehavior "*"
```

or add

```
"meysampg/yii2-intldatebehavior": "*"
```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your class by `use meysampg\behaviors\IntlDateBehavior` and use it by attaching it as a behavior to your ActiveRecord model:

```
public function behaviors()
{
    return [
        IntlDateBehavior::className(),
    ];
}
```

**Also in your model, you must change the rule of `timestamp` fields from `integer` to `safe`.**

For default, behavior try to show `created_at` and `updated_at` in your desired manner which both of them have `timestamp` type. If you wanna select other attributes, you can assign them as an array (a.e. `['time1', 'time2', 'time3']`) to `timestampAttributes` property.

Configuration
-------------

[](#configuration)

Configuration of this behavior can be on two way. The first one is using Yii2 configuration array, for example:

```
public function behaviors()
{
    return [
        [
            'class' => IntlDateBehavior::className(),
            'timestampAttributes' => ['create_time', 'update_time', 'another_time'],
            'calendar' => 'persian',
            'format' => 'php:d F Y، H:i:s',
            'locale' => 'fa',
            'tz' => 'Asia/Tehran'
        ],
    ];
}
```

This is a local configuration. The second way is when you want to use this behavior in multiple model with same configurations, so you should add it as a behavior to model:

```
public function behaviors()
{
    return [
        IntlDateBehavior::className(),
    ];
}
```

and put the configurations in `params.php` file. As an example, here is my `params.php`:

```
