This project is archived and is in readonly mode.
distance_of_time_in_words displays Rational instead of integer
-
Rohit Arondekar
- State changed from new to stale
- Importance changed from to Low
Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.
-
Corey
From the latest 2.3.x release:
$ script/console Loading development environment (Rails 2.3.9) >> from_time = Time.now => Thu Oct 07 18:20:30 -0700 2010 >> helper.distance_of_time_in_words(from_time, from_time + 1.year + 3.days) => "about 1 year" >> require 'mathn' => ["Prime"] >> helper.distance_of_time_in_words(from_time, from_time + 1.year + 3.days) => "about 368/365 years" >>From the latest Rails release:
$ rails console Loading development environment (Rails 3.0.0) >> from_time = Time.now => Thu Oct 07 18:28:08 -0700 2010 >> helper.distance_of_time_in_words(from_time, from_time + 1.year + 3.days) => "about 1 year" >> require 'mathn' => ["Prime"] >> helper.distance_of_time_in_words(from_time, from_time + 1.year + 3.days) => "about 368/365 years" >>I wanted to add a test case that would illustrate the problem. However, as it turned out requiring 'mathn' in the date_helper_test.rb also had it loaded for all of the tests that run after it and some of those then also failed. I don't know how to sandbox the loading of 'mathn' in the test suite so that other tests aren't affected.
However, for Fixnums the methods / and div give the same result, and that changing from / to div ensures that mathn's Rationals are not returned. I've created a patch from 2-3-stable which does that for distance_of_time_in_words and attached it.
-
Rohit Arondekar
- State changed from stale to open
Wait, so mathn is redefining '/'? I think then it's the gems fault and not Rails. I mean Rails shouldn't change because of this. Still, opening ticket to get a consensus on this issue. Thanks for the reply!
-
Corey
Unfortunately, in my application I'm not loading 'mathn' directly, some gem I just happen to use is loading it. Everything was ok for me with until this change to the DateHelper.
Just for reference, here's the Ruby issue related to mathn's behavior.
-
Ryan Bigg
Automatic cleanup of spam.
