Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I eventually found a solution searching more deeply into Stackoverlow :</p> <p>This blog post explains the problem and gives a working solution : <a href="http://blog.nominet.org.uk/tech/2007/06/14/date-and-time-formating-issues-in-ruby-on-rails/" rel="nofollow">http://blog.nominet.org.uk/tech/2007/06/14/date-and-time-formating-issues-in-ruby-on-rails/</a> </p> <p>So we have : <em>lib/column-patch.rb</em></p> <pre><code>class ActiveRecord::ConnectionAdapters::Column def self.string_to_date(string) return string unless string.is_a?(String) begin return DateTime.strptime(string, ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default]) rescue date_array = ParseDate.parsedate(string) # treat 0000-00-00 as nil Date.new(date_array[0], date_array[1], date_array[2]) rescue nil end end def self.string_to_time(string) return string unless string.is_a?(String) begin if dt=Date._strptime(string,ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS[:default]) return Time.mktime(*dt.values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)) else raise "Bad format" end rescue time_hash = Date._parse(string) time_hash[:sec_fraction] = microseconds(time_hash) time_array = time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction) # treat 0000-00-00 00:00:00 as nil Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue DateTime.new(*time_array[0..5]) rescue nil end end end </code></pre> <p>And we add in <em>config/environment.rb</em></p> <pre><code>require 'column-patch' </code></pre>
 

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