instance
I was reading on how to make a cooldown when i stumbled across this block of code. I was asking myslef if the last line should be
since without it, we would be checking if the current time is before cooldown (which we dont) so we should neagte that. right?
10 Replies
⌛
This post has been reserved for your question.
Hey @Omaster! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
the current code without the negation is checking if the current time is before the cooldown in other words if the cooldown ends in the future (or now)
i.e. it is active if it ends in the future
hello
the method name
hasCooldown
isn't clear enough imo
id name it isCooldownEpired
world
That's the opposite of what the method is currently doing
ye they can reverse the return value. im looking for a way to make it more readable
hasCooldown
<-> hasActiveCooldown
<-> is the current time before the expiration time of the cooldown <-> Does the cooldown expire in the future?
if they care about equality ("the cooldown should still be active in the last millisecond of the cooldown"), that would change behavior
there is isBefore
and isAfter
but if you want isAfterOrEqual
, you'd need to use isBefore
and switch the receiver and parameteri think that the word "cooldown" is not suitable to this
imo it refers to a number of seconds like 10, 5, 2
it would be better to say timeout
now().isBefore(timeout)
it makes sense this way igtbh I'd say it's fine, especially if it's also called cooldown in interactions with other systems (e.g. telling the user)
But I'd just wait for the question author - I think discussing these things without the doesn't make much sense
got it
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.