Sha256: 9e05ec7e7a263f30111df59ae35d9c29196c64b84189a24a16cb6f778e8e18df

Contents?: true

Size: 972 Bytes

Versions: 11

Compression:

Stored size: 972 Bytes

Contents

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

          include TimeValueFractional2

          def type_cast_for_database(value)
            return super unless value.acts_like?(:time)
            time = value.to_s(:_sqlserver_time)
            "#{time}".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 if value.blank?
            value = value.change year: 2000, month: 01, day: 01
            cast_fractional(value)
          end

          def fractional_scale
            precision
          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/time.rb
activerecord-sqlserver-adapter-4.2.17 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.16 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter_new-4.2.15 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.15 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.13 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.12 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.11 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.10 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.9 lib/active_record/connection_adapters/sqlserver/type/time.rb
activerecord-sqlserver-adapter-4.2.8 lib/active_record/connection_adapters/sqlserver/type/time.rb