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:

Instance Attribute Summary

Attributes inherited from ActiveModel::Type::Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Type::Internal::Timezone

#default_timezone, #is_utc?

Methods inherited from ActiveModel::Type::DateTime

#type

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

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

Methods inherited from ActiveModel::Type::Value

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

Constructor Details

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

Instance Method Details

#cast_value(value) ⇒ Object


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

def cast_value(value)
  case value
  when 'infinity' then ::Float::INFINITY
  when '-infinity' then -::Float::INFINITY
  when / BC$/
    astronomical_year = format("%04d", -value[/^\d+/].to_i + 1)
    super(value.sub(/ BC$/, "").sub(/^\d+/, astronomical_year))
  else
    super
  end
end