Open the Rails console and enter the following:
2.weeks.ago.between? 2.weeks.ago, 1.week.ago
Did it give you truth or falsehood? No, try a few more times and it will give you different answers.
Now I think that since we are comparing 2.weeks.ago with 2.weeks.ago, the time between evaluating the two statements causes this behavior.
I can’t say for sure, but I guess in between? the method is not inclusive, and therefore, if several milliseconds have passed between the two operators, the above code will be evaluated as true, because it will be between two matched dates.
However, if the processor manages to process it fast enough so that the elapsed time is clueless, it will be evaluated as false.
Can anyone shed some light on this? This is an extreme case at best in a system where it can be crucial, but it gave me a headache when my tests passed and did not seem random.
Oddly enough, this does not happen:
Date.yesterday.between? Date.yesterday, Date.tomorrow
Jaryl source
share