Class: Db2Query::Type::Date
- Inherits:
-
Value
- Object
- Value
- Db2Query::Type::Date
show all
- Defined in:
- lib/db2_query/type/date.rb
Constant Summary
collapse
- YMD_DATE =
/\A(\d{4})-(\d\d)-(\d\d)\z/
- DMY_DATE =
/\A(\d\d)-(\d\d)-(\d{4})\z/
Instance Attribute Summary
Attributes inherited from Value
#options
Instance Method Summary
collapse
Methods inherited from Value
#initialize, #quote, #type_name
Instance Method Details
#deserialize(value) ⇒ Object
29
30
31
|
# File 'lib/db2_query/type/date.rb', line 29
def deserialize(value)
::Date.parse(value.to_s)
end
|
#serialize(value) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/db2_query/type/date.rb', line 13
def serialize(value)
if value.is_a?(::String)
value = value.tr("/", "-")
case value
when YMD_DATE, DMY_DATE
quote(::Date.parse(value))
else
nil
end
elsif value.is_a?(::Date)
quote(value.strftime("%F"))
else
nil
end
end
|
#type ⇒ Object
6
7
8
|
# File 'lib/db2_query/type/date.rb', line 6
def type
:string
end
|