From 7ca5178c8ac5d717b1fc3c2b9ddd0a35526b7e85 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 21 Aug 2019 13:32:25 +0200 Subject: [PATCH] Fixed day range check --- .../java/eu/faircode/email/EntityRule.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 9e18a0964e..38ddad86ae 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -180,17 +180,31 @@ public class EntityRule { int start = jschedule.optInt("start", 0); int end = jschedule.optInt("end", 0); - if (end <= start) - end += 7 * 24 * 60; - - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date(message.received)); - int mday = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY; - int mhour = cal.get(Calendar.HOUR_OF_DAY); - int mminute = cal.get(Calendar.MINUTE); - int minutes = mday * 24 * 60 + mhour * 60 + mminute; - - if (minutes < start || minutes > end) + int dstart = start / (24 * 60); + int hstart = start / 60 % 24; + int mstart = start % 60; + + int dend = end / (24 * 60); + int hend = end / 60 % 24; + int mend = end % 60; + + Calendar cal_start = Calendar.getInstance(); + cal_start.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY + dstart); + cal_start.set(Calendar.HOUR_OF_DAY, hstart); + cal_start.set(Calendar.MINUTE, mstart); + cal_start.set(Calendar.SECOND, 0); + + Calendar cal_end = Calendar.getInstance(); + cal_end.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY + dend); + cal_end.set(Calendar.HOUR_OF_DAY, hend); + cal_end.set(Calendar.MINUTE, mend); + cal_end.set(Calendar.SECOND, 0); + + if (cal_start.getTimeInMillis() > cal_end.getTimeInMillis()) + cal_start.add(Calendar.HOUR_OF_DAY, -7 * 24); + + if (message.received < cal_start.getTimeInMillis() || + message.received > cal_end.getTimeInMillis()) return false; }