CubicLouve

Spring_MTの技術ブログ

rails4の日付のcast

active_record/connection_adapters/column.rb

          def new_time(year, mon, mday, hour, min, sec, microsec)
            # Treat 0000-00-00 00:00:00 as nil.
            return nil if year.nil? || (year == 0 && mon == 0 && mday == 0)

            Time.send(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil                                
          end