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.
283 284 285 286 |
# File 'lib/innodb/data_type.rb', line 283 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.
281 282 283 |
# File 'lib/innodb/data_type.rb', line 281 def name @name end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
281 282 283 |
# File 'lib/innodb/data_type.rb', line 281 def width @width end |
Instance Method Details
#value(data) ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/innodb/data_type.rb', line 288 def value(data) datetime = BinData::Int64be.read(data) ^ (-1 << 63) date = datetime / 1000000 year, month, day = [date / 10000, (date / 100) % 100, date % 100] time = datetime - (date * 1000000) hour, min, sec = [time / 10000, (time / 100) % 100, time % 100] "%04d-%02d-%02d %02d:%02d:%02d" % [year, month, day, hour, min, sec] end |