Class: Innodb::DataType::TimestampType

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

Returns a new instance of TimestampType.



333
334
335
336
# File 'lib/innodb/data_type.rb', line 333

def initialize(base_type, modifiers, properties)
  @width = 4
  @name = Innodb::DataType.make_name(base_type, modifiers, properties)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



330
331
332
# File 'lib/innodb/data_type.rb', line 330

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



331
332
333
# File 'lib/innodb/data_type.rb', line 331

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object

Returns the UTC timestamp as a value in ‘YYYY-MM-DD HH:MM:SS’ format.



339
340
341
342
343
344
# File 'lib/innodb/data_type.rb', line 339

def value(data)
  timestamp = BinData::Uint32be.read(data)
  return "0000-00-00 00:00:00" if timestamp.zero?

  DateTime.strptime(timestamp.to_s, "%s").strftime "%Y-%m-%d %H:%M:%S"
end