Last active
September 28, 2016 17:40
-
-
Save usbportnoy/f478818fa5f3e2221f24ace0946d4e9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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