Handling cases when a timezone isn't applicable

3 views
Skip to first unread message

Dave Rothlisberger

unread,
Nov 25, 2008, 7:42:59 PM11/25/08
to Ruby on Rails: Core
I've run into the following issue:

My app has multiple users from multiple timezones. In the majority of
cases, I want datetime columns to take into account the user's
timezone. This works fine.

However, for *one* particular datetime field, I want users to enter
the arrival date & time of a flight that is arriving into a country in
a different timezone to the user's timezone. Hence I don't want any
timezone conversion done on this particular field.

e.g. a user in Germany enters the data for a flight that will arrive
in New Zealand on January 1st at 2:00pm. When a different user views
this data, I want it to say 2:00pm, regardless of the user's timezone.

I don't see that the datetime_select helper allows me to specify a
timezone for the time I am selecting; but anyway, I don't want the
user to have to enter a timezone.

I suppose the easiest (only?) solution is to store the data in
separate date and time fields in the database, and use separate
date_select and time_select helpers.

Any comments? Should this functionality be something that datetimes /
datetime_select should support?

Cheers
Dave

Geoff B

unread,
Nov 26, 2008, 1:12:26 AM11/26/08
to Ruby on Rails: Core
Dave,

You can currently opt out of time zone aware attributes for specific
attributes like so:

class Flight < ActiveRecord::Base
...
self.skip_time_zone_conversion_for_attributes =
[:departure_time, :arrival_time]
...
end

With this setup, no time zone conversions will be done for
Flight#departure_time and #arrival time.

Does this give you what you need?

Geoff

Dave Rothlisberger

unread,
Nov 26, 2008, 11:13:46 AM11/26/08
to Ruby on Rails: Core
Yes! That's exactly what I need. Thank you very much -- far nicer than
overriding arrival_time and arrival_time= which is what I had ended up
doing.
Reply all
Reply to author
Forward
0 new messages