Skip to content

datetime_select preselects wrong times upon edit #9610

@GSI

Description

@GSI

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:

t.datetime "beginx"
t.datetime "endx"
t.string   "time_zone"

And an edit action like so:

@event = Event.find(id)
Time.zone = @event.time_zone
@event.beginx = @event.beginx.in_time_zone
@event.endx = @event.endx.in_time_zone

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 before_filter of the application controller (Time.zone = whatever).

If the code of the edit action is changed to the following, suddenly the time is shown within the time zone of the event:

@event = Event.find(id)
Time.zone = @event.time_zone
@event.beginx = @event.beginx.in_time_zone + 1.second
@event.endx = @event.endx.in_time_zone - 1.second

Note the +/- second.
(It's irrelevant which calculation is done - as long as one is done.)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions