kartik-v / yii2-datecontrol

Date control module allowing separation of date formats for View & Model for Yii Framework 2.0.
http://demos.krajee.com/datecontrol
Other
55 stars 29 forks source link

datecontrol datetime conversion not working properly #62

Closed vzani closed 9 years ago

vzani commented 9 years ago

I´ve been learning Yii2 framework the past 2 weeks. I´m doing some tests to update and retrieve datetime fields.

I create a Mysql Table "order" with 'created_date' field as "DATETIME".

I configured the \kartik\datecontrol\Module this way:

                'datecontrol' => [ 
                    'class' => '\kartik\datecontrol\Module',

                    // format settings for displaying each date attribute (ICU format example)
                    'displaySettings' => [ 
                            Module::FORMAT_DATE => 'dd/MM/yyyy',
                            Module::FORMAT_TIME => 'HH:mm:ss a',
                            Module::FORMAT_DATETIME => 'dd/MM/yyyy HH:mm:ss a' 
                    ],

                    // format settings for saving each date attribute (PHP format example)
                    'saveSettings' => [ 
                            Module::FORMAT_DATE => 'php:Y-m-d',
                            Module::FORMAT_TIME => 'php:H:i:s',
                            Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s' 
                    ],

                    // set your display timezone
                    'displayTimezone' => 'America/Sao_Paulo',

                    // set your timezone for date saved to db
                    'saveTimezone' => 'UTC',

                    // aut;omatically use kartik\widgets for each of the above formats
                    'autoWidget' => true,

                    // default settings for each widget from kartik\widgets used when autoWidget is true
                    'autoWidgetSettings' => [ 
                            Module::FORMAT_DATE => [ 
                                    'type' => 2,
                                    'pluginOptions' => [ 
                                            'autoclose' => true 
                                    ] 
                            ], // example
                            Module::FORMAT_DATETIME => [ ], // setup if needed
                            Module::FORMAT_TIME => [ ] 
                    ], // setup if needed*/

                    // custom widget settings that will be used to render the date input instead of kartik\widgets,
                       // this will be used when autoWidget is set to false at module or widget level.
                    'widgetSettings' => [ 
                            Module::FORMAT_DATE => [ 
                                    'class' => 'yii\jui\DatePicker', // example
                                    'options' => [ 
                                            'dateFormat' => 'php:d-M-Y',
                                            'options' => [ 
                                                    'class' => 'form-control' 
                                            ] 
                                    ] 
                            ] 
                    ] 
            ],

My update view:

<?= $form->field($model, 'created_date')->widget(DateControl::classname(), [
    'type'=>DateControl::FORMAT_DATETIME,
    'ajaxConversion'=>true,
    /*'options' => [
        'pluginOptions' => [
            'autoclose' => true
        ]
    ],*/
    'autoWidget' => true,
    'displayTimezone'=>'America/Sao_Paulo',
    'saveTimezone'=>'UTC'
]);
?>

My test, putting the current Sao Paulo timezone date and time

Please check image: http://i.stack.imgur.com/jBv0I.png

After updating, I check the DB. The expected result (on my understanding) would be:

2015-06-04 17:00:00 (The UTC date time for given input)

But it´s not working. It´s saving as:

2015-06-05 06:00:00

And on view it´s being displayed as:

Please check image: http://i.stack.imgur.com/gGRJH.png

Any help?

Thanks

CTOlet commented 9 years ago

I have exactly the same problem and i have debugged and seen that 'type' not sended via ajax request to convert action

CTOlet commented 9 years ago

The problem was in version 1.9.1 inside the datecontrol.js at 38 line. (self.reqType)

kartik-v commented 9 years ago

The latest stable version is v1.9.3.

Report issues on the latest release.