title: Send Newsletter to Users at 9:00 AM in their Local Time Zone
body: <p>I am using the following gems:</p>
  
  <ul>
  <li><code>timezone</code></li>
  <li><code>tzinfo</code></li>
  </ul>
  
  <p>I am trying to have a newsletter sent at <code>user</code>'s time zone, so that they get the newsletter at their 9:00:00; <em>not</em> 09:00:00 PST where my server is.</p>
  
  <p>I am storing the time zones by name, like "Pacific Time (US &amp; Canada)".  Each user has a column <code>user.time_zone</code> where their specific time zone is stored.</p>
  
  <p>I have built a <code>job</code> that checks every hour for <code>user</code>s who could receive the newsletter (i.e. <code>user</code>s whose local time is 9:00 AM).</p>
  
  <pre><code>class NewsletterTimezoneJob &lt; ActiveJob::Base
    def self.perform
        users = User.all.gets_newsletter
        users.each do |user|
        d = Date.current
        t = "09:00:00 -0700"
        t = t.to_time
        newsletter_sendtime = DateTime.new(d.year, d.month, d.day, t.hour, t.min, t.sec, t.zone)
        newsletter_sendtime = newsletter_sendtime.to_s
        if user.is_in_time_around(newsletter_sendtime) 
          NewsletterMailer.send_mailer(user, newsletter_sendtime).deliver_later
        end
      end
    end
  end
  </code></pre>
  
  <p>I have built a method on <code>user</code> that <em>tries</em> to see if the user's local time matches <code>newsletter_sendtime</code>.</p>
  
  <p>I added a +/- 5 minute window to account for slow servers.</p>
  
  <p><code>User.rb</code>:</p>
  
  <pre><code>def is_in_time_around(timeofday)
     timeofday = timeofday.to_time
     user_zoned =  timeofday.in_time_zone(self.time_zone)
     user_zoned = user_zoned.strftime("%r").to_time
     timeofday = timeofday.strftime("%r").to_time
     if user_zoned &gt;= (timeofday - 5.minutes) &amp;&amp; user_zoned &lt;= (timeofday + 5.minutes)
      true
     end
   end
  </code></pre>
  
  <p>This <code>job</code> and <code>method</code> <em>should</em> run every hour and send to different users in different time zones each hour; and yet it currently only sends to users in "Pacific Time (US &amp; Canada)," <em>each</em> hour and <em>never</em> sends it to any other `users.</p>