I'm using a Rails application to access a database from a legacy application. This application stores all datetime fields using Europe/Madrid timezone.
I tried to set this in my application.rb:
config.time_zone = 'Madrid'
config.active_record.default_timezone = :local
Unfortunately it didn't worked as I expected. It looks like Rails is using the timezone of my system ( America/Sao_Paulo ). So a date that is stored as:
2015-09-09 18:38:01
Will be shown with a difference of 5 hours in Rails:
2015-09-09 23:38:01
Which is the difference between São Paulo and Madrid. It should show 18:38:01 in Rails too since my app's default timezone is Madrid.
Is there a way to force the ActiveRecord timezone without changing my OS timezone?
--- Edit ---
Here is the output that I get:
2.1.3 :004 > Time.zone.name
=> "Madrid"
2.1.3 :005 > LogSent.last.sent_date
LogSent Load (0.4ms) SELECT `log_sent`.* FROM `log_sent` ORDER BY `log_sent`.`id` DESC LIMIT 1
=> Wed, 09 Sep 2015 23:38:01 CEST +02:00
I'm expecting "Wed, 09 Sep 2015 18:38:01 CEST +02:00" which is the value stored in database, in Madrid timezone.