Class: MongoModel::Types::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomodel/support/types/time.rb

Instance Method Summary (collapse)

Methods inherited from Object

#boolean, #to_query

Instance Method Details

- (Object) cast(value)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mongomodel/support/types/time.rb', line 8

def cast(value)
  case value
  when ::Array
    base = ::Time.zone ? ::Time.zone : ::Time
    base.local(*value)
  when ::String
    base = ::Time.zone ? ::Time.zone : ::Time
    cast(base.parse(value))
  when ::Hash
    cast("#{value[:date]} #{value[:time]}")
  else
    time = value.to_time.in_time_zone
    time.change(:usec => (time.usec / 1000.0).floor * 1000)
  end
rescue
  nil
end

- (Object) from_mongo(value)



30
31
32
# File 'lib/mongomodel/support/types/time.rb', line 30

def from_mongo(value)
  value.in_time_zone if value
end

- (Object) to_mongo(value)



26
27
28
# File 'lib/mongomodel/support/types/time.rb', line 26

def to_mongo(value)
  value.utc if value
end