Skip to content

Commit

Permalink
v1.3.7 中元节改为农历七月十五;修复Solar的nextMonth超期问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Sep 5, 2023
1 parent 526653d commit 0db466d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
25 changes: 10 additions & 15 deletions src/Solar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/LunarUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('天灸日'),
Expand Down
24 changes: 24 additions & 0 deletions test/SolarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 0db466d

Please sign in to comment.