Rails Time Zone

I understand that the default behavior for rails is to save database records and any columns associated with date and date in UTC. And we can control the display of date / date and time to users with config.time_zone in environment.rb. Thus, the main setting for config.time_zone is to control the display with which rails converts entries from UTC to the one we specify in config.time_zone.

Is there a way or setting to force the rails to save entries in EST, not UTC, and still do the conversion for display based on config.time_zone setting?

-Satynos

+4
source share
2 answers

You should consider the arguments for your question. Remember: Rails implements a configuration convention - and you will have a good reason to change the convention! Especially on something as arbitrary as the date and time stored in the database, and given how easy Rails allows us to work with dates.

+3
source

I don’t know how to make records save to EST, but I wanted to share this discussion about using the local time zone in db: http://www.ruby-forum.com/topic/890711

From the discussion, I ended up using skip_time_zone_conversion_for_attributes for a similar problem (about this method: http://api.rubyonrails.org/classes/ActiveRecord/Timestamp.html ). This may be of interest to you - perhaps set the time zone to EST, and then try this method.

Good luck I know it has been a while, but it may take some time for people to know what you were doing.

0
source

All Articles