Summary

https://github.com/agency-of-learning/PairApp/issues/30

“We want to be able to store the timezone on a User.”

Proposals

Proposal 1 : Store time_zone as user preference in user table. Use ActiveSupport::TimeZone

Store timezone:

  1. create a migration to add a user column timezone
  2. edit the users controller by adding the new time_zone attribute to the permitted params
  3. edit user signup form to include users’ preferred time_zone field
    1. Initially the app will only take new users via invitations(devise_invitable) therefore we won’t need to modify the user registrations forms.
    2. Instead we’ll modify the invitation form to include the new timezone field

Pros:

  1. Storing the timezone will ensure that the correct time will always be used
  2. Will allow users to edit their timezone at will

Cons:

  1. Adds complexity to the table by adding the timezone field
  2. Adds steps to the user sign up process

Proposal 2: Set timezone using ActiveSupport::TimeZone and ActiveSupport::TimeWithZone

  1. Add :time_zone to the User model

    create_table :users do |t|
      t.string :time_zone, default: "UTC"
      ...
    end
    
  2. Add helper to profile form to allow user to set own desired time zone

    <%= f.input :time_zone %>
    
  3. In the ApplicationController set an around_action

    around_action :set_time_zone, if: :current_user
    
    private
    
    def set_time_zone(&block)
      Time.use_zone(current_user.time_zone, &block)
    end