Class: StoreSchema::Converter::DateTime
- Inherits:
-
Object
- Object
- StoreSchema::Converter::DateTime
- Includes:
- Base
- Defined in:
- lib/store_schema/converter/date_time.rb
Constant Summary collapse
- DATETIME_DB_FORMAT =
Returns the database format for storing a DateTime object.
"%Y-%m-%d %H:%M:%S.%N"
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
-
#from_db ⇒ DateTime
Converts the Base#value to a Ruby-type value.
-
#to_db ⇒ String, false
Converts the Base#value to a database-storable value.
Methods included from Base
Instance Method Details
#from_db ⇒ DateTime
Converts the Base#value to a Ruby-type value.
35 36 37 |
# File 'lib/store_schema/converter/date_time.rb', line 35 def from_db ::DateTime.parse(value) end |
#to_db ⇒ String, false
Converts the Base#value to a database-storable value.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/store_schema/converter/date_time.rb', line 14 def to_db begin case value when ::DateTime, ::Date value.strftime(DATETIME_DB_FORMAT) when ::Time value.utc.strftime(DATETIME_DB_FORMAT) when ::String ::DateTime.parse(value).strftime(DATETIME_DB_FORMAT) else false end rescue false end end |