jeremyevans / home_run

Fast Date/DateTime classes for ruby :: Unmaintained, unnecessary on ruby 1.9.3+
Other
465 stars 10 forks source link

home_run and ActiveSupport 3.0 dependencies #34

Closed pivotalcommon closed 13 years ago

pivotalcommon commented 13 years ago

We've gone down the rabbit hole a little more.

deep breath

The issue with ActiveSupport and home_run is that ActiveSupport assumes that DateTime object inherits its base from Date object. ActiveSupport modifies Date object plus and minus methods to handle duration objects (1.day, 2.hours, etc).

When looking at date.rb in the base Ruby 1.9.2 implementation, DateTime does inherit from Date.

home_run declares the DateTime object and Date objects as two separate entities.

A lot of these issues could be corrected if home_run's DateTime object inherited correctly from Date. My only gotchya for this would that DateTime should not have certain methods defined for it because it should naturally inherit them from the Date object. Please see date.rb in Ruby 1.9.2 for those methods.

These are the default DateTime methods that are actually defined for DateTime, everything else appears to be inherited from Date object.

require "date"
DateTime.methods - Date.methods
=> [:now] 
DateTime.instance_methods - Date.instance_methods
=> [:hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset, :minute, :second, :second_fraction]
DateTime.private_methods - Date.private_methods
=> [:today]

etc....

jeremyevans commented 13 years ago

This behavior is not a bug, it's by design. Note that ruby 1.9.3's date/datetime implementation (switch_hitter) has the same issue. This is an ActiveSupport bug, which they fixed in trunk but didn't backport to 3.0-stable. This is the patch that they need to backport:

https://github.com/rails/rails/commit/33f222b9e1b20aa6264084ec2c8c3206e1c2d598#activesupport/lib/active_support/core_ext/date_time/calculations.rb

You could ask ActiveSupport maintainers to backport that commit to 3.0-stable, since it's their bug. They shouldn't be depending on DateTime inheriting methods from Date versus DateTime implementing the methods itself. That's an internal implementation detail.

I actually added a bug for this to Rails lighthouse late last year (before they switched to GitHub Issues): https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6062 . I guess I just didn't get enough +1s.