Class: Innodb::DataType::DatetimeType
- Inherits:
-
Object
- Object
- Innodb::DataType::DatetimeType
- Defined in:
- lib/innodb/data_type.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(base_type, modifiers, properties) ⇒ DatetimeType
constructor
A new instance of DatetimeType.
- #value(data) ⇒ Object
Constructor Details
#initialize(base_type, modifiers, properties) ⇒ DatetimeType
Returns a new instance of DatetimeType.
310 311 312 313 |
# File 'lib/innodb/data_type.rb', line 310 def initialize(base_type, modifiers, properties) @width = 8 @name = Innodb::DataType.make_name(base_type, modifiers, properties) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
307 308 309 |
# File 'lib/innodb/data_type.rb', line 307 def name @name end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
308 309 310 |
# File 'lib/innodb/data_type.rb', line 308 def width @width end |
Instance Method Details
#value(data) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/innodb/data_type.rb', line 315 def value(data) datetime = BinData::Int64be.read(data) ^ (-1 << 63) date = datetime / 1_000_000 year = date / 10_000 month = (date / 100) % 100 day = date % 100 time = datetime - (date * 1_000_000) hour = time / 10_000 min = (time / 100) % 100 sec = time % 100 "%04d-%02d-%02d %02d:%02d:%02d" % [year, month, day, hour, min, sec] end |