Refactor TemporalAdjusters (#2266)
This commit is contained in:
committed by
GitHub
parent
1acbe9b162
commit
3e2d766f37
@@ -10,14 +10,13 @@ public class CustomTemporalAdjuster implements TemporalAdjuster {
|
||||
|
||||
@Override
|
||||
public Temporal adjustInto(Temporal temporal) {
|
||||
DayOfWeek dayOfWeek = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
|
||||
int daysToAdd;
|
||||
if (dayOfWeek == DayOfWeek.FRIDAY)
|
||||
daysToAdd = 3;
|
||||
else if (dayOfWeek == DayOfWeek.SATURDAY)
|
||||
daysToAdd = 2;
|
||||
else
|
||||
daysToAdd = 1;
|
||||
return temporal.plus(daysToAdd, ChronoUnit.DAYS);
|
||||
switch (DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK))) {
|
||||
case FRIDAY:
|
||||
return temporal.plus(3, ChronoUnit.DAYS);
|
||||
case SATURDAY:
|
||||
return temporal.plus(2, ChronoUnit.DAYS);
|
||||
default:
|
||||
return temporal.plus(1, ChronoUnit.DAYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user