此为工作笔记。
需求背景:每个月的1号不可能都是从周一开始,因此需要截取上月的最后几天;相对的每个月的最后一天也不可能就是周日,因此需要获取下月的前几天。
以2022-07月为例,需要获取的日期范围数据为:2022-06-27 -- 2022-07-31
/**
* 获取周一-周日月度数据
* @param string $month 月份,格式:2022-12
* @return array 全部的日期list
*/
function getNatureMonthDays($month)
{
$week_keys = [1, 2, 3, 4, 5, 6, 0];
$sdate = $month . '-01';
$sdate_week = date('w', strtotime($sdate));
$edate = date('Y-m-t', strtotime($sdate));
$edate_week = date('w', strtotime($edate));
$sdate_search = array_search($sdate_week, $week_keys);
$edate_search = array_search($edate_week, $week_keys);
if ($sdate_search != 0) {
$sdate = date('Y-m-d', strtotime("-{$