This project is archived and is in readonly mode.
#localtime fails for TimeWithZone-wrapped DateTimes
Reported by John Firebaugh | August 10th, 2010 @ 01:13 AM | in 3.0.2
Simple test case:
DateTime.now.in_time_zone.localtime
# => NoMethodError: undefined method `getlocal' for Mon, 09 Aug 2010 23:59:31 +0000:DateTime
from /Users/jfire/.rvm/gems/jruby-1.5.1/gems/activesupport-3.0.0.rc/lib/active_support/time_with_zone.rb:75:in `localtime'
from (irb):25
Comments and changes to this ticket
-
chrispanda August 30th, 2010 @ 06:21 PM
I am also seeing this error with ruby 1.9.2
DateTime.now.in_time_zone.localtime
NoMethodError: undefined methodgetlocal' for Mon, 30 Aug 2010 13:28:15 +0000:DateTime<br/>
from /home/chris/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0.rc/lib/active_support/time_with_zone.rb:75:in `localtime' from (irb):1
-
MikZ September 10th, 2010 @ 03:13 PM
- Tag set to datetime, method_missing, timewithzone, timezone
Same problem here.
I'm unable to save records with time zone.
ruby-1.9.2-p0 > new.class ActiveSupport::TimeWithZone < Object ruby-1.9.2-p0 > new Thu, 16 Sep 2010 18:00:00 CEST +02:00 ruby-1.9.2-p0 > new.localtime NoMethodError: undefined method `getlocal' for Thu, 16 Sep 2010 16:00:00 +0000:DateTime from /Users/mikz/.rvm/gems/ruby-1.9.2-p0@avion-is/gems/activesupport-3.0.0/lib/active_support/time_with_zone.rb:75:in `localtime' from (irb):14
-
MikZ September 10th, 2010 @ 03:28 PM
Meanwhile you can use this workaround:
class DateTime def getlocal
self.to_time.getlocal.to_datetime
end end -
Álvaro Bautista September 11th, 2010 @ 08:16 PM
- Tag changed from datetime, method_missing, timewithzone, timezone to datetime, method_missing, patch, timewithzone, timezone
The
ActiveSupport::TimeWithZone#localtime
method is not covered by any test. It fails when callinggetlocal
on a DateTime instance. A quick (and simple) workaround would be to convert it into a Time object before calling getlocal, since the documentation says the returned value is a Time object (the same as callingTime.local()
).Here is a patch adding both tests (with and without DateTime) and a slight (maybe a little ugly?) modification to the
localtime
method.It does not break any tests (under ruby 1.8.7 p266 and using the sqlite3 and mysql adapters for activerecord tests) so, do you think it would be a valid fix?
-
José Valim November 8th, 2010 @ 01:24 PM
- State changed from new to open
- Milestone set to 3.0.2
- Assigned user set to José Valim
- Importance changed from to Low
-
Repository November 11th, 2010 @ 03:33 AM
- State changed from open to committed
(from [5dc7f34dca3a5b0bd65dff157ae547347e86670e]) Fix ActiveSupport::TimeWithZone#localtime method with DateTime
[#5344 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/5dc7f34dca3a5b0bd65dff157ae54... -
Repository November 11th, 2010 @ 03:34 AM
(from [387a1a6365d6452961fce6ac61a8ca6db99a1ed1]) Fix ActiveSupport::TimeWithZone#localtime method with DateTime
[#5344 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/387a1a6365d6452961fce6ac61a8c...
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
Attachments
Referenced by
- 5344 #localtime fails for TimeWithZone-wrapped DateTimes [#5344 state:committed]
- 5344 #localtime fails for TimeWithZone-wrapped DateTimes [#5344 state:committed]