This project is archived and is in readonly mode.
#localtime fails for TimeWithZone-wrapped DateTimes
-
chrispanda
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
- 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
Meanwhile you can use this workaround:
class DateTime def getlocal
self.to_time.getlocal.to_datetime
end end -
Álvaro Bautista
- Tag changed from datetime, method_missing, timewithzone, timezone to datetime, method_missing, patch, timewithzone, timezone
The
ActiveSupport::TimeWithZone#localtimemethod is not covered by any test. It fails when callinggetlocalon 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
localtimemethod.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
- State changed from new to open
- Milestone set to 3.0.2
- Assigned user set to José Valim
- Importance changed from to Low
-
Repository
- State changed from open to committed
(from [5dc7f34dca3a5b0bd65dff157ae547347e86670e]) Fix ActiveSupport::TimeWithZone#localtime method with DateTime
[#5344 #localtime fails for TimeWithZone-wrapped DateTimes state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/5dc7f34dca3a5b0bd65dff157ae54... -
Repository
(from [387a1a6365d6452961fce6ac61a8ca6db99a1ed1]) Fix ActiveSupport::TimeWithZone#localtime method with DateTime
[#5344 #localtime fails for TimeWithZone-wrapped DateTimes state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/387a1a6365d6452961fce6ac61a8c...
