views:

26

answers:

2

What am I missing here, it's driving me crazy..

>> user.current_login_at.utc > 24.hours.ago.utc
=> false
>> 24.hours.ago.utc
=> Mon May 17 18:46:16 UTC 2010
>> user.current_login_at.utc
=> Mon May 17 15:47:44 UTC 2010

user.current_login_at was 27 hours ago, yet the greater than comparison says it was not greater than 24 hours ago. It leaves me scratching my head..

+3  A: 

"Greater than" for a date means "after". 24.hours.ago gives a time, not a length of time. Conceptually, you are asking "did the user log in after the time that was 24 hours ago?", not "did the user log in more than 24 hours ago?". So you want:

user.current_login_at.utc < 24.hours.ago.utc

Which says "did the user log in before 24 hours ago?"

Nick Lewis
Jinx! Great minds think alike.
Matt Van Horn
Ugh.. my brain hurts. Seems so obvious.. now. :D
revgum
A: 

You are using "greater than", which in date comparisons, means "later than"

Is current login later than 24 hours ago?

user.current_login_at.utc > 24.hours.ago.utc

Is current login earlier than 24 hours ago?

user.current_login_at.utc < 24.hours.ago.utc
Matt Van Horn