Class: ActiveModel::Type::Time

Inherits:
Value
  • Object
show all
Includes:
Helpers::TimeValue
Defined in:
lib/active_model/type/time.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Helpers::TimeValue

#apply_seconds_precision, #default_timezone, #is_utc?, #serialize, #type_cast_for_schema

Methods inherited from Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #deserialize, #hash, #initialize, #map, #serialize, #type_cast_for_schema

Constructor Details

This class inherits a constructor from ActiveModel::Type::Value

Instance Method Details

#typeObject



9
10
11
# File 'lib/active_model/type/time.rb', line 9

def type
  :time
end

#user_input_in_time_zone(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_model/type/time.rb', line 13

def user_input_in_time_zone(value)
  return unless value.present?

  case value
  when ::String
    value = "2000-01-01 #{value}"
  when ::Time
    value = value.change(year: 2000, day: 1, month: 1)
  end

  super(value)
end