evaluating/comparing amount of time passed
The following code evaluates that the time being parsed is greate开发者_StackOverflow中文版r than 30 days ago.
Time.parse("2011-01-03T14:31:57Z") < 30.days.ago
=> true
Why is this true? It looks to me like the <
is going the wrong way, and ought to be >
. What am I missing?
30.days.ago
is a time, that time being 30 days ago. You're seeing if your time is earlier than 30 days ago, and it is.
So, don't read it as "less than 30 days ago", read it as "before 30 days ago", or "earlier than 30 days ago".
>
refers to being a date past or "greater than" the preceding date. 30 days ago is past January 3rd, therefor it is greater.
精彩评论