Class: Db2Query::Type::Timestamp

Inherits:
Value
  • Object
show all
Defined in:
lib/db2_query/type/timestamp.rb

Instance Attribute Summary

Attributes inherited from Value

#options

Instance Method Summary collapse

Methods inherited from Value

#initialize, #quote, #type_name

Constructor Details

This class inherits a constructor from Db2Query::Type::Value

Instance Method Details

#deserialize(value) ⇒ Object



25
26
27
# File 'lib/db2_query/type/timestamp.rb', line 25

def deserialize(value)
  value
end

#serialize(value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/db2_query/type/timestamp.rb', line 10

def serialize(value)
  if value.is_a?(::String)
    case value
    when  /\A(\d{4})-(\d\d)-(\d\d)-(\d\d).(\d\d).(\d\d).(\d{1,6})\z/
      quote(value)
    else
      nil
    end
  elsif value.is_a?(::DateTime) || value.is_a?(::Time)
    quote(value.strftime("%F-%H.%M.%S.%6N"))
  else
    nil
  end
end

#typeObject



6
7
8
# File 'lib/db2_query/type/timestamp.rb', line 6

def type
  :time
end