Weekend filter for Java 8 LocalDateTime

前端 未结 6 1187
春和景丽
春和景丽 2021-02-20 03:47

I want to write a boolean valued function which returns true if the given LocalDateTime falls between two specific points in time, false otherwise.

Specific

6条回答
  •  粉色の甜心
    2021-02-20 04:18

    How would you expect such a library to work? You would still need to tell it when your weekend begins and ends and it would end up being not much shorter than the simple

    boolean isWeekend(LocalDateTime dt) {
        switch(dt.getDayOfWeek()) {
            case FRIDAY:
                return dt.getHour() >= ...;
            case SATURDAY:
                return true;
            case SUNDAY:
                return dt.getHour() < ...;
            default:
                return false;
        }
    }
    

提交回复
热议问题