loading...

カレンダーの行数を求める

twitter logo github logo ・1 min read

カレンダーの行数を求める。

算出方法は以下を参考。
https://biz.hino-tama.com/creative/blog0012/

int calendarRows(LocalDate date) {
    if (date == null) {
        throw new IllegalArgumentException();
    }

    LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
    DayOfWeek dow = firstDay.getDayOfWeek();
    Month month = firstDay.getMonth();

    if (DayOfWeek.SATURDAY.equals(dow)) {
        return Month.FEBRUARY.equals(month) ? 5 : 6;
     }

    if (DayOfWeek.FRIDAY.equals(dow)) {
        return firstDay.lengthOfMonth() == 31 ? 6 : 5;
    }

    if (DayOfWeek.SUNDAY.equals(dow) && Month.FEBRUARY.equals(month)) {
        return firstDay.isLeapYear() ? 5 :4;
    }

    return 5;
}
twitter logo DISCUSS
Classic DEV Post from May 17 '19

CSS can do that?

A list of amazing things that CSS can do

Kentama7 profile image

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️