Sha256: 5a4afd44835096ce1faafe469b0ffd1be01dc49de3c8fa95336b5d91e057a2aa

Contents?: true

Size: 755 Bytes

Versions: 6

Compression:

Stored size: 755 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      module OID # :nodoc:
        class TimestampWithTimeZone < DateTime # :nodoc:
          def type
            real_type_unless_aliased(:timestamptz)
          end

          def cast_value(value)
            time = super
            return time if time.is_a?(ActiveSupport::TimeWithZone)

            # While in UTC mode, the PG gem may not return times back in "UTC" even if they were provided to Postgres in UTC.
            # We prefer times always in UTC, so here we convert back.
            if is_utc?
              time.getutc
            else
              time.getlocal
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activerecord-7.0.0 lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb
activerecord-7.0.0.rc3 lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb
activerecord-7.0.0.rc2 lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb
activerecord-7.0.0.rc1 lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb
activerecord-7.0.0.alpha2 lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb
activerecord-7.0.0.alpha1 lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb