ActiveRecord model with datetime stamp with timezone support attribute.

Posted by jtarchie on Stack Overflow See other posts from Stack Overflow or by jtarchie
Published on 2010-01-26T08:21:53Z Indexed on 2010/04/22 15:03 UTC
Read the original article Hit count: 334

Rails is great that it will support timezone overall in the application with Time.zone. I need to be able to support the timezone a user selects for a record. The user will be able to select date, time, and timezone for the record and I would like all calculations to be done with respect to the user selected timezone.

My question is what is the best practice to handle user selected timezones. The model is using a time_zone_select and datetime_select for two different attributes timezone and scheduled_at. When the model saves, the scheduled_at attribute gets converted to the locally defined Time.zone.

When a user goes back to edit the scheduled_at attribute with the datetime_select the datetime is set to the converted Time.zone timezone and not the timezone attribute. Is there a nice way to handle to the conversion to the user selected timezone?

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about timezone