Created
August 19, 2011 14:13
-
-
Save shaunoconnell/1156890 to your computer and use it in GitHub Desktop.
Fix for dates with jruby on rails and mssqladapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'arjdbc/mssql/adapter' | |
# I think this is just a hack for mssqlserver 2008 | |
module ::ArJdbc | |
module MsSQL | |
module Column | |
def cast_to_time(value) | |
return value if value.is_a?(Time) | |
begin | |
value_as_time = Time.parse value | |
return value_as_time if value_as_time.is_a?(Time) | |
end | |
time_array = ParseDate.parsedate(value) | |
return nil if !time_array.any? | |
time_array[0] ||= 2000 | |
time_array[1] ||= 1 | |
time_array[2] ||= 1 | |
return Time.send(ActiveRecord::Base.default_timezone, *time_array) rescue nil | |
# Try DateTime instead - the date may be outside the time period support by Time. | |
DateTime.new(*time_array[0..5]) rescue nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment