Changing the Date from UTC to Another Time Zone

I had some calculations that I wanted to do according to my app’s time zone and not UTC. was changing earlier than I wanted it to since the default is to use UTC.  However, I found a simple way to fix this:

in application.rb:

config.time_zone = ‘Eastern Time (US & Canada)’

then you can use this to get the date in the time zone you set:


If do not want to set the time_zone in the configuration, you can just do this: ‘Eastern Time (US & Canada)’).to_date

Time Zones in Rails 3

I was looking for what options I could use to set the time zone config in application.rb.  The best I could find were these posts in Stack Overflow:

essentially they are (for the biggest US zones):

Pacific Time (US & Canada), Central Time (US & Canada), Eastern Time (US & Canada)

The posts are good to reference nonetheless, as there seems to be a lot of confusion on what the config does (and time helpers).

Validations for Dates

I searched many times trying to figure out how to validate date of birth in my user model.  Finally, I stumbled on the validates_timeliness gem and it worked great for validating if a user was old enough to join my site.

after installing the gem, i just added the line from the example in my user model:

validates_date :date_of_birth, :before => lambda { 18.years.ago },
                              :before_message => "must be at least 18 years old"

Thank you for making this gem available adzap!