title: "comparison of Date with ActiveSupport::TimeWithZone" fails consistently after about two months in prod
body: <p>In a production app, the following code works in dev and (initially) in production:</p>
  
  <pre><code>@employee.ident_expiration_date &amp;&amp; @employee.ident_expiration_date &lt; 3.months.from_now
  </code></pre>
  
  <p>The app is used daily by one or more users. At random intervals, at least a week at most 3 months, this error starts to occur: <code>ActionView::Template::Error (comparison of Date with ActiveSupport::TimeWithZone)</code></p>
  
  <p>In the console:</p>
  
  <pre><code>&gt;&gt; date = e.ident_expiration_date
  =&gt; Sat, 12 Jun 2021
  
  &gt;&gt; date.class
  =&gt; Date
  
  &gt;&gt; twz = 3.months.from_now
  =&gt; Sat, 04 Nov 2017 10:11:54 CDT -05:00
  
  &gt;&gt; twz.class
  =&gt; ActiveSupport::TimeWithZone
  
  &gt;&gt; date &lt; twz
  =&gt; false
  </code></pre>
  
  <p>I thought maybe I was requiring something that might cause that issue... but the only require statement in the entire /app directory is <code>require 'valuable'</code>, a gem I wrote. I'm sure that isn't causing the issue.</p>
  
  <p>The process has been alive since I last restarted the app (which caused the issue to disappear.)</p>
  
  <p><code>product+  3053  0.0 16.7 1981264 342088 ?      Sl   Jun16  50:32 puma 2.12.3 (tcp://0.0.0.0:9444) [20170323153916]</code></p>
  
  <p>So my conclusion at this point is that one of those classes is being polluted by some code that doesn't run very often. I'm have run through the recent history of the app to force this to happen. But I haven't succeeded.</p>
  
  <p>I'm open to any ideas about how this might be happening.</p>
  
  <p>Based on the second reference below, my long-shot answer is to change TimeWithZone to a Date using <code>@employee.ident_expiration_date &amp;&amp; @employee.ident_expiration_date &lt; 3.months.from_now.to_date</code> ... but if someone could explain what's happening that would be fantastic.</p>
  
  <h2>Versions</h2>
  
  <p>Versions:</p>
  
  <ul>
  <li>rbx 2.5.2 which is ruby 2.1.0</li>
  <li>rails 4.2.3</li>
  <li>Linux version 4.9.15-x86_64-linode81 (maker@build) (gcc version 4.7.2 (Debian 4.7.2-5) )</li>
  </ul>
  
  <h2>References</h2>
  
  <p><a href="https://stackoverflow.com/questions/12811207/comparison-of-date-with-activesupporttimewithzone-failed">Don't use Date == TimeWithZone</a>, which makes sense.</p>
  
  <p><a href="https://github.com/rails/rails/issues/6254" rel="nofollow noreferrer">Date.today > Time.now fails in some situations</a> -- interestingly, I can reproduce their error in irb but not in the Rails console. I assume Rails is doing something to fix this? Could be related but since I can't reproduce it in the console, I'm not sure what to do about it.</p>