diff --git a/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java b/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java index a591b7e..b2d06f0 100644 --- a/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java @@ -295,7 +295,34 @@ public void onClick(View view) { citrus.setCurMonth(month); citrus.setCurYear(year); + //指定した年月の一日の曜日を取得 + LocalDate firstDay = LocalDate.of(year, month, 1); + DayOfWeek dayOfWeek = firstDay.getDayOfWeek(); + int firstDayOfWeek = dayOfWeek.getValue(); + //前の月の最後の日付を取得 + LocalDate lastDate = LocalDate.of(year, month, 1); + LocalDate lastDayPrevMonth = lastDate.minusDays(1); + int prevMonthDay = lastDayPrevMonth.getDayOfMonth(); + //現在の月の最後の日付を取得 + YearMonth yearMonth = YearMonth.of(year, month); + LocalDate CurLastDay = yearMonth.atEndOfMonth(); + int lastDay = CurLastDay.getDayOfMonth(); + + String[][] daysString = calendarString(firstDayOfWeek, prevMonthDay, lastDay); citrus.setCurDay(Integer.parseInt(daysString[ii][jj])); + if(ii == 0 && Integer.parseInt(daysString[ii][jj]) > 8) { + if(month == 1) { + month = 13; + citrus.setCurMonth(month - 1); + } + citrus.setCurMonth(month - 1); + } else if (ii >= 4 && Integer.parseInt(daysString[ii][jj]) < 25) { + if(month == 12) { + month = 0; + citrus.setCurMonth(month + 1); + } + citrus.setCurMonth(month + 1); + } ((MainActivity) getActivity()).showFragment(new HomeFragment()); } });