I am trying to determine if a timestamp is older than 30 seconds, but for some reason it is coming back as older than 30 seconds when it hasn't even been a couple seconds.
Example: https://ideone.com/KLIIBz
public static Boolean cooldown(int id) {
Calendar now = Calendar.getInstance();
now.add(Calendar.SECOND, -secondsAgo);
long timeAgo = now.getTimeInMillis();
if ( cooldown.containsKey(id) ) {
System.out.println(cooldown.get(id) + " | " + timeAgo);
// Stored timestamp always older than timeAgo
if ( cooldown.get(id) < timeAgo ) {
cooldown.remove(id);
} else {
// This code should be executed, as I am running the function one after another from same UUID not even a second or two apart.
return false;
}
}
now = Calendar.getInstance();
cooldown.put(id, now.getTimeInMillis());
return true;
}