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.



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

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.



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

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



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

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