kartik-v / yii2-date-range

A Date Range Picker for Bootstrap useful for reports and filtering.
http://demos.krajee.com/date-range
Other
93 stars 80 forks source link

Incorrect timezone date #175

Closed gashik1979 closed 7 months ago

gashik1979 commented 7 months ago

Hello!

I have some problem with date formation. For some reason, after creating the model, the time becomes UTC.

Model:

public function rules()
    {
        return [
            ..
            [['time_range'], 'match', 'pattern' => '/^.+\s\-\s.+$/'],
            [['time_range'], 'default', 'value' => date('Y-m-d', strtotime('-1 month')) . ' - ' . date('Y-m-d')],            
        ];
    }
public function behaviors()
{
    return [
        [
            'class' => DateRangeBehavior::className(),
            'attribute' => 'time_range',
            'dateStartAttribute' => 'start_date',
            'dateEndAttribute' => 'end_date',
        ]
    ];
}

Controller:

    date_default_timezone_set('Europe/Moscow');
    echo date('Y-m-d', strtotime('-1 month')) . ' - ' . date('Y-m-d')."<br>";
    $searchModel = new StatisticSearch();

    $dataProvider = $searchModel->search($this->request->queryParams);

    echo $searchModel->time_range;
    exit;

Output result: 2024-01-28 - 2024-02-28 2024-01-27 - 2024-02-27

The first output is correct, the time is Moscow time, but the second output is UTC for some reason.

Operating System

Libraries

gashik1979 commented 7 months ago

я туплю, у меня фильтр был в ссылке