/**
* @notes: 获取快捷时间
* @return array
* @author: lavender
* @time: 2024/7/23 15:36
*/
public function getShortcutsTimeArea()
{
$arr = [];
$timezone = new \DateTimeZone('PRC');
$datetime = new \DateTime();
$datetime->setTimezone($timezone);
$month = get_now_date('n');
$season = (int)($month / 3);
if ($month % 3 > 0) {
$season += 1;
}
// 本周
$datetime->modify('Monday this week');
$start_time1 = $datetime->format('Y-m-d');
$datetime->modify('Sunday this week');
$end_time1 = $datetime->format('Y-m-d');
$arr['this_week'] = $start_time1 . ' ~ ' . $end_time1;
// 本月
$datetime->modify('first day of this month');
$start_time2 = $datetime->format('Y-m-d');
$datetime->modify('last day of this month');
$end_time2 = $datetime->format('Y-m-d');
$arr['this_month'] = $start_time2 . ' ~ ' . $end_time2;
// 本季度
if ($season === 1) {
$arr['this_quarter'] = get_now_date('Y-01-01') . ' ~ ' . get_now_date('Y-03-31');
} else if ($season === 2) {
$arr['this_quarter'] = get_now_date('Y-04-01') . ' ~ ' . get_now_date('Y-06-30');
} else if ($season === 3) {
$arr['this_quarter'] = get_now_date('Y-07-01') . ' ~ ' . get_now_date('Y-09-30');
} else {
$arr['this_quarter'] = get_now_date('Y-10-01') . ' ~ ' . get_now_date('Y-12-31');
}
// 今年
$datetime->modify('first day of january this year');
$start_time4 = $datetime->format('Y-m-d');
$datetime->modify('last day of december this year');
$end_time4 = $datetime->format('Y-m-d');
$arr['this_year'] = $start_time4 . ' ~ ' . $end_time4;
// 上周
$timezone = new \DateTimeZone('PRC');
$datetime = new \DateTime();
$datetime->setTimezone($timezone);
$datetime->modify('Monday last week');
$start_time5 = $datetime->format('Y-m-d');
$datetime->modify('Sunday this week');
$end_time5 = $datetime->format('Y-m-d');
$arr['last_week'] = $start_time5 . ' ~ ' . $end_time5;
// 上月
$timezone = new \DateTimeZone('PRC');
$datetime = new \DateTime();
$datetime->setTimezone($timezone);
$datetime->modify('first day of last month');
$start_time6 = $datetime->format('Y-m-d');
$datetime->modify('last day of this month');
$end_time6 = $datetime->format('Y-m-d');
$arr['last_month'] = $start_time6 . ' ~ ' . $end_time6;
// 上季度
if ($season === 1) {
$year = intval(get_now_date('Y')) - 1;
$arr['last_quarter'] = $year . '-10-01' . ' ~ ' . $year . '-12-31';
} else if ($season === 2) {
$arr['last_quarter'] = get_now_date('Y-01-01') . ' ~ ' . get_now_date('Y-03-31');
} else if ($season === 3) {
$arr['last_quarter'] = get_now_date('Y-04-01') . ' ~ ' . get_now_date('Y-06-30');
} else {
$arr['last_quarter'] = get_now_date('Y-07-01') . ' ~ ' . get_now_date('Y-09-30');
}
// 去年
$timezone = new \DateTimeZone('PRC');
$datetime = new \DateTime();
$datetime->setTimezone($timezone);
$datetime->modify('first day of january last year');
$start_time8 = $datetime->format('Y-m-d');
$datetime->modify('last day of december this year');
$end_time8 = $datetime->format('Y-m-d');
$arr['last_year'] = $start_time8 . ' ~ ' . $end_time8;
return $arr;
}