Skip to content

Commit a4f67c3

Browse files
committed
🐞 (DateHelper):修复获取上个月或某个月之前的起止结束时间错误
1 parent b005571 commit a4f67c3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Helpers/DateHelper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ public static function thisMonth()
102102
*/
103103
public static function lastMonth()
104104
{
105-
$start = mktime(0, 0, 0, (int)date('m') - 1, 1, (int)date('Y'));
106-
$end = mktime(23, 59, 59, (int)date('m') - 1, (int)date('t'), (int)date('Y'));
105+
$year = (int)date('Y');
106+
$start = mktime(0, 0, 0, (int)date('m') - 1, 1,$year);
107+
$end = mktime(23, 59, 59, (int)date('m') - 1, (int)date('t',$start), $year);
107108

108109
if (date('m', $start) != date('m', $end)) {
109110
$end -= 60 * 60 * 24;
@@ -123,8 +124,9 @@ public static function lastMonth()
123124
*/
124125
public static function monthsAgo($month)
125126
{
126-
$start = mktime(0, 0, 0, (int)date('m') - $month, 1, (int)date('Y'));
127-
$end = mktime(23, 59, 59, (int)date('m') - $month, (int)date('t'), (int)date('Y'));
127+
$year = (int)date('Y');
128+
$start = mktime(0, 0, 0, (int)date('m') - $month, 1, $year);
129+
$end = mktime(23, 59, 59, (int)date('m') - $month, (int)date('t',$start), $year);
128130
if (date('m', $start) != date('m', $end)) {
129131
$end -= 60 * 60 * 24;
130132
}

0 commit comments

Comments
 (0)