Open oveddan opened 11 years ago
So this is really just a replacement to the time_select
helper. If you've got user accounts that are in specific timezones, what you should really be doing is setting the time zone in a before_filter
so that everything in that user's request is set in their timezone.
Provided you're doing this, the gem is already parsing them into the correct TimeZone with this line: https://github.com/excid3/combined_time_select/blob/master/lib/combined_time_select.rb#L11
Since it's using Time.zone
to do the parsing, all you have to do is set the TimeZone.
Mine last implementation like that was a little more complex
class ApplicationController < ActionController::Base
around_filter :set_time_zone
def set_time_zone
old_time_zone = Time.zone
if user_signed_in?
Time.zone = current_user.time_zone
end
yield
ensure
Time.zone = old_time_zone
end
end
That will set the Time.zone for the whole request, then replace it with the server one once it's finished. I forget the reason for doing it this way exactly since it has been a while. I've recorded the time_zone
from the user as part of the registration form.
You might be taking a completely different approach to this however, so let me know!
I didn't have this problem in an app that I used the gem on. To set the time zone all I did was edit application.rb
and set config.time_zone
like this
config.time_zone = 'Central Time (US & Canada)'
Worked for me, but maybe I'm not understanding the problem correctly
Right now, the time always gets parsed in UTC time. What if you have users in different time zones with times displayed in their local time? There would be no way to out of the box specify which time zone the time they selected was in. The model code has to now convert this to a local time. It would be great to be able to specify this within the field itself.