File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
lib/active_record/connection_adapters/sqlserver/type Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,16 @@ module TimeValueFractional
1010 def apply_seconds_precision ( value )
1111 return value if !value . respond_to? ( fractional_property ) || value . send ( fractional_property ) . zero?
1212 value . change fractional_property => seconds_precision ( value )
13+
14+ millis = seconds_precision ( value ) . to_i
15+ value = value . change fractional_property => millis % fractional_operator
16+ value + millis / fractional_operator
1317 end
1418
1519 def seconds_precision ( value )
1620 return 0 if fractional_scale == 0
1721 seconds = value . send ( fractional_property ) . to_d / fractional_operator . to_d
18- seconds = ( ( seconds * ( 1 / fractional_precision ) ) . round / ( 1 / fractional_precision ) ) . truncate ( fractional_scale )
22+ seconds = ( ( seconds / fractional_precision ) . round * fractional_precision ) . round ( fractional_scale )
1923 ( seconds * fractional_operator ) . round ( 0 ) . to_i
2024 end
2125
@@ -39,7 +43,7 @@ def fractional_operator
3943 end
4044
4145 def fractional_precision
42- BigDecimal ( '0.00333 ' )
46+ BigDecimal ( '0.003333 ' )
4347 end
4448
4549 def fractional_scale
Original file line number Diff line number Diff line change @@ -223,14 +223,14 @@ class QuoteARBaseTest < ActiveRecord::TestCase
223223 coerce_tests! :test_quote_ar_object
224224 def test_quote_ar_object_coerced
225225 value = DatetimePrimaryKey . new ( id : @time )
226- assert_equal "'02-14-2017 12:34:56.789 '" , @connection . quote ( value )
226+ assert_equal "'02-14-2017 12:34:56.79 '" , @connection . quote ( value )
227227 end
228228
229229 # Use our date format.
230230 coerce_tests! :test_type_cast_ar_object
231231 def test_type_cast_ar_object_coerced
232232 value = DatetimePrimaryKey . new ( id : @time )
233- assert_equal "02-14-2017 12:34:56.789 " , @connection . type_cast ( value )
233+ assert_equal "02-14-2017 12:34:56.79 " , @connection . type_cast ( value )
234234 end
235235
236236 end
You can’t perform that action at this time.
0 commit comments