Class: DB::MariaDB::Native::Types::DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/db/mariadb/native/types.rb

Overview

A datetime type converter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "DATETIME") ⇒ DateTime

Initialize a datetime type converter.



132
133
134
# File 'lib/db/mariadb/native/types.rb', line 132

def initialize(name = "DATETIME")
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



137
138
139
# File 'lib/db/mariadb/native/types.rb', line 137

def name
  @name
end

#The SQL type name.(SQLtypename.) ⇒ Object (readonly)



137
# File 'lib/db/mariadb/native/types.rb', line 137

attr :name

Instance Method Details

#parse(string) ⇒ Object

Parse a datetime value from the database.



142
143
144
145
146
147
148
# File 'lib/db/mariadb/native/types.rb', line 142

def parse(string)
  if string
    parts = string.split(/[\-\s:]/)
    
    return Time.utc(*parts)
  end
end