<?php
$start_date = '2019-01-01';
$end_date = '2019-12-31';
function makeBroadcastCalendar($start_date, $end_date) {
$end = new DateTime($end_date);
$start = new DateTime($start_date);
$start->modify('monday this week');
$week = 1;
$weeks = array();
while($start < $end) {
$weeks[$week++] = $start->format('Y-m-d');
$start->modify('+1 week');
}
return $weeks;
}
function getBroadcastMonth($date) {
$end_of_week = new DateTime($date);
$end_of_week->modify('sunday this week');
return (int)$end_of_week->format('n');
}
function getBroadcastWeek($date) {
$start = new DateTime($date);
$start->modify('January 1');
$start->modify('monday this week');
$start_of_week = new DateTime($date);
$start_of_week->modify('monday this week');
$week = 1;
while ($start < $start_of_week) {
$start->modify('+1 week');
$week++;
}
return $week;
}
function getFirstAndLast($year, $month) {
$start = new DateTime("$year-$month-01");
$end = clone $start;
$start->modify('monday this week');
$output = array('first_day' => $start->format('Y-m-d'));
$end->modify('+1 month');
$end->modify('monday this week');
while ($start < $end) {
$start->modify('+1 week');
}
$output['end'] = $start->modify('-1 day')->format('Y-m-d');
return $output;
}
echo getBroadcastMonth('2019-10-12') . PHP_EOL;
echo getBroadcastMonth('2019-10-29') . PHP_EOL;
echo getBroadcastMonth('2019-05-31') . PHP_EOL;
echo getBroadcastWeek('2019-10-12') . PHP_EOL;
echo getBroadcastWeek('2019-10-29') . PHP_EOL;
echo getBroadcastWeek('2019-05-31') . PHP_EOL;
for ($i = 1; $i <= 12; $i++) {
print_r(getFirstAndLast(2019, $i));
}
- Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- 10
11
6
41
44
22
Array
(
[first_day] => 2018-12-31
[end] => 2019-01-27
)
Array
(
[first_day] => 2019-01-28
[end] => 2019-02-24
)
Array
(
[first_day] => 2019-02-25
[end] => 2019-03-31
)
Array
(
[first_day] => 2019-04-01
[end] => 2019-04-28
)
Array
(
[first_day] => 2019-04-29
[end] => 2019-05-26
)
Array
(
[first_day] => 2019-05-27
[end] => 2019-06-30
)
Array
(
[first_day] => 2019-07-01
[end] => 2019-07-28
)
Array
(
[first_day] => 2019-07-29
[end] => 2019-08-25
)
Array
(
[first_day] => 2019-08-26
[end] => 2019-09-29
)
Array
(
[first_day] => 2019-09-30
[end] => 2019-10-27
)
Array
(
[first_day] => 2019-10-28
[end] => 2019-11-24
)
Array
(
[first_day] => 2019-11-25
[end] => 2019-12-29
)
preferences:
166.24 ms | 410 KiB | 5 Q