Class: Innodb::DataType::TimeType

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

Returns a new instance of TimeType.



256
257
258
259
# File 'lib/innodb/data_type.rb', line 256

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.



254
255
256
# File 'lib/innodb/data_type.rb', line 254

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



254
255
256
# File 'lib/innodb/data_type.rb', line 254

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



261
262
263
264
265
266
# File 'lib/innodb/data_type.rb', line 261

def value(data)
  time = BinData::Int24be.read(data) ^ (-1 << 23)
  sign = "-" if time < 0
  time = time.abs
  "%s%02d:%02d:%02d" % [sign, time / 10000, (time / 100) % 100, time % 100]
end