1 | <?php |
||
8 | class Week extends DateRange |
||
9 | { |
||
10 | private const WEEK_START_DAY = 1; |
||
11 | |||
12 | 9 | public function __construct(?string $date_string = null) |
|
13 | { |
||
14 | 9 | $date = new DateTimeImmutable($date_string); |
|
15 | |||
16 | 9 | $first_day_of_week = self::getFirstDayOfWeek($date); |
|
17 | |||
18 | 9 | $this->start = $first_day_of_week->setTime(0, 0, 0); |
|
19 | 9 | $this->end = $first_day_of_week->modify('+6 days')->setTime(23, 59, 59); |
|
20 | |||
21 | 9 | $period = $this->getPeriod(); |
|
22 | 9 | foreach ($period as $day) { |
|
23 | 9 | $this->dates[] = new Day($day->format('Y-m-d')); |
|
24 | } |
||
25 | 9 | } |
|
26 | |||
27 | 1 | public static function fromWeekNumber($year, $week_number): Week |
|
33 | |||
34 | 9 | public static function getFirstDayOfWeek(DateTimeImmutable $day): DateTimeImmutable |
|
46 | |||
47 | /** |
||
48 | * It's unnecessary defining this method. It's here only to allow IDE type hinting. |
||
49 | * |
||
50 | * @return Day |
||
51 | */ |
||
52 | 1 | public function current() |
|
56 | } |
||
57 |