Weird Behaviors of datetime(timezone) in Rails application


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?


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.


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

around_filter :

def use_time_zone(&block)
  Time.use_zone('London', &block)

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