Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be a way to specify which time zone the time is in #4

Open
oveddan opened this issue Feb 7, 2013 · 2 comments
Open

There should be a way to specify which time zone the time is in #4

oveddan opened this issue Feb 7, 2013 · 2 comments

Comments

@oveddan
Copy link

oveddan commented Feb 7, 2013

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.

@excid3
Copy link
Owner

excid3 commented Feb 8, 2013

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!

@nynhex
Copy link

nynhex commented Jan 31, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants