Skip to content

Commit

Permalink
v1.3.14 修复节气当天获取下一节气仍为当前节气的问题;修复每日宜忌存在重复项的问题;修复八字转阳历存在遗漏的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Feb 29, 2024
1 parent eaedb06 commit 9411d87
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog


## [1.3.14] - 2024-02-29
1. 修复节气当天获取下一节气仍为当前节气的问题。
2. 修复每日宜忌存在重复项的问题。
3. 修复八字转阳历存在遗漏的问题。
2 changes: 1 addition & 1 deletion src/Lunar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ protected function getNearJieQi($forward, $conditions, $wholeDay)
}
$day = $wholeDay ? $solar->toYmd() : $solar->toYmdHms();
if ($forward) {
if (strcmp($day, $today) < 0) {
if (strcmp($day, $today) <= 0) {
continue;
}
if (null == $near) {
Expand Down
32 changes: 20 additions & 12 deletions src/Solar.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public static function fromBaZiBySectAndBaseYear($yearGanZhi, $monthGanZhi, $day
$m *= 2;
// 时辰地支转时刻,子时按零点算
$h = LunarUtil::index(substr($timeGanZhi, strlen($timeGanZhi) / 2), LunarUtil::$ZHI, -1) * 2;
$hours = array($h);
if (0 == $h && 2 == $sect) {
$hours = array(0, 23);
}
$startYear = $baseYear - 1;

// 结束年
Expand All @@ -234,8 +238,6 @@ public static function fromBaZiBySectAndBaseYear($yearGanZhi, $monthGanZhi, $day
// 节令推移,年干支和月干支就都匹配上了
$solarTime = $jieQiTable[Lunar::$JIE_QI_IN_USE[4 + $m]];
if ($solarTime->getYear() >= $baseYear) {
$mi = 0;
$s = 0;
// 日干支和节令干支的偏移值
$lunar = $solarTime->getLunar();
$dgz = (2 == $sect) ? $lunar->getDayInGanZhiExact2() : $lunar->getDayInGanZhiExact();
Expand All @@ -246,17 +248,23 @@ public static function fromBaZiBySectAndBaseYear($yearGanZhi, $monthGanZhi, $day
if ($d > 0) {
// 从节令推移天数
$solarTime = $solarTime->next($d);
} else if ($h == $solarTime->getHour()) {
// 如果正好是节令当天,且小时和节令的小时数相等的极端情况,把分钟和秒钟带上
$mi = $solarTime->getMinute();
$s = $solarTime->getSecond();
}
// 验证一下
$solar = Solar::fromYmdHms($solarTime->getYear(), $solarTime->getMonth(), $solarTime->getDay(), $h, $mi, $s);
$lunar = $solar->getLunar();
$dgz = (2 == $sect) ? $lunar->getDayInGanZhiExact2() : $lunar->getDayInGanZhiExact();
if (strcmp($lunar->getYearInGanZhiExact(), $yearGanZhi) == 0 && strcmp($lunar->getMonthInGanZhiExact(), $monthGanZhi) == 0 && strcmp($dgz, $dayGanZhi) == 0 && strcmp($lunar->getTimeInGanZhi(), $timeGanZhi) == 0) {
$l[] = $solar;
foreach ($hours as $hour)
{
$mi = 0;
$s = 0;
if ($d == 0 && $hour == $solarTime->getHour()) {
// 如果正好是节令当天,且小时和节令的小时数相等的极端情况,把分钟和秒钟带上
$mi = $solarTime->getMinute();
$s = $solarTime->getSecond();
}
// 验证一下
$solar = Solar::fromYmdHms($solarTime->getYear(), $solarTime->getMonth(), $solarTime->getDay(), $hour, $mi, $s);
$lunar = $solar->getLunar();
$dgz = (2 == $sect) ? $lunar->getDayInGanZhiExact2() : $lunar->getDayInGanZhiExact();
if (strcmp($lunar->getYearInGanZhiExact(), $yearGanZhi) == 0 && strcmp($lunar->getMonthInGanZhiExact(), $monthGanZhi) == 0 && strcmp($dgz, $dayGanZhi) == 0 && strcmp($lunar->getTimeInGanZhi(), $timeGanZhi) == 0) {
$l[] = $solar;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/LunarUtil.php

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions test/EightCharTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,28 @@ public function test22()
$this->assertEquals($expected, $actual);
}

public function test23()
{
$solarList = Solar::fromBaZiBySectAndBaseYear('甲辰','丙寅','壬戌','壬子', 2, 1900);
$actual = array();
foreach ($solarList as $solar) {
$actual[] = $solar->toYmdHms();
}

$expected = array('2024-02-28 23:00:00');
$this->assertEquals($expected, $actual);
}

public function test24()
{
$solarList = Solar::fromBaZiBySectAndBaseYear('甲辰','丙寅','癸亥','壬子', 1, 1900);
$actual = array();
foreach ($solarList as $solar) {
$actual[] = $solar->toYmdHms();
}

$expected = array('2024-02-29 00:00:00');
$this->assertEquals($expected, $actual);
}

}

0 comments on commit 9411d87

Please sign in to comment.