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.



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

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.



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

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



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

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