aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2014-12-16 18:03:16 -0500
committerSam Whited <sam@samwhited.com>2014-12-16 18:03:16 -0500
commit0b4987581f6aeebd2b8c729b83aaebf9998ec0d6 (patch)
tree82943ac2dd09911fa5462b4b12874ca43fb02e7c /src/main/java/eu/siacs/conversations/services
parentf9c783085def547e82a8ab83826d74dd543ec0c2 (diff)
Handle time comparisons using longs
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index 9e21d1604..c27ab72a2 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -72,20 +72,15 @@ public class NotificationService {
if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
return false;
}
- final Calendar startTime = Calendar.getInstance();
- startTime.setTimeInMillis(mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE));
- final Calendar endTime = Calendar.getInstance();
- endTime.setTimeInMillis(mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE));
- final Calendar nowTime = Calendar.getInstance();
+ final long startTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
+ final long endTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
+ final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY;
- startTime.set(nowTime.get(Calendar.YEAR), nowTime.get(Calendar.MONTH), nowTime.get(Calendar.DATE));
- endTime.set(nowTime.get(Calendar.YEAR), nowTime.get(Calendar.MONTH), nowTime.get(Calendar.DATE));
-
- if (endTime.before(startTime)) {
- endTime.add(Calendar.DATE, 1);
+ if (endTime < startTime) {
+ return nowTime > startTime || nowTime < endTime;
+ } else {
+ return nowTime > startTime && nowTime < endTime;
}
-
- return nowTime.after(startTime) && nowTime.before(endTime);
}
public boolean conferenceNotificationsEnabled() {