Skip to content

ActiveSupport assumes too much about how Date/DateTime are implemented, breaking some usage with home_run #766

lighthouse-import opened this Issue May 16, 2011 · 6 comments

1 participant


Imported from Lighthouse. Original ticket at:
Created by Jeremy Evans - 2010-11-25 07:22:05 UTC

ActiveSupport assumes that DateTime inherits certain methods from Date, such as -. This is true in the standard library (where dates are stored as datetimes), but not true in home_run. I think ActiveSupport should be changed so that any methods that are overridden in Date should not be assumed to be automatically overridden in DateTime, so that you are sure that DateTime objects have the same behavior. I believe that ActiveSupport overrides the following methods in Date and assumes they will be overridden in DateTime: +, -, >>.

Removing the methods from DateTime or defining them to call super will not work, because the behavior for DateTime could be different from Date (and is in home_run). However, just adding the following to the DateTime core extension should work:

class DateTime
  alias_method :plus_without_duration, :+
  alias_method :+, :plus_with_duration
  alias_method :minus_without_duration, :-
  alias_method :-, :minus_with_duration

For >>, you should probably do something similar, like defining a new method and aliasing instead of undefing, even if you don't call the previous method. That's less of an issue, though, as you aren't changing behavior. You aren't going to effect home_run's DateTime class, but as it doesn't suffer from the bug you are trying to fix, it doesn't matter much.

See for a gist of the problem. See for the issue reported on home_run's bugtracker.


Imported from Lighthouse.
Comment by Jeremy Evans - 2010-11-25 17:43:15 UTC

I'm attaching a tested patch that fixes DateTime#+ and DateTime#- to work both with and without home_run, including some new tests for it.


Imported from Lighthouse.
Comment by rails - 2011-02-26 00:00:07 UTC

This issue has been automatically marked as stale because it has not been commented on for at least three months.

The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.


Imported from Lighthouse.
Comment by Jeremy Evans - 2011-02-26 02:48:27 UTC

[state:open] This still hasn't been fixed, and the patch probably still applies. While it currently only affects people that use home_run, as soon as tadf (ruby core member) merges his switch_hitter patch (replacing the standard date/datetime library with a C extension, see, this is going to start breaking on ruby-head, so you are going to have to fix it sooner or later.


Imported from Lighthouse.
Comment by Jeremy Evans - 2011-03-29 18:45:51 UTC

This currently affects ruby-head even without home_run, since tadf merged his switch_hitter patch:

$ gem list | grep active
activesupport (3.0.5)
$ ruby -v -r date -ractive_support/all -e 'p(DateTime::parse("January 1 1943") + 1.year)'
ruby 1.9.3dev (2011-02-28 trunk 30975) [x86_64-openbsd4.9]
/home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:1358:in `plus_r': expected numeric (TypeError)
        from -e:1:in `+'
        from -e:1:in `<main>'

Imported from Lighthouse.
Comment by Jeremy Evans - 2011-03-29 18:52:33 UTC

Looks like tenderlove fixed this earlier this month (33f222b), but didn't merge it into the stable branch. Could this be merged to 3-0-stable so it makes 3.0.6?


Attachments saved to Gist:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.