@@ -131,58 +131,9 @@ def is_special?
131131 def is_utf8?
132132 sql_type =~ /nvarchar|ntext|nchar|nvarchar(max)/i
133133 end
134-
135- def type_cast ( value )
136- return nil if value . nil?
137- case type
138- when :datetime then self . class . cast_to_datetime ( value )
139- when :timestamp then self . class . cast_to_time ( value )
140- when :time then self . class . cast_to_time ( value )
141- when :date then self . class . cast_to_datetime ( value )
142- else super
143- end
144- end
145-
146- def type_cast_code ( var_name )
147- case type
148- when :datetime then "#{ self . class . name } .cast_to_datetime(#{ var_name } )"
149- when :timestamp then "#{ self . class . name } .cast_to_time(#{ var_name } )"
150- when :time then "#{ self . class . name } .cast_to_time(#{ var_name } )"
151- when :date then "#{ self . class . name } .cast_to_datetime(#{ var_name } )"
152- else super
153- end
154- end
155134
156135 class << self
157136
158- def cast_to_datetime ( value )
159- return value . to_time if value . is_a? ( DBI ::Timestamp )
160- return string_to_time ( value ) if value . is_a? ( Time )
161- return string_to_time ( value ) if value . is_a? ( DateTime )
162- return cast_to_time ( value ) if value . is_a? ( String )
163- value
164- end
165-
166- def cast_to_time ( value )
167- return value if value . is_a? ( Time )
168- time_hash = Date . _parse ( value )
169- time_hash [ :sec_fraction ] = 0 # REVISIT: microseconds(time_hash)
170- new_time ( *time_hash . values_at ( :year , :mon , :mday , :hour , :min , :sec , :sec_fraction ) ) rescue nil
171- end
172-
173- def string_to_time ( value )
174- if value . is_a? ( DateTime ) || value . is_a? ( Time )
175- # The DateTime comes in as '2008-08-08T17:57:28+00:00'
176- # Original code was taking a UTC DateTime, ignored the time zone by
177- # creating a localized Time object, ex: 'FRI Aug 08 17:57:28 +04 2008'
178- # Instead, let Time.parse translate the DateTime string including it's timezone
179- # If Rails is UTC, call .utc, otherwise return a local time value
180- return Base . default_timezone == :utc ? Time . parse ( value . to_s ) . utc : Time . parse ( value . to_s )
181- else
182- super
183- end
184- end
185-
186137 def string_to_binary ( value )
187138 "0x#{ value . unpack ( "H*" ) [ 0 ] } "
188139 end
@@ -191,14 +142,6 @@ def binary_to_string(value)
191142 value =~ /[^[:xdigit:]]/ ? value : [ value ] . pack ( 'H*' )
192143 end
193144
194- protected
195-
196- def new_time ( year , mon , mday , hour , min , sec , microsec = 0 )
197- # Treat 0000-00-00 00:00:00 as nil.
198- return nil if year . nil? || year == 0
199- Time . time_with_datetime_fallback ( Base . default_timezone , year , mon , mday , hour , min , sec , microsec ) rescue nil
200- end
201-
202145 end #class << self
203146
204147 private
0 commit comments