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.



292
293
294
295
# File 'lib/innodb/data_type.rb', line 292

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.



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

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



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

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