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.



275
276
277
278
# File 'lib/innodb/data_type.rb', line 275

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.



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

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



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

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