Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ago (ActiveSupport::CoreExtensions::Numeric::Time) does not respect current timezone

#4076

When calling 'ago' without parameters (so: ago(time = ::Time.now)), it returns an unexpected result as the timezone is disregarded. For example, see the following session:

  Loading production environment (Rails 2.3.4)
  >> Time.now
  => Mon Mar 01 00:12:04 +0100 2010
  >> Date.today
  => Mon, 01 Mar 2010
  >> 1.month.ago(Date.today)
  => Mon, 01 Feb 2010
  >> 1.month.ago(Time.now)
  => Mon Feb 01 00:12:51 +0100 2010
  >> 1.month.ago
  => Thu, 28 Jan 2010 23:12:57 UTC +00:00

I find it very confusing that 1.month.ago is not the same as 1.month.ago(Time.now). It is not clear to me whether this is a feature or a bug, but imo it should be changed.

Reported by Reinier de Lange · March 1st, 2010 @ 09:25 AM

State: wontfix
Milestone: none
Importance: Low

Activity

  1. José Valim
    José Valim

    Please provide a patch.

    March 3rd, 2010 @ 08:50 AM

  2. Roel van der Hoorn
  3. Simon Garcia
    Simon Garcia

    It's not a bug. Time conversions use ActiveSupport::Duration which relies on Time.current which returns Time.zone.now or Time.now depending if Time.zone_default is defined which can be done on environment.rb

    April 10th, 2010 @ 08:45 AM

  4. Nathaniel Bibler
    Nathaniel Bibler

    I agree with the author that this is unexpected and not a well known task that must be performed (setting Time.zone_default), but Simon's suggestion does fix the issue and makes sense to me.

    April 11th, 2010 @ 04:08 AM

  5. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • Assigned user set to Prem Sichanugrist (sikachu)
    • Importance changed from to Low

    September 10th, 2010 @ 03:58 PM

  6. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • State changed from new to wontfix

    I was so tempted to write a patch for this one. However, it seems like it was changed from Time.now to Time.current in this commit:

    http://github.com/rails/rails/commit/32b82e4c

    So, I'd say that I'll leave it as-is. In order for ago to return the correct time zone, you must set the corresponding config.time_zone in application.rb (or environment.rb in Rails 2.3)

    September 10th, 2010 @ 04:33 PM