All,
= Rails 1.2.6
I’ve been down this road of not being able to get the SQLServer AR
driver to support pre-1970 SQLServer datetime fields before back in
Rails 1.1.6 (Selecting datetime values from SQL Server (year < 1970) - Rails - Ruby-Forum), but now I’m finally
updating this app. to Rails 1.2 and beyond.
So…below is a patch to the current 1.0.0 version of
sqlserver_adapter.rb (from the new separate AR adapter Rails 2.0-style
gem) that appears (in my app. so far) to successfully allow for the
successful manipulation of < 1970 datetime values in Rails. It requires
mods. to both the “cast_to_datetime” and “string_to_time” methods, and
as you can see, simply returns DateTime objects instead of Time objects
(which are limited to 1970 and later).
I’m not sure why the casts to time are there in the first place - my
guess is that the way that MySQL handles dates influences how this
SQLServer driver is handling dates.
I will try and make time to set up a proper patch submission in Trac at
some point, but really pressed for time these days.
Thanks,
Wes
---- BEGIN PATCH ----
Index: sqlserver_adapter.rb
— sqlserver_adapter.rb (revision 8940)
+++ sqlserver_adapter.rb (working copy)
@@ -104,8 +104,7 @@
end
if value.is_a?(DateTime)
-
return Time.mktime(value.year, value.mon, value.day,
value.hour, valu
e.min, value.sec)
-
#return DateTime.new(value.year, value.mon, value.day,
value.hour, va
lue.min, value.sec)
-
return DateTime.new(value.year, value.mon, value.day,
value.hour, val
ue.min, value.sec)
end
return cast_to_time(value) if value.is_a?(Date) or
value.is_a?(String)
rescue nil
@@ -116,7 +115,7 @@
def self.string_to_time(value)
if value.is_a?(DateTime)
-
return Time.mktime(value.year, value.mon, value.day,
value.hour, valu
e.min, value.sec)
-
return DateTime.new(value.year, value.mon, value.day,
value.hour, val
ue.min, value.sec)
else
super
end
---- END PATCH ----