I have multiple working hours in LocalTime and I want to check if the time exceeds 24 hours. The time is in 24h format.
For example:
- 02:00 - 08:00
- 10:00 - 12:00
- 23:00 - 03:00
In the example above, it exceeds 24h since it starts at 02:00 and goes till 03.00. It is only allowed to go till 02:00.
I implemented a loop and tried to calculate the time difference and sum it, for example:
- 02:00 - 08:00 --> 6 h
- 08:00 - 10:00 --> 2 h
- 10:00 - 12:00 --> 2 h
- 12:00 - 23:00 --> 11h
- 23:00 - 03:00 --> 4 h
In total it would be 25h, so it is bigger than 24h. However my problem is that I cannot calculate the time difference between 23:00 - 03:00 because LocalTime only goes till 23:59:59. So I currently I cannot calculate durations beyond a 24 hour period.
So using ChronoUnit won't work:
ChronoUnit.HOURS.between(23:00, 03:00);
I am not sure what kind of approach I should use to solve this problem