Class: Innodb::DataType::DatetimeType

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/data_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_type, modifiers, properties) ⇒ DatetimeType

Returns a new instance of DatetimeType.



290
291
292
293
# File 'lib/innodb/data_type.rb', line 290

def initialize(base_type, modifiers, properties)
  @width = 8
  @name = Innodb::DataType.make_name(base_type, modifiers, properties)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



288
289
290
# File 'lib/innodb/data_type.rb', line 288

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



288
289
290
# File 'lib/innodb/data_type.rb', line 288

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



295
296
297
298
299
300
301
302
# File 'lib/innodb/data_type.rb', line 295

def value(data)
  datetime = BinData::Int64be.read(data) ^ (-1 << 63)
  date = datetime / 1000000
  year, month, day = [date / 10000, (date / 100) % 100, date % 100]
  time = datetime - (date * 1000000)
  hour, min, sec = [time / 10000, (time / 100) % 100, time % 100]
  "%04d-%02d-%02d %02d:%02d:%02d" % [year, month, day, hour, min, sec]
end