Currently I'm trying to find out whether a certain time is between a startTime-1 Hour and endTime.
Currently my code is :
if (localTimeNow.isAfter(startShift.minus(1, ChronoUnit.HOURS)) &&
localTimeNow.isBefore(endShift)) {
Toast.makeText(this, "In shift", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Not in shift", Toast.LENGTH_SHORT).show();
}
This would work well if, let's say the startShift
is at 08:00 and endShift
at 16:00, but this doesn't work when I put startShift
at 22:00 and endShift
at 06:00.
Any suggestion on the logic here?