TemporalAdjuster ofDateAdjuster implementation and DayOfWeek calculating the next working day with Bangla name.
Transcribed from the original LinkedIn image post.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.Locale;
class Day23 {
public static void main(String[] args) {
LocalDate today = LocalDate.now();
LocalDate nextWorkingDay = today.with(Day23.nextWorkingDay);
DayOfWeek namedDate = nextWorkingDay.getDayOfWeek();
System.out.println(namedDate.getDisplayName(TextStyle.FULL, Locale.forLanguageTag("bn-BD")));
}
static TemporalAdjuster nextWorkingDay = TemporalAdjusters.ofDateAdjuster(localDate -> {
DayOfWeek dayOfWeek = localDate.getDayOfWeek();
int daysToAddToGetWorkingDay;
int daysToOffsetForFriday = 2;
int daysToOffsetForSaturday = 1;
int daysToOffsetOtherDay = 1;
if (dayOfWeek == DayOfWeek.FRIDAY)
daysToAddToGetWorkingDay = daysToOffsetForFriday;
else if (dayOfWeek == DayOfWeek.SATURDAY)
daysToAddToGetWorkingDay = daysToOffsetForSaturday;
else
daysToAddToGetWorkingDay = daysToOffsetOtherDay;
return localDate.plusDays(daysToAddToGetWorkingDay);
});
}
|
The original LinkedIn graphic is preserved below.
