Class: Mongoid::Metastamp::Time

Inherits:
Object
  • Object
show all
Includes:
Fields::Internal::Timekeeping, Fields::Serializable
Defined in:
lib/mongoid/metastamp/time.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(object) ⇒ Object


9
10
11
12
13
# File 'lib/mongoid/metastamp/time.rb', line 9

def deserialize(object)
  return nil if object.blank?
  return super(object) if object.instance_of?(::Time)
  super(object['time'])
end

#serialize(object) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mongoid/metastamp/time.rb', line 15

def serialize(object)
  return nil if object.blank?
  time = super(object)
  date_time = parse_datetime(object)
  { 
    time:         time,
    normalized:   normalized_time(date_time),
    year:         date_time.year,
    month:        date_time.month,
    day:          date_time.day,
    wday:         date_time.wday,
    hour:         date_time.hour,
    min:          date_time.min,
    sec:          date_time.sec,
    zone:         date_time.zone,
    offset:       date_time.utc_offset
  }.stringify_keys
end