Module: ActiveModel::Type::Helpers::TimeValue
    Do not use.  This module is for internal use only.
  
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
| 
       Included In: 
      ::ActiveModel::Type::DateTime,
          ::ActiveModel::Type::Time,
          ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime,
          ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp,
          ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone,
          ::ActiveRecord::Type::DateTime,
          ::ActiveRecord::Type::Time
       | |
| Defined in: | activemodel/lib/active_model/type/helpers/time_value.rb | 
Constant Summary
- 
    ISO_DATETIME =
    
# File 'activemodel/lib/active_model/type/helpers/time_value.rb', line 64/ \A (\d{4})-(\d\d)-(\d\d)(?:T|\s) # 2020-06-20T (\d\d):(\d\d):(\d\d)(?:\.(\d{1,6})\d*)? # 10:20:30.123456 (?:(Z(?=\z)|[+-]\d\d)(?::?(\d\d))?)? # +09:00 \z /x 
Instance Method Summary
- #apply_seconds_precision(value)
 - #serialize_cast_value(value)
 - #type_cast_for_schema(value)
 - #user_input_in_time_zone(value)
 - 
    
      #fast_string_to_time(string)  
    
    private
    
BUG: Wrapping the
::ActiveModel::Type::Timeobject with Time.at becauseTime.newwithin:in Ruby 3.2.0 used to return an invalid::ActiveModel::Type::Timeobject see: bugs.ruby-lang.org/issues/19292. - #new_time(year, mon, mday, hour, min, sec, microsec, offset = nil) private
 
Instance Method Details
#apply_seconds_precision(value)
[ GitHub ]# File 'activemodel/lib/active_model/type/helpers/time_value.rb', line 24
def apply_seconds_precision(value) return value unless precision && value.respond_to?(:nsec) number_of_insignificant_digits = 9 - precision round_power = 10**number_of_insignificant_digits rounded_off_nsec = value.nsec % round_power if rounded_off_nsec > 0 value.change(nsec: value.nsec - rounded_off_nsec) else value end end
#fast_string_to_time(string) (private)
BUG: Wrapping the ::ActiveModel::Type::Time object with Time.at because Time.new with in: in Ruby 3.2.0 used to return an invalid ::ActiveModel::Type::Time object see: bugs.ruby-lang.org/issues/19292
See additional method definition at line 76.
#new_time(year, mon, mday, hour, min, sec, microsec, offset = nil) (private)
[ GitHub ]# File 'activemodel/lib/active_model/type/helpers/time_value.rb', line 47
def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil) # Treat 0000-00-00 00:00:00 as nil. return if year.nil? || (year == 0 && mon == 0 && mday == 0) if offset time = ::Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil return unless time time -= offset unless offset == 0 is_utc? ? time : time.getlocal elsif is_utc? ::Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil else ::Time.local(year, mon, mday, hour, min, sec, microsec) rescue nil end end
#serialize_cast_value(value)
[ GitHub ]# File 'activemodel/lib/active_model/type/helpers/time_value.rb', line 10
def serialize_cast_value(value) value = apply_seconds_precision(value) if value.acts_like?(:time) if is_utc? value = value.getutc if !value.utc? else value = value.getlocal end end value end
#type_cast_for_schema(value)
[ GitHub ]# File 'activemodel/lib/active_model/type/helpers/time_value.rb', line 38
def type_cast_for_schema(value) value.to_fs(:db).inspect end
#user_input_in_time_zone(value)
[ GitHub ]# File 'activemodel/lib/active_model/type/helpers/time_value.rb', line 42
def user_input_in_time_zone(value) value.in_time_zone end