Weird Behaviors of datetime(timezone) in Rails application

Hi,

In our rails 3.2 application, we have configured,

config.time_zone = 'London'
config.active_record.default_timezone = :local

And in postgresql also configured timezone as “Europe/London”.

For the past one week, our application datetime field is not working
properly with timezone.

For an example, If we create an reminder start_date at 2015-08-18 10AM.
it
creates 2015-08-18 10:00:00 in postgresql database.

when displaying in template,

reminder start date: 2015-08-18 10AM (2015-08-18 10:00:00 +0100 )

BUT,(not always) now frequently its showing UTC time.

reminder start date: 2015-08-18 9AM (2015-08-18 09:00:00 UTC )

it could not be reproduced in development.

anyone faced this kind of problem?

On Sunday, August 16, 2015 at 10:45:17 PM UTC+1, Shanmugavel A wrote:

Hi,

In our rails 3.2 application, we have configured,

config.time_zone = 'London'
config.active_record.default_timezone = :local

I wouldn’t recommend setting default_timezone to local - it means that
in addition to these settings, the timezone of the application server
will also influence results.

Fred

On 16 August 2015 at 22:47, Frederick C.
[email protected] wrote:

On Sunday, August 16, 2015 at 10:45:17 PM UTC+1, Shanmugavel A wrote:

Hi,

In our rails 3.2 application, we have configured,

config.time_zone = 'London'
config.active_record.default_timezone = :local

I wouldn’t recommend setting default_timezone to local - it means that in
addition to these settings, the timezone of the application server will also
influence results.

Just to reinforce Fred’s comment, in case you think :local means the
local time of the user in the browser that is not correct. It means
the local time of the server which may not even be under your control.

Colin

I fixed this issue, by adding around filter in ApplicationController.

around_filter :use_time_zone
private
def use_time_zone(&block)
Time.use_zone(‘London’, &block)end

So, whenever the default timezone changed to UTC, it will override and
set
as BST.