This project is archived and is in readonly mode.
ago (ActiveSupport::CoreExtensions::Numeric::Time) does not respect current timezone
Reported by Reinier de Lange | March 1st, 2010 @ 09:25 AM
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.
Comments and changes to this ticket
-
Roel van der Hoorn March 3rd, 2010 @ 09:59 AM
- Tag set to 2.3.6
-
Simon Garcia April 10th, 2010 @ 08:45 AM
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
-
Nathaniel Bibler April 11th, 2010 @ 04:08 AM
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.
-
Prem Sichanugrist (sikachu) September 10th, 2010 @ 03:58 PM
- Assigned user set to Prem Sichanugrist (sikachu)
- Importance changed from to Low
-
Prem Sichanugrist (sikachu) September 10th, 2010 @ 04:33 PM
- 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
toTime.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 correspondingconfig.time_zone
in application.rb (or environment.rb in Rails 2.3)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Tags
Referenced by
- 5607 Use `Time.current` in AS::CoreExtensions::Numeric::Time to maintain consistency with AS::Duration After I was investigate with #4076, I found out that ago ...