lib/active_support/refinements/core_ext/string/conversions.rb
# Converts a string to a DateTime value.
#
#   "1-1-2012".to_datetime            #=> Sun, 01 Jan 2012 00:00:00 +0000
#   "01/01/2012 23:59:59".to_datetime #=> Sun, 01 Jan 2012 23:59:59 +0000
#   "2012-12-13 12:50".to_datetime    #=> Thu, 13 Dec 2012 12:50:00 +0000
#   "12/13/2012".to_datetime          #=> ArgumentError: invalid date
Converts a string to a DateTime value.
Converts a string to a DateTime value .
def to_datetime
    unless blank?
      date_values = ::Date._parse(self, false).
        values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :sec_fraction).
        map! { |arg| arg || 0 }
      date_values[5] += date_values.pop
      ::DateTime.civil(*date_values)
    end
  end
def to_datetime unless blank? date_values = :: Date . _parse ( self , false ) . values_at ( :year , :mon , :mday , :hour , :min , :sec , :zone , :sec_fraction ) . map! { | arg | arg || 0 } date_values [ 5 ] += date_values . pop :: DateTime . civil ( * date_values ) end end
Converts a string to a DateTime value.
Converts a string to a DateTime value .