Class: MongoModel::Types::DateTime
- Defined in:
- lib/mongomodel/support/types/date_time.rb
Instance Method Summary collapse
Methods inherited from Object
Instance Method Details
#cast(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mongomodel/support/types/date_time.rb', line 7 def cast(value) case value when ::Array ::DateTime.civil(*value) when ::Hash cast("#{value[:date]} #{value[:time]}") when ::String cast(::DateTime.parse(value)) else round_microseconds(value.to_datetime.utc) if value end rescue nil end |
#from_mongo(t) ⇒ Object
26 27 28 |
# File 'lib/mongomodel/support/types/date_time.rb', line 26 def from_mongo(t) ::DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec + Rational(t.usec, 1000000)) if t end |
#to_mongo(value) ⇒ Object
22 23 24 |
# File 'lib/mongomodel/support/types/date_time.rb', line 22 def to_mongo(value) to_time(value.utc) if value end |