Sha256: a12a5d49810497cd9f111e8ce30f53a47a9c121653c86a05e4936c9cbbb3b7c6

Contents?: true

Size: 886 Bytes

Versions: 2

Compression:

Stored size: 886 Bytes

Contents

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

          def type_cast_for_schema(value)
            value.acts_like?(:string) ? "'#{value}'" : super
          end


          private

          def cast_value(value)
            value = value.respond_to?(:usec) ? value : super
            return unless value
            value.change usec: cast_usec(value)
          end

          def cast_usec(value)
            return 0 if !value.respond_to?(:usec) || value.usec.zero?
            seconds = value.usec.to_f / 1_000_000.0
            ss_seconds = ((seconds * (1 / second_precision)).round / (1 / second_precision)).round(3)
            (ss_seconds * 1_000_000).to_i
          end

          def second_precision
            0.00333
          end

        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-4.2.6 lib/active_record/connection_adapters/sqlserver/type/datetime.rb
activerecord-sqlserver-adapter-4.2.5 lib/active_record/connection_adapters/sqlserver/type/datetime.rb