Skip to content

Instantly share code, notes, and snippets.

@usbportnoy
Last active September 28, 2016 17:40
Show Gist options
  • Select an option

  • Save usbportnoy/f478818fa5f3e2221f24ace0946d4e9d to your computer and use it in GitHub Desktop.

Select an option

Save usbportnoy/f478818fa5f3e2221f24ace0946d4e9d to your computer and use it in GitHub Desktop.
public class OnlineStatus {
public enum States {Unknown, Online}
private int onlineThresholdHrs;
public void setOnlineThresholdHrs(int hours) {
this.onlineThresholdHrs = hours;
}
public States getStatus(Date lastOnline, Calendar calendar) {
int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
calendar.set(
Calendar.HOUR_OF_DAY,
currentHour + onlineThresholdHrs);
Date onlineThreshold = calendar.getTime();
if (lastOnline.before(onlineThreshold)) {
return States.Online;
} else {
return States.Unknown;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment