On Jul 30, 2009, at 12:38 PM, Will wrote:
> > Hi, > > I'm trying to use the ActiveSupport Time extension but running into a > bit of trouble with the time zone. > > I'd like to test if a user record has expired using the Time .ago > method, such as: > > def expired > return true if self.activated < 1.day.ago > end > > Unfortunately I can't seem to use the .ago method in the comparison > because it's using UTC time, whereas Time.now has my current time zone > (-0700). > > will$ script/console > Loading development environment (Rails 2.3.2) > >>> Time.now > => Thu Jul 30 12:16:30 -0700 2009 > >>> 1.hour.ago > => Thu, 30 Jul 2009 18:16:34 UTC +00:00 > > I can get around this by using something like "Time.now + 1.day" but > I'm interested to know what I'm doing wrong with the .ago method. > > Maybe there's some sort of time zone setting that I've missed? Maybe. I've never looked, but you can always tack localtime() onto it. >> Time.now => Thu Jul 30 12:40:31 -0700 2009 >> 1.day.ago => Wed, 29 Jul 2009 19:40:31 UTC 00:00 >> 1.day.ago.localtime => Wed Jul 29 12:40:38 -0700 2009 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---