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.



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

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.



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

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



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

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