Sha256: 268589acb55fddc6400b89b37415fbd75ff4d5d7d770f503626a8b748ee0aa3e
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 KB
Contents
module ActiveRecord module ConnectionAdapters module SQLServer module Type class DateTime < ActiveRecord::Type::DateTime include TimeValueFractional def sqlserver_type 'datetime'.freeze end def serialize(value) value = super return value unless value.acts_like?(:time) datetime = value.to_s(:_sqlserver_datetime).tap do |v| fraction = quote_fractional(value) v << ".#{fraction}" end Data.new datetime, self end if defined? JRUBY_VERSION # Currently only called by our custom Time type for formatting def _formatted(value) "#{value.to_s(:_sqlserver_datetime)}.#{quote_fractional(value)}" end # @Override # We do not want the Time object to be turned into a string def serialize(value) value = super value.acts_like?(:time) ? CoreExt::Time._at_with_sql_type(value, self) : value end end def deserialize(value) value.is_a?(Data) ? super(value.value) : super end def type_cast_for_schema(value) serialize(value).quoted end def quoted(value) Utils.quote_string_single(value) end private def fast_string_to_time(string) time = ActiveSupport::TimeZone['UTC'].strptime(string, fast_string_to_time_format) new_time(time.year, time.month, time.day, time.hour, time.min, time.sec, Rational(time.nsec, 1_000)) rescue ArgumentError super end def fast_string_to_time_format "#{::Time::DATE_FORMATS[:_sqlserver_datetime]}.%N".freeze end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems