bupy7/yii2-datetime-converter Converting date and/or time from saving format to display and converse.

extensiondatetimedatetimeconverterformattercarbontranslator

yii2-datetime-converter

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Coverage Status

Converting date/time from display/save to save/display format.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist bupy7/yii2-datetime-converter "*"

or add

"bupy7/yii2-datetime-converter": "*"

to the require section of your composer.json file.

Usage

Add component to your config:

'dtConverter' => [
    'class' => 'bupy7\datetime\converter\Converter',
    // 'saveTimeZone' => 'UTC' - by default
    // 'saveDate' => 'php:Y-m-d' - by default
    // 'saveTime' => 'php:H:i:s' - by default
    // 'saveDateTime' => 'php:U' - by default
    // add format patterns if need for your locales (by default uses `en`)
    'patterns' => [
        'ru' => [
            'displayTimeZone' => 'Europe/Moscow',
            'displayDate' => 'php:d.m.Y',
            'displayTime' => 'php:H:i',
            'displayDateTime' => 'php:d.m.Y, H:i',
        ],
    ],
],
$datetime = 2015-06-07 12:45:00;
echo Yii::$app->dtConverter->toDisplayDateTime($datetime);

or

$datetime = new DateTime('now');
echo Yii::$app->dtConverter->toDisplayDateTime($datetime);

You can add behavior of your model for converting date/time before save.

use bupy7\datetime\converter\ConverterBehavior;

public function behaviors()
{
    return [
        // converter date/time before save
        [
            'class' => ConverterBehavior::className(),
            'type' => ConverterBehavior::TYPE_DATE_TIME,
            'to' => ConverterBehavior::TO_SAVE,
            'attributes' => [
                self::EVENT_BEFORE_SAVE => ['attribute_1', 'attribute_2'],
            ],
        ],
    ];
}

License

yii2-grid is released under the BSD 3-Clause License.

Changelog

yii2-datetime-converter

v1.1.1 [2016-02-05]

  • Added unit tests.

v1.1.0 [2015-12-11]

  • Removed the possibility calling method normalizePattern() as static.

v1.0.0 [2015-07-24]

  • First release.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.1.1 is the latest of 3 releases



BSD-3-Clause license
Stats
1 github stars & 2 github forks
0 downloads in the last day
0 downloads in the last 30 days
882 total downloads