Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime

Inherits:
Type::DateTime show all
Defined in:
activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb

Overview

:nodoc:

Direct Known Subclasses

Timestamp, TimestampWithTimeZone

Instance Attribute Summary

Attributes inherited from ActiveModel::Type::Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Type::Internal::Timezone

#default_timezone, #initialize, #is_utc?

Methods inherited from ActiveModel::Type::DateTime

#type

Methods included from ActiveModel::Type::Helpers::TimeValue

#apply_seconds_precision, #serialize_cast_value, #user_input_in_time_zone

Methods included from ActiveModel::Type::Helpers::Timezone

#default_timezone, #is_utc?

Methods inherited from ActiveModel::Type::Value

#==, #as_json, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #deserialize, #force_equality?, #hash, #immutable_value, #initialize, #map, #serializable?, #serialize, #type, #value_constructed_by_mass_assignment?

Instance Method Details

#cast_value(value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb', line 8

def cast_value(value)
  case value
  when "infinity" then ::Float::INFINITY
  when "-infinity" then -::Float::INFINITY
  when / BC$/
    value = value.sub(/^\d+/) { |year| format("%04d", -year.to_i + 1) }
    super(value.delete_suffix!(" BC"))
  else
    super
  end
end

#type_cast_for_schema(value) ⇒ Object



20
21
22
23
24
25
26
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb', line 20

def type_cast_for_schema(value)
  case value
  when ::Float::INFINITY then "::Float::INFINITY"
  when -::Float::INFINITY then "-::Float::INFINITY"
  else super
  end
end