Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 2.3.5 parses date inconsistently
    text
    copied!<p>To start, I am using an old rails version because of Redmine.</p> <p>I am trying to write a script for updating Redmine's database dump timestamps' to a specific timezone, therefore I need ruby to parse them and change the timezone, assuming rails can handle dst boundaries.</p> <p>Nevertheless, I found an inconsistency in (or misunderstood) how Time.parse works.</p> <p>Here's the script I executed on my Rails 2.3.5 raw application:</p> <pre><code>impulse@ImpulseServer:~/pgtz_converter$ script/console Loading development environment (Rails 2.3.5) &gt;&gt; Time.zone =&gt; #&lt;ActiveSupport::TimeZone:0x7fa94a57b9a8 @tzinfo=nil, @name="UTC", @utc_offset=0&gt; &gt;&gt; Time.parse('2011-02-19 23:00:00') =&gt; Sat Feb 19 23:00:00 -0200 2011 &gt;&gt; Time.zone =&gt; #&lt;ActiveSupport::TimeZone:0x7fa94a57b9a8 @tzinfo=nil, @name="UTC", @utc_offset=0&gt; &gt;&gt; Time.parse('2011-02-20 00:00:00') =&gt; Sun Feb 20 00:00:00 -0300 2011 &gt;&gt; Time.zone =&gt; #&lt;ActiveSupport::TimeZone:0x7fa94a57b9a8 @tzinfo=nil, @name="UTC", @utc_offset=0&gt; &gt;&gt; Time.parse('2011-02-19 23:00:00') =&gt; Sat Feb 19 23:00:00 -0300 2011 &gt;&gt; Time.zone =&gt; #&lt;ActiveSupport::TimeZone:0x7fa94a57b9a8 @tzinfo=nil, @name="UTC", @utc_offset=0&gt; &gt;&gt; exit </code></pre> <p>Here's what is going on above:</p> <p>The server local datetime zone is BRT.</p> <pre><code>impulse@ImpulseServer:~/pgtz_converter$ date Fri Apr 8 19:17:34 BRT 2011 </code></pre> <p>First I check Time.zone (which is UTC), then try to parse a DST date. The output is fine, DST is on (I presume Time.zone = UTC means Ruby checked the server zone configuration and used it). Then I try another date, in which DST was not active anymore (DST ended on 02/20/2011 00:00 here). This date is correctly parsed (GMT-3).</p> <p>Now the problem begins.</p> <p>I try to parse again the old DST date, and the result is wrong! It wasn't read as a DST date!</p> <p>I thought perhaps the parsing changed the Time.zone, but as it is pasted it is UTC all the time.</p> <p>What is causing this ?</p> <p>Thank you for reading.</p> <p>Nilo</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