Class: ActiveRecord::ConnectionAdapters::MSSQL::Type::DateTime2

Inherits:
Type::DateTime
  • Object
show all
Defined in:
lib/arjdbc/mssql/types/date_and_time_types.rb

Instance Method Summary collapse

Instance Method Details

#apply_seconds_precision(value) ⇒ Object

Overrides method in a super class (located in active model)



23
24
25
26
27
28
29
# File 'lib/arjdbc/mssql/types/date_and_time_types.rb', line 23

def apply_seconds_precision(value)
  return value unless ar_precision && value.respond_to?(:usec)

  number_of_insignificant_digits = 6 - ar_precision
  round_power = 10**number_of_insignificant_digits
  value.change(usec: value.usec / round_power * round_power)
end

#type_cast_for_schema(value) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/arjdbc/mssql/types/date_and_time_types.rb', line 12

def type_cast_for_schema(value)
  return %("#{value}") if value.acts_like?(:string)

  if value.usec > 0
    %("#{value.to_s(:db)}.#{value.usec.to_s.remove(/0+$/)}")
  else
    %("#{value.to_s(:db)}")
  end
end