Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
datetime_select preselects wrong times upon edit #9610
Note that the following was working correctly in Rails 3.2.6. I skipped the versions between, but can confirm at least that it fails 3.2.11 & 3.2.12.
Given an Event class with:
And an edit action like so:
In the datetime_select, beginx and endx should shown in regards to the time zone of the event.
Instead, they are shown in the time zone as defined in the
If the code of the edit action is changed to the following, suddenly the time is shown within the time zone of the event:
Note the +/- second.
The problem is also described in this SO-question: http://stackoverflow.com/questions/15209130/how-can-i-prefill-datetime-select-with-times-in-custom-time-zone
This is because the conversion is cached and when you try to assign the new value it sees it as the same value because it's converted to UTC first so it's never cleared. Rather than changing the global
class Event < ActiveRecord::Base def beginx super.in_time_zone(time_zone) end def endx super.in_time_zone(time_zone) end end
This will ensure that the values are always in the correct time zone.
@GSI yes, if you can have nil values in the column then you need to detect that. Other ways of doing it are:
super && super.in_time_zone(time_zone)
Which you prefer is down to you - I know some people have an ideological objection to the last one
Closing the ticket because it's working as it should be - thanks for your report though.