between java.time.LocalTime (next day)

前端 未结 3 1828
孤街浪徒
孤街浪徒 2021-01-04 13:59

Please suggest if there is an API support to determine if my time is between 2 LocalTime instances, or suggest a different approach.

I have this entity:

3条回答
  •  长情又很酷
    2021-01-04 14:06

    If I understand correctly, you need to make two cases depending on whether the closing time is on the same day as the opening time (9-17) or on the next day (22-5).

    It could simply be:

    public static boolean isOpen(LocalTime start, LocalTime end, LocalTime time) {
      if (start.isAfter(end)) {
        return !time.isBefore(start) || !time.isAfter(end);
      } else {
        return !time.isBefore(start) && !time.isAfter(end);
      }
    }
    

提交回复
热议问题