|
@@ 54-72 (lines=19) @@
|
| 51 |
|
|
| 52 |
|
// If first day of month > 1 (first week doesn't start on a Monday)... |
| 53 |
|
// ...then pad the first week with remaining days from previous month |
| 54 |
|
private function padStart(): void |
| 55 |
|
{ |
| 56 |
|
// what day in the week is the first of the month? |
| 57 |
|
$startOfMonthWeekday = $this->startOfMonth->isoWeekday(); |
| 58 |
|
|
| 59 |
|
if ($startOfMonthWeekday > 1) { |
| 60 |
|
$currentMonth = $this->currentMonth; |
| 61 |
|
|
| 62 |
|
$daysToPad = $startOfMonthWeekday - 1; |
| 63 |
|
$prevMonth = CarbonPeriod::create( |
| 64 |
|
$this->startOfMonth->subDays($daysToPad), |
| 65 |
|
$this->startOfMonth->subDay() |
| 66 |
|
)->toArray(); |
| 67 |
|
|
| 68 |
|
$this->padWithNull |
| 69 |
|
? $this->currentMonth = array_pad($currentMonth, -(count($currentMonth) + $daysToPad), null) |
| 70 |
|
: $this->currentMonth = array_merge($prevMonth, $currentMonth); |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
// If last day of month < 7 (last week doesn't end on a Sunday)... |
| 75 |
|
// ...then pad the last week with beginning days from next month |
|
@@ 76-94 (lines=19) @@
|
| 73 |
|
|
| 74 |
|
// If last day of month < 7 (last week doesn't end on a Sunday)... |
| 75 |
|
// ...then pad the last week with beginning days from next month |
| 76 |
|
private function padEnd(): void |
| 77 |
|
{ |
| 78 |
|
// what day in the week is the last of the month? |
| 79 |
|
$endOfMonthWeekday = $this->endOfMonth->isoWeekday(); |
| 80 |
|
|
| 81 |
|
if ($endOfMonthWeekday < 7) { |
| 82 |
|
$currentMonth = $this->currentMonth; |
| 83 |
|
|
| 84 |
|
$daysToPad = 7 - $endOfMonthWeekday; |
| 85 |
|
$nextMonth = CarbonPeriod::create( |
| 86 |
|
$this->endOfMonth->addDay(), |
| 87 |
|
$this->endOfMonth->addDays($daysToPad) |
| 88 |
|
)->toArray(); |
| 89 |
|
|
| 90 |
|
$this->padWithNull |
| 91 |
|
? $this->currentMonth = array_pad($currentMonth, count($currentMonth) + $daysToPad, null) |
| 92 |
|
: $this->currentMonth = array_merge($currentMonth, $nextMonth); |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
|