Sha256: 7f0faeabd92bc1174c98aa80440b734dd398153cadd321d9859e969c270ec4c4
Contents?: true
Size: 848 Bytes
Versions: 23
Compression:
Stored size: 848 Bytes
Contents
module Mongoid #:nodoc: module Extensions #:nodoc: module TimeConversions #:nodoc: def set(value) return nil if value.blank? time = convert_to_time(value) strip_milliseconds(time).utc end def get(value) return nil if value.blank? if Mongoid::Config.instance.use_utc? value else value.getlocal end end protected def strip_milliseconds(time) ::Time.at(time.to_i) end def convert_to_time(value) case value when ::String then ::Time.parse(value) when ::DateTime then ::Time.utc(value.year, value.month, value.day, value.hour, value.min, value.sec) when ::Date then ::Time.utc(value.year, value.month, value.day) else value end end end end end
Version data entries
23 entries across 23 versions & 6 rubygems