models/News.php
protected function correctSavedData($insert)
    {
        if ($insert) {

            $tzShiftSec = intval(date('Z')); // server time zone shift in seconds: west UTC <0, east UTC >0
            if (!empty($tzShiftSec)) {//var_dump($tzShiftSec);exit;
                $now = new Expression("DATE_SUB(NOW(), INTERVAL {$tzShiftSec} SECOND)"); // UTC time
            } else {
                $now = new Expression('NOW()'); // server time
            }
            $this->create_time = $now;
            if (empty($this->show_from_time)) $this->show_from_time = $now;
            $this->owner_id = Yii::$app->user->identity->id;
        } else {
/*
            // this corrections move to controller to POST preprocessing
            if (!empty($this->timezoneshift)) {//var_dump($this->attributes);var_dump($this->timezoneshift);
                $tz = intval($this->timezoneshift);
                $this->show_from_time = new Expression("DATE_ADD('{$this->show_from_time}', INTERVAL {$tz} MINUTE)");
                $this->show_to_time   = new Expression("DATE_ADD('{$this->show_to_time}',   INTERVAL {$tz} MINUTE)");
            }//var_dump($this->attributes);exit;
*/
        }
    }
protected function correctSavedData($insert)
    {
        if ($insert) {

            $tzShiftSec = intval(date('Z')); // server time zone shift in seconds: west UTC <0, east UTC >0
            if (!empty($tzShiftSec)) {//var_dump($tzShiftSec);exit;
                $now = new Expression("DATE_SUB(NOW(), INTERVAL {$tzShiftSec} SECOND)"); // UTC time
            } else {
                $now = new Expression('NOW()'); // server time
            }
            $this->create_time = $now;
            if (empty($this->show_from_time)) $this->show_from_time = $now;
            $this->owner_id = Yii::$app->user->identity->id;
        } else {
/*
            // this corrections move to controller to POST preprocessing
            if (!empty($this->timezoneshift)) {//var_dump($this->attributes);var_dump($this->timezoneshift);
                $tz = intval($this->timezoneshift);
                $this->show_from_time = new Expression("DATE_ADD('{$this->show_from_time}', INTERVAL {$tz} MINUTE)");
                $this->show_to_time   = new Expression("DATE_ADD('{$this->show_to_time}',   INTERVAL {$tz} MINUTE)");
            }//var_dump($this->attributes);exit;
*/
        }
    }
protected function correctSavedData ( $ insert ) { if ( $ insert ) { $ tzShiftSec = intval ( date ( 'Z' ) ) ; // server time zone shift in seconds: west UTC <0, east UTC >0 if ( ! empty ( $ tzShiftSec ) ) { //var_dump($tzShiftSec);exit; $ now = new Expression ( "DATE_SUB(NOW(), INTERVAL {$tzShiftSec} SECOND)" ) ; // UTC time } else { $ now = new Expression ( 'NOW()' ) ; // server time } $ this -> create_time = $ now ; if ( empty ( $ this -> show_from_time ) ) $ this -> show_from_time = $ now ; $ this -> owner_id = Yii :: $ app -> user -> identity -> id ; } else { /*
            // this corrections move to controller to POST preprocessing
            if (!empty($this->timezoneshift)) {//var_dump($this->attributes);var_dump($this->timezoneshift);
                $tz = intval($this->timezoneshift);
                $this->show_from_time = new Expression("DATE_ADD('{$this->show_from_time}', INTERVAL {$tz} MINUTE)");
                $this->show_to_time   = new Expression("DATE_ADD('{$this->show_to_time}',   INTERVAL {$tz} MINUTE)");
            }//var_dump($this->attributes);exit;
*/ } }
Data correction immediatly before save.
Datetime fields will convert into Expression-class.
Data correction immediatly before save . Datetime fields will convert into Expression - class .