Created
July 5, 2019 17:31
-
-
Save Bahaaib/99c03020926722869e3eccdda22c02a0 to your computer and use it in GitHub Desktop.
Doctor Date Problem
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
| 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