Sha256: a483ce22ad32af0f818c5124d7db641733b935f9fb3d2a721efa344842458350

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    module SQLServer
      module Type
        class DateTime < ActiveRecord::Type::DateTime

          include TimeValueFractional

          def type_cast_for_database(value)
            return super unless value.acts_like?(:time)
            value = zone_conversion(value)
            datetime = value.to_s(:_sqlserver_datetime)
            "#{datetime}".tap do |v|
              fraction = quote_fractional(value)
              v << ".#{fraction}" unless fraction.to_i.zero?
            end
          end

          def type_cast_for_schema(value)
            type_cast_for_database(value).inspect
          end


          private

          def cast_value(value)
            value = value.acts_like?(:time) ? value : super
            return unless value
            cast_fractional(value)
          end

          def zone_conversion(value)
            method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
            value.respond_to?(method) ? value.send(method) : value
          end

        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
activerecord-sqlserver-adapter-4.2.18 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.17 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.16 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter_new-4.2.15 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.15 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.13 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.12 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.11 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.10 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.9 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.8 lib/active_record/connection_adapters/sqlserver/type/datetime.rb