1

I have an external service that allows me to log users into my website.

To avoid getting kicked out of it for overuse I use a MySQL table on the following form that caches user accesses:

username (STRING) | last access (TIMESTAMP) | has access? (TINYINT(1) - BOOLEAN)

If the user had access on a given time I trust he has access and don't query the service during a day, that is

query_again = !user["last access"].between?(Time.now, 1.day.ago)

This always returns true for some reason, any help with this logic?

1 Answer 1

2

In ranges (which you effectively use here), it is generally expected that the lower number is the start and the higher number is the end. Thus, it should work for you if you just switch the condition in your between? call

query_again = !user["last access"].between?(1.day.ago, Time.now)

You can test this yourself easily in IRB:

1.hour.ago.between?(Time.now, 1.day.ago)
# => false

1.hour.ago.between?(1.day.ago, Time.now)
# => true

Not the answer you're looking for? Browse other questions tagged or ask your own question.