File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
connection_adapters/abstract Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,10 @@ def quoted_date(value)
146
146
end
147
147
end
148
148
149
+ def quoted_time ( value ) # :nodoc:
150
+ quoted_date ( value ) . sub ( /\A 2000-01-01 / , '' )
151
+ end
152
+
149
153
def prepare_binds_for_database ( binds ) # :nodoc:
150
154
binds . map ( &:value_for_database )
151
155
end
@@ -166,6 +170,7 @@ def _quote(value)
166
170
# BigDecimals need to be put in a non-normalized form and quoted.
167
171
when BigDecimal then value . to_s ( 'F' )
168
172
when Numeric , ActiveSupport ::Duration then value . to_s
173
+ when Type ::Time ::Value then "'#{ quoted_time ( value ) } '"
169
174
when Date , Time then "'#{ quoted_date ( value ) } '"
170
175
when Symbol then "'#{ quote_string ( value . to_s ) } '"
171
176
when Class then "'#{ value } '"
@@ -181,6 +186,7 @@ def _type_cast(value)
181
186
when false then unquoted_false
182
187
# BigDecimals need to be put in a non-normalized form and quoted.
183
188
when BigDecimal then value . to_s ( 'F' )
189
+ when Type ::Time ::Value then quoted_time ( value )
184
190
when Date , Time then quoted_date ( value )
185
191
when *types_which_need_no_typecasting
186
192
value
Original file line number Diff line number Diff line change @@ -2,6 +2,18 @@ module ActiveRecord
2
2
module Type
3
3
class Time < ActiveModel ::Type ::Time
4
4
include Internal ::Timezone
5
+
6
+ class Value < DelegateClass ( ::Time ) # :nodoc:
7
+ end
8
+
9
+ def serialize ( value )
10
+ case value = super
11
+ when ::Time
12
+ Value . new ( value )
13
+ else
14
+ value
15
+ end
16
+ end
5
17
end
6
18
end
7
19
end
Original file line number Diff line number Diff line change @@ -44,7 +44,6 @@ def test_invalid_time_precision_raises_error
44
44
end
45
45
46
46
def test_formatting_time_according_to_precision
47
- skip ( "TIME column on MariaDB doesn't ignore the date part of the string when it coerces to time" ) if current_adapter? ( :Mysql2Adapter ) && ActiveRecord ::Base . connection . mariadb?
48
47
@connection . create_table ( :foos , force : true ) do |t |
49
48
t . time :start , precision : 0
50
49
t . time :finish , precision : 4
You can’t perform that action at this time.
0 commit comments