diff --git a/src/Solar.php b/src/Solar.php index a2c5b48..10495c0 100644 --- a/src/Solar.php +++ b/src/Solar.php @@ -541,19 +541,17 @@ public function nextYear($years) { $y = $this->year + $years; $m = $this->month; $d = $this->day; - // 2月处理 - if (2 == $m) { + if (1582 == $y && 10 == $m) { + if ($d > 4 && $d < 15) { + $d += 10; + } + } else if (2 == $m) { if ($d > 28) { if (!SolarUtil::isLeapYear($y)) { $d = 28; } } } - if (1582 == $y && 10 == $m) { - if ($d > 4 && $d < 15) { - $d += 10; - } - } return self::fromYmdHms($y, $m, $d, $this->hour, $this->minute, $this->second); } @@ -567,18 +565,15 @@ public function nextMonth($months) { $y = $month->getYear(); $m = $month->getMonth(); $d = $this->day; - // 2月处理 - if (2 == $m) { - if ($d > 28) { - if (!SolarUtil::isLeapYear($y)) { - $d = 28; - } - } - } if (1582 == $y && 10 == $m) { if ($d > 4 && $d < 15) { $d += 10; } + } else { + $days = SolarUtil::getDaysOfMonth($y, $m); + if ($d > $days) { + $d = $days; + } } return self::fromYmdHms($y, $m, $d, $this->hour, $this->minute, $this->second); } diff --git a/src/util/LunarUtil.php b/src/util/LunarUtil.php index 1fc4a30..9f01076 100644 --- a/src/util/LunarUtil.php +++ b/src/util/LunarUtil.php @@ -150,7 +150,7 @@ class LunarUtil '6-6' => array('天贶节'), '6-24' => array('观莲节'), '6-25' => array('五谷母节'), - '7-14' => array('中元节'), + '7-15' => array('中元节'), '7-22' => array('财神节'), '7-29' => array('地藏节'), '8-1' => array('天灸日'), diff --git a/test/SolarTest.php b/test/SolarTest.php index 5df92d5..f79c102 100644 --- a/test/SolarTest.php +++ b/test/SolarTest.php @@ -133,5 +133,29 @@ public function test24() $solar = Solar::fromYmd(1582, 10, 15); $this->assertEquals('1582-09-30', $solar->next(-5)->toYmd()); } + + public function test25() + { + $solar = Solar::fromYmd(2023, 8, 31); + $this->assertEquals('2023-09-30', $solar->nextMonth(1)->toYmd()); + } + + public function test26() + { + $solar = Solar::fromYmd(2023, 8, 31); + $this->assertEquals('2023-10-31', $solar->nextMonth(2)->toYmd()); + } + + public function test27() + { + $solar = Solar::fromYmd(2023, 8, 31); + $this->assertEquals('2024-02-29', $solar->nextMonth(6)->toYmd()); + } + + public function test28() + { + $solar = Solar::fromYmd(2023, 8, 31); + $this->assertEquals('2025-08-31', $solar->nextYear(2)->toYmd()); + } }