Module: ActiveModel::Type::Helpers::TimeValue
Instance Method Summary collapse
- #apply_seconds_precision(value) ⇒ Object
- #serialize(value) ⇒ Object
- #type_cast_for_schema(value) ⇒ Object
- #user_input_in_time_zone(value) ⇒ Object
Instance Method Details
#apply_seconds_precision(value) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/active_model/type/helpers/time_value.rb', line 24 def apply_seconds_precision(value) return value unless precision && value.respond_to?(:usec) number_of_insignificant_digits = 6 - precision round_power = 10**number_of_insignificant_digits value.change(usec: value.usec - value.usec % round_power) end |
#serialize(value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_model/type/helpers/time_value.rb', line 10 def serialize(value) value = apply_seconds_precision(value) if value.acts_like?(:time) zone_conversion_method = is_utc? ? :getutc : :getlocal if value.respond_to?(zone_conversion_method) value = value.send(zone_conversion_method) end end value end |
#type_cast_for_schema(value) ⇒ Object
31 32 33 |
# File 'lib/active_model/type/helpers/time_value.rb', line 31 def type_cast_for_schema(value) value.to_s(:db).inspect end |
#user_input_in_time_zone(value) ⇒ Object
35 36 37 |
# File 'lib/active_model/type/helpers/time_value.rb', line 35 def user_input_in_time_zone(value) value.in_time_zone end |