public static LocalDateTime getWorkDateTime(LocalDateTime dateTime, int days) {
if (days > 0) {
for (int i = 0; i < days; i++) {
dateTime = (LocalDateTime) getNextWorkDay.adjustInto(dateTime);
}
} else if (days < 0) {
for (int i = 0; i < (-days); i++) {
dateTime = (LocalDateTime) getPreWorkDay.adjustInto(dateTime);
}
}
return dateTime;
}
private final static TemporalAdjuster getNextWorkDay = TemporalAdjusters.ofDateAdjuster((d) -> {
if (d.getDayOfWeek().equals(DayOfWeek.FRIDAY)) {
return d.plusDays(3);
} else if (d.getDayOfWeek().equals(DayOfWeek.SATURDAY)) {
return d.plusDays(2);
} else {
return d.plusDays(1);
}
});
private final static TemporalAdjuster getPreWorkDay = TemporalAdjusters.ofDateAdjuster((d) -> {
if (d.getDayOfWeek().equals(DayOfWeek.MONDAY)) {
return d.minusDays(3);
} else if (d.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
return d.minusDays(2);
} else {
return d.minusDays(1);
}
});