@@ -11,8 +11,9 @@ def sqlserver_type
1111 end
1212
1313 def serialize ( value )
14- return super unless value . acts_like? ( :time )
15- datetime = super . to_s ( :_sqlserver_datetime ) . tap do |v |
14+ value = super
15+ return value unless value . acts_like? ( :time )
16+ datetime = value . to_s ( :_sqlserver_datetime ) . tap do |v |
1617 fraction = quote_fractional ( value )
1718 v << ".#{ fraction } "
1819 end
@@ -34,9 +35,7 @@ def quoted(value)
3435 private
3536
3637 def cast_value ( value )
37- value = value . acts_like? ( :time ) ? value : super
38- return unless value
39- apply_seconds_precision ( value )
38+ super . try ( :in_time_zone )
4039 end
4140
4241 def fast_string_to_time ( string )
@@ -53,6 +52,20 @@ def fast_string_to_time_zone
5352 ::Time . zone || ActiveSupport ::TimeZone . new ( 'UTC' )
5453 end
5554
55+ # Copy of module ActiveModel::Type::Helpers::TimeValue with
56+ # else condition using a zone for local parsing.
57+ def new_time ( year , mon , mday , hour , min , sec , microsec , offset = nil )
58+ return if year . nil? || ( year == 0 && mon == 0 && mday == 0 )
59+ if offset
60+ time = ::Time . utc ( year , mon , mday , hour , min , sec , microsec ) rescue nil
61+ return unless time
62+ time -= offset
63+ is_utc? ? time : time . getlocal
64+ else
65+ fast_string_to_time_zone . local ( year , mon , mday , hour , min , sec , microsec ) rescue nil
66+ end
67+ end
68+
5669 end
5770 end
5871 end
0 commit comments