Class: Innodb::DataType::DateType

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) ⇒ DateType

Returns a new instance of DateType.



273
274
275
276
# File 'lib/innodb/data_type.rb', line 273

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



271
272
273
# File 'lib/innodb/data_type.rb', line 271

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



271
272
273
# File 'lib/innodb/data_type.rb', line 271

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



278
279
280
281
282
283
284
# File 'lib/innodb/data_type.rb', line 278

def value(data)
  date = BinData::Int24be.read(data) ^ (-1 << 23)
  day = date & 0x1f
  month = (date >> 5) & 0xf
  year = date >> 9
  "%04d-%02d-%02d" % [year, month, day]
end