Class: DBI::DBD::Mysql::Type::Date

Inherits:
Type::Null show all
Defined in:
lib/dbd/Mysql.rb

Overview

Custom handling for DATE types in MySQL. See DBI::Type for more information.

Class Method Summary collapse

Class Method Details

.parse(obj) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/dbd/Mysql.rb', line 117

def self.parse(obj)
    obj = super
    return obj unless obj

    case obj.class
    when ::Date
        return obj
    when ::String
        return ::Date.strptime(obj, "%Y-%m-%d")
    else
        return ::Date.parse(obj.to_s)   if obj.respond_to? :to_s
        return ::Date.parse(obj.to_str) if obj.respond_to? :to_str
        return obj
    end
end