| 1 | <?php |
||
| 8 | class Month extends DateRange |
||
| 9 | { |
||
| 10 | 6 | public function __construct(?string $date_string = null) |
|
| 11 | { |
||
| 12 | 6 | $date = new DateTimeImmutable($date_string); |
|
| 13 | |||
| 14 | 6 | $this->start = $date->modify('first day of this month')->setTime(0, 0, 0); |
|
| 15 | 6 | $this->end = $date->modify('last day of this month')->setTime(23, 59, 59); |
|
| 16 | |||
| 17 | 6 | $period = $this->getPeriod('P7D', Week::getFirstDayOfWeek($this->start())); |
|
| 18 | 6 | foreach ($period as $week) { |
|
| 19 | 6 | $this->dates[] = new Week($week->format('Y-m-d')); |
|
| 20 | } |
||
| 21 | 6 | } |
|
| 22 | |||
| 23 | 1 | public static function fromMonth($year, $month): Month |
|
| 24 | { |
||
| 25 | 1 | return new self($year . '-' . $month . '-1'); |
|
| 26 | } |
||
| 27 | |||
| 28 | 1 | public function isOutOfMonth(DateRange $period): bool |
|
| 32 | |||
| 33 | /** |
||
| 34 | * It's unnecessary defining this method. It's here only to allow IDE type hinting. |
||
| 35 | * |
||
| 36 | * @return Week |
||
| 37 | */ |
||
| 38 | 1 | public function current() |
|
| 42 | } |
||
| 43 |