Fixed day range check

pull/161/head
M66B 5 years ago
parent 722f94cb8a
commit 7ca5178c8a

@ -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;
}

Loading…
Cancel
Save