Note that there are some explanatory texts on larger screens.

plurals
  1. POTime Behavior in Rails
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/7515398/utc-time-resets-to-2000-01-01-ruby-how-do-i-prevent-the-time-from-resetting">UTC time resets to 2000-01-01 (ruby). How do I prevent the time from resetting?</a> </p> </blockquote> <p>In my application.rb, I have:</p> <pre><code>config.time_zone = "Eastern Time (US &amp; Canada)" </code></pre> <p>If, in my application, I display:</p> <pre><code>&lt;%= Time.now %&gt; </code></pre> <p>everything looks as I'd expect ("<code>2012-10-09 09:20:39 -0400</code>").</p> <p>I also have a <code>Session</code> model with an attributes '<code>start</code>' and '<code>end</code>' of type <code>Time</code>.</p> <p>If, in my application code, I create a <code>Session</code> and set <code>s.start=Time.now</code>, the time shows up in the database as a UTC time, which is ok if translated for the application, but with a date of <code>2000-01-01</code>, and, displays the same way in the application if I have something like:</p> <pre><code>&lt;%= s.start %&gt; </code></pre> <p>Also, if I then populate my '<code>end</code>' attribute some time later with <code>s.end = Time.now</code>, I get a similar <code>2000-01-01</code> and UTC time value. At the same time, I set an <code>elapsed</code> time attribute as:</p> <pre><code>s.elapsed = s.end - s.start </code></pre> <p>In the database, <code>elapsed</code> shows up as an extremely large number (403056003) even if the difference between <code>start</code> and <code>end</code> is only a few seconds.</p> <p>If I display <code>s.elapsed</code> and (<code>s.end - s.start</code>) in my application later, <code>s.elapsed</code> shows the big number in the database (obviously), but the calculation of <code>s.end - s.start</code> displays correctly!</p> <p>Sorry if this is rambling. I'm clearly missing something fundamental, but can't get there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload