From a8b61a7d40531efbb120f97769393a683cb66305 Mon Sep 17 00:00:00 2001 From: Christoph Thelen <christoph.thelen@mni.thm.de> Date: Wed, 29 Oct 2014 12:28:33 +0100 Subject: [PATCH] Refactored handling of time --- src/main/java/de/thm/arsnova/FeedbackStorage.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/thm/arsnova/FeedbackStorage.java b/src/main/java/de/thm/arsnova/FeedbackStorage.java index c5eb5a750..52f14f8e9 100644 --- a/src/main/java/de/thm/arsnova/FeedbackStorage.java +++ b/src/main/java/de/thm/arsnova/FeedbackStorage.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -105,9 +106,9 @@ public class FeedbackStorage { return removedFeedbackOfUsersInSession; } - private List<User> cleanFeedbackVotesInSession(final Session session, final int cleanupFeedbackDelay) { - final long timelimitInMillis = 60000 * (long) cleanupFeedbackDelay; - final long maxAllowedTimeInMillis = System.currentTimeMillis() - timelimitInMillis; + private List<User> cleanFeedbackVotesInSession(final Session session, final int cleanupFeedbackDelayInMins) { + final long timelimitInMillis = TimeUnit.MILLISECONDS.convert(cleanupFeedbackDelayInMins, TimeUnit.MINUTES); + final Date maxAllowedTime = new Date(System.currentTimeMillis() - timelimitInMillis); final Map<User, FeedbackStorageObject> sessionFeedbacks = data.get(session); final List<User> affectedUsers = new ArrayList<User>(); @@ -115,7 +116,7 @@ public class FeedbackStorage { for (final Map.Entry<User, FeedbackStorageObject> entry : sessionFeedbacks.entrySet()) { final User user = entry.getKey(); final FeedbackStorageObject feedback = entry.getValue(); - final boolean timeIsUp = feedback.getTimestamp().getTime() < maxAllowedTimeInMillis; + final boolean timeIsUp = feedback.getTimestamp().before(maxAllowedTime); if (timeIsUp) { sessionFeedbacks.remove(user); affectedUsers.add(user); -- GitLab