Class: ActiveModel::Type::Time

Inherits:
Value show all
Includes:
Helpers::TimeValue, Helpers::Timezone
Defined in:
activemodel/lib/active_model/type/time.rb

Overview

:nodoc:

Direct Known Subclasses

ActiveRecord::Type::Time

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Helpers::TimeValue

#apply_seconds_precision, #serialize, #type_cast_for_schema

Methods included from Helpers::Timezone

#default_timezone, #is_utc?

Methods inherited from Value

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

Constructor Details

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

Instance Method Details

#typeObject



12
13
14
# File 'activemodel/lib/active_model/type/time.rb', line 12

def type
  :time
end

#user_input_in_time_zone(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'activemodel/lib/active_model/type/time.rb', line 16

def user_input_in_time_zone(value)
  return unless value.present?

  case value
  when ::String
    value = "2000-01-01 #{value}"
    time_hash = ::Date._parse(value)
    return if time_hash[:hour].nil?
  when ::Time
    value = value.change(year: 2000, day: 1, month: 1)
  end

  super(value)
end