yii2: Formatter timeZone problem

Hi, I have problem with Formatter. asTime method always add 2 hours.

I think that it is because php on my server date.timezone option is set on Europe/Warsaw. But Yii Formatter have $defaultTimeZone = 'UTC' by default.

Yii should sync this settings, because for now I need to configure this option in this way:

        'formatter' => [
            'defaultTimeZone' => date_default_timezone_get(),
        ],

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

@cebe I still think that it IS a bug. Because Yii should by default use php server timezone do convert user input and display proper time, but store in files and database in UTC format.

For now, Yii store time data directly based on user input without casting it to UTC time.

It is simple workflow:

  • User enter the time in server time zone
  • Model validate it
  • Model convert it to UTC time zone and save it
  • Model read time from DB
  • Formatter format time as time zone on server
  • Time is displayed

It can be useful when application is running on the same database and different servers with different time zone configuration.

The problem is that Model or ActiveRecord does not convert time to UTC time zone. Yii should have build-in system to do this thing.