Handle time comparisons using longs
This commit is contained in:
parent
f9c783085d
commit
0b4987581f
|
@ -24,7 +24,7 @@ public final class Config {
|
||||||
|
|
||||||
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
|
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
|
||||||
|
|
||||||
private static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
|
public static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
|
||||||
public static final long MAM_MAX_CATCHUP = MILLISECONDS_IN_DAY / 2;
|
public static final long MAM_MAX_CATCHUP = MILLISECONDS_IN_DAY / 2;
|
||||||
public static final int MAM_MAX_MESSAGES = 500;
|
public static final int MAM_MAX_MESSAGES = 500;
|
||||||
|
|
||||||
|
|
|
@ -72,20 +72,15 @@ public class NotificationService {
|
||||||
if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
|
if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Calendar startTime = Calendar.getInstance();
|
final long startTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
|
||||||
startTime.setTimeInMillis(mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE));
|
final long endTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
|
||||||
final Calendar endTime = Calendar.getInstance();
|
final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY;
|
||||||
endTime.setTimeInMillis(mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE));
|
|
||||||
final Calendar nowTime = Calendar.getInstance();
|
|
||||||
|
|
||||||
startTime.set(nowTime.get(Calendar.YEAR), nowTime.get(Calendar.MONTH), nowTime.get(Calendar.DATE));
|
if (endTime < startTime) {
|
||||||
endTime.set(nowTime.get(Calendar.YEAR), nowTime.get(Calendar.MONTH), nowTime.get(Calendar.DATE));
|
return nowTime > startTime || nowTime < endTime;
|
||||||
|
} else {
|
||||||
if (endTime.before(startTime)) {
|
return nowTime > startTime && nowTime < endTime;
|
||||||
endTime.add(Calendar.DATE, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nowTime.after(startTime) && nowTime.before(endTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean conferenceNotificationsEnabled() {
|
public boolean conferenceNotificationsEnabled() {
|
||||||
|
|
Loading…
Reference in New Issue