class StoreSchema::Converter::DateTime
Constants
- DATETIME_DB_FORMAT
@return [String] the database format for storing a
DateTime
object.
Public Instance Methods
from_db()
click to toggle source
Converts the {#value} to a Ruby-type value.
@return [DateTime]
# File lib/store_schema/converter/date_time.rb, line 34 def from_db ::DateTime.parse(value) end
to_db()
click to toggle source
Converts the {#value} to a database-storable value.
@return [String, false] false if {#value} is an invalid date-type.
# File lib/store_schema/converter/date_time.rb, line 15 def to_db 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