/** * 計算 * * @return \Month */ public function calc() { $day = 1; // 先月用 $lastMonthLastDay = $this->lastMonthLastDay() - $this->firstDayWeekCode; // 来月開始日用 $nextMonthDay = 1; $weekCnt = $this->haveWeeksCount(); for ($i = 1; $i <= $weekCnt; $i++) { $week = new Week(); for ($j = 0; $j < 7; $j++) { // 先月 if ($i === 1 && $j < $this->firstDayWeekCode) { $week->setDays(Day::forge($this->lastMonthFullDate($lastMonthLastDay + $j + 1), Day::LAST_MONTH)->calc()); continue; } // 当月 if ($day <= $this->lastDay) { $week->setDays(Day::forge($this->fullDate($day++))->calc()); continue; } // 来月 $week->setDays(Day::forge($this->nextMonthFullDate($nextMonthDay++), Day::NEXT_MONTH)->calc()); } $this->weeks[$i] = $week; } return $this; }