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.



283
284
285
286
# File 'lib/innodb/data_type.rb', line 283

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.



281
282
283
# File 'lib/innodb/data_type.rb', line 281

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



281
282
283
# File 'lib/innodb/data_type.rb', line 281

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



288
289
290
291
292
293
294
295
# File 'lib/innodb/data_type.rb', line 288

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