Skip to content

Instantly share code, notes, and snippets.

@Bahaaib
Created July 5, 2019 17:31
Show Gist options
  • Select an option

  • Save Bahaaib/99c03020926722869e3eccdda22c02a0 to your computer and use it in GitHub Desktop.

Select an option

Save Bahaaib/99c03020926722869e3eccdda22c02a0 to your computer and use it in GitHub Desktop.
Doctor Date Problem
static String getStatusOfDoctorOpenedOrClosed(int[] doctorDays, int[] fromHour, int[] toHour) {
String opened = "Opened: Closes at 8 PM";
String closed = "Closed: Opens at Mon 4 PM";
int doctorWeekLength = doctorDays.length;
//Get Exact day of the week
Date date = new Date();
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int dayOfWeek = localDate.getDayOfWeek().getValue() + 1;
//Get Exact hour of the day
LocalTime now = LocalTime.now();
int timeNow = now.getHour();
for (int i = 0; i < doctorWeekLength; i++) {
if (dayOfWeek == doctorDays[i]) {
if (timeNow >= fromHour[i] && timeNow < toHour[i]) {
return opened;
} else {
break;
}
}
}
return closed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment