diff --git a/CHANGELOG.md b/CHANGELOG.md
index ab0dd42..2c5295b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,3 +20,10 @@
3. 新增:六曜。
4. 新增:入梅出梅。
5. 新增:获取农历日当天的时辰列表。
+
+## [1.1.0] - 2024-07-10
+1. 注意:此版本更改了getYear()、getMonth()、getDay()的返回类型,非兼容性更新。
+2. 新增:吉神宜趋、凶神宜忌。
+3. 新增:每日宜忌、时辰宜忌。
+4. 新增:支持方法扩展。
+5. 修复:农历日获取时辰列表遇闰月报错的问题。
diff --git a/README.md b/README.md
index 512da12..d672c5a 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,13 @@ Tyme是一个非常强大的日历工具库,可以看作 [Lunar](https://6tail
// 农历丙寅年四月廿一
echo $solarDay->getLunarDay();
+ // 扩展方法
+ SolarDay::extend('myMethod', function () {
+ return sprintf('%04d-%02d-%02d', $this->getYear(), $this->getMonth(), $this->getDay());
+ });
+ // 1986-05-29
+ echo $solarDay->myMethod();
+
## 单文件版本
> 1. 下载本源代码,执行tools/build-standalone.php,可在tools目录下生成Tyme.php单文件。
diff --git a/src/AbstractCulture.php b/src/AbstractCulture.php
index cc0888f..6a366d2 100644
--- a/src/AbstractCulture.php
+++ b/src/AbstractCulture.php
@@ -12,6 +12,8 @@
*/
abstract class AbstractCulture implements Culture
{
+ use ExtendTrait;
+
function __toString(): string
{
return $this->getName();
diff --git a/src/ExtendTrait.php b/src/ExtendTrait.php
new file mode 100644
index 0000000..8c073a7
--- /dev/null
+++ b/src/ExtendTrait.php
@@ -0,0 +1,47 @@
+bindTo($this, static::class);
+ return $function(...$parameters);
+ }
+}
diff --git a/src/culture/God.php b/src/culture/God.php
new file mode 100644
index 0000000..f2b697b
--- /dev/null
+++ b/src/culture/God.php
@@ -0,0 +1,83 @@
+nextIndex($n));
+ }
+
+ /**
+ * 吉凶
+ * @return Luck 吉凶
+ */
+ function getLuck(): Luck
+ {
+ return Luck::fromIndex($this->index < 60 ? 0 : 1);
+ }
+
+ /**
+ * 日神煞列表(吉神宜趋,凶神宜忌)
+ * @param SixtyCycle $month 月干支
+ * @param SixtyCycle $day 日干支
+ * @return God[] 神煞列表
+ */
+ static function getDayGods(SixtyCycle $month, SixtyCycle $day): array
+ {
+ $l = array();
+ if (preg_match_all(sprintf('/;%02X(.[^;]*)/', $day->getIndex()), static::$dayGods[$month->getEarthBranch()->next(-2)->getIndex()], $matches)) {
+ $data = $matches[1][0];
+ for ($i = 0, $j = strlen($data); $i < $j; $i += 2) {
+ $l[] = static::fromIndex(hexdec(substr($data, $i, 2)));
+ }
+ }
+ return $l;
+ }
+}
diff --git a/src/culture/Taboo.php b/src/culture/Taboo.php
new file mode 100644
index 0000000..a0dc551
--- /dev/null
+++ b/src/culture/Taboo.php
@@ -0,0 +1,150 @@
+nextIndex($n));
+ }
+
+ /**
+ * 吉凶
+ * @return Luck 吉凶
+ */
+ function getLuck(): Luck
+ {
+ return Luck::fromIndex($this->index < 60 ? 0 : 1);
+ }
+
+ /**
+ * 日宜
+ * @param SixtyCycle $month 月干支
+ * @param SixtyCycle $day 日干支
+ * @return Taboo[] 宜忌列表
+ */
+ static function getDayRecommends(SixtyCycle $month, SixtyCycle $day): array
+ {
+ $l = array();
+ $data = explode(',', explode(';', static::$dayTaboo[$month->getEarthBranch()->getIndex()])[$day->getIndex()])[0];
+ for ($i = 0, $j = strlen($data); $i < $j; $i += 2) {
+ $l[] = static::fromIndex(hexdec(substr($data, $i, 2)));
+ }
+ return $l;
+ }
+
+ /**
+ * 日忌
+ * @param SixtyCycle $month 月干支
+ * @param SixtyCycle $day 日干支
+ * @return Taboo[] 宜忌列表
+ */
+ static function getDayAvoids(SixtyCycle $month, SixtyCycle $day): array
+ {
+ $l = array();
+ $data = explode(',', explode(';', static::$dayTaboo[$month->getEarthBranch()->getIndex()])[$day->getIndex()])[1];
+ for ($i = 0, $j = strlen($data); $i < $j; $i += 2) {
+ $l[] = static::fromIndex(hexdec(substr($data, $i, 2)));
+ }
+ return $l;
+ }
+
+ /**
+ * 时宜
+ * @param SixtyCycle $day 日干支
+ * @param SixtyCycle $hour 时干支
+ * @return Taboo[] 宜忌列表
+ */
+ static function getHourRecommends(SixtyCycle $day, SixtyCycle $hour): array
+ {
+ $l = array();
+ $data = explode(',', explode(';', static::$hourTaboo[$hour->getEarthBranch()->getIndex()])[$day->getIndex()])[0];
+ for ($i = 0, $j = strlen($data); $i < $j; $i += 2) {
+ $l[] = static::fromIndex(hexdec(substr($data, $i, 2)));
+ }
+ return $l;
+ }
+
+ /**
+ * 时忌
+ * @param SixtyCycle $day 日干支
+ * @param SixtyCycle $hour 时干支
+ * @return Taboo[] 宜忌列表
+ */
+ static function getHourAvoids(SixtyCycle $day, SixtyCycle $hour): array
+ {
+ $l = array();
+ $data = explode(',', explode(';', static::$hourTaboo[$hour->getEarthBranch()->getIndex()])[$day->getIndex()])[1];
+ for ($i = 0, $j = strlen($data); $i < $j; $i += 2) {
+ $l[] = static::fromIndex(hexdec(substr($data, $i, 2)));
+ }
+ return $l;
+ }
+}
diff --git a/src/eightchar/DecadeFortune.php b/src/eightchar/DecadeFortune.php
index d47837c..a0bdccb 100644
--- a/src/eightchar/DecadeFortune.php
+++ b/src/eightchar/DecadeFortune.php
@@ -62,7 +62,7 @@ function getEndAge(): int
*/
function getStartLunarYear(): LunarYear
{
- return $this->childLimit->getEndTime()->getLunarHour()->getDay()->getMonth()->getYear()->next($this->index * 10);
+ return $this->childLimit->getEndTime()->getLunarHour()->getLunarDay()->getLunarMonth()->getLunarYear()->next($this->index * 10);
}
/**
diff --git a/src/eightchar/EightChar.php b/src/eightchar/EightChar.php
index 3617729..bd90b7e 100644
--- a/src/eightchar/EightChar.php
+++ b/src/eightchar/EightChar.php
@@ -178,11 +178,11 @@ function getSolarTimes(int $startYear, int $endYear): array
$term = $term->next($m);
}
$solarTime = $term->getJulianDay()->getSolarTime();
- if ($solarTime->getDay()->getMonth()->getYear()->getYear() >= $startYear) {
+ if ($solarTime->getYear() >= $startYear) {
$mi = 0;
$s = 0;
// 日干支和节令干支的偏移值
- $solarDay = $solarTime->getDay();
+ $solarDay = $solarTime->getSolarDay();
$d = $this->day->next(-$solarDay->getLunarDay()->getSixtyCycle()->getIndex())->getIndex();
if ($d > 0) {
// 从节令推移天数
@@ -192,8 +192,7 @@ function getSolarTimes(int $startYear, int $endYear): array
$mi = $solarTime->getMinute();
$s = $solarTime->getSecond();
}
- $solarMonth = $solarDay->getMonth();
- $time = SolarTime::fromYmdHms($solarMonth->getYear()->getYear(), $solarMonth->getMonth(), $solarDay->getDay(), $h, $mi, $s);
+ $time = SolarTime::fromYmdHms($solarDay->getYear(), $solarDay->getMonth(), $solarDay->getDay(), $h, $mi, $s);
// 验证一下
if ($time->getLunarHour()->getEightChar()->equals($this)) {
$l[] = $time;
diff --git a/src/eightchar/Fortune.php b/src/eightchar/Fortune.php
index a72ed26..d95bfb1 100644
--- a/src/eightchar/Fortune.php
+++ b/src/eightchar/Fortune.php
@@ -52,7 +52,7 @@ function getAge(): int
*/
function getLunarYear(): LunarYear
{
- return $this->childLimit->getEndTime()->getLunarHour()->getDay()->getMonth()->getYear()->next($this->index);
+ return $this->childLimit->getEndTime()->getLunarHour()->getLunarDay()->getLunarMonth()->getLunarYear()->next($this->index);
}
/**
diff --git a/src/eightchar/provider/impl/China95ChildLimitProvider.php b/src/eightchar/provider/impl/China95ChildLimitProvider.php
index 2669161..d40b80a 100644
--- a/src/eightchar/provider/impl/China95ChildLimitProvider.php
+++ b/src/eightchar/provider/impl/China95ChildLimitProvider.php
@@ -26,17 +26,15 @@ function getInfo(SolarTime $birthTime, SolarTerm $term): ChildLimitInfo
$minutes %= 360;
$day = intdiv($minutes, 12);
- $birthday = $birthTime->getDay();
- $birthMonth = $birthday->getMonth();
- $sm = SolarMonth::fromYm($birthMonth->getYear()->getYear() + $year, $birthMonth->getMonth())->next($month);
+ $sm = SolarMonth::fromYm($birthTime->getYear() + $year, $birthTime->getMonth())->next($month);
- $d = $birthday->getDay() + $day;
+ $d = $birthTime->getDay() + $day;
$dc = $sm->getDayCount();
if ($d > $dc) {
$d -= $dc;
$sm = $sm->next(1);
}
- return new ChildLimitInfo($birthTime, SolarTime::fromYmdHms($sm->getYear()->getYear(), $sm->getMonth(), $d, $birthTime->getHour(), $birthTime->getMinute(), $birthTime->getSecond()), $year, $month, $day, 0, 0);
+ return new ChildLimitInfo($birthTime, SolarTime::fromYmdHms($sm->getYear(), $sm->getMonth(), $d, $birthTime->getHour(), $birthTime->getMinute(), $birthTime->getSecond()), $year, $month, $day, 0, 0);
}
}
diff --git a/src/eightchar/provider/impl/DefaultChildLimitProvider.php b/src/eightchar/provider/impl/DefaultChildLimitProvider.php
index 0c9a3bf..f940193 100644
--- a/src/eightchar/provider/impl/DefaultChildLimitProvider.php
+++ b/src/eightchar/provider/impl/DefaultChildLimitProvider.php
@@ -35,10 +35,7 @@ function getInfo(SolarTime $birthTime, SolarTerm $term): ChildLimitInfo
// 1秒 = 2分,1秒/2=0.5秒 = 1分
$minute = $seconds * 2;
- $birthday = $birthTime->getDay();
- $birthMonth = $birthday->getMonth();
-
- $d = $birthday->getDay() + $day;
+ $d = $birthTime->getDay() + $day;
$h = $birthTime->getHour() + $hour;
$mi = $birthTime->getMinute() + $minute;
$h += intdiv($mi, 60);
@@ -46,7 +43,7 @@ function getInfo(SolarTime $birthTime, SolarTerm $term): ChildLimitInfo
$d += intdiv($h, 24);
$h %= 24;
- $sm = SolarMonth::fromYm($birthMonth->getYear()->getYear() + $year, $birthMonth->getMonth())->next($month);
+ $sm = SolarMonth::fromYm($birthTime->getYear() + $year, $birthTime->getMonth())->next($month);
$dc = $sm->getDayCount();
if ($d > $dc) {
@@ -54,6 +51,6 @@ function getInfo(SolarTime $birthTime, SolarTerm $term): ChildLimitInfo
$sm = $sm->next(1);
}
- return new ChildLimitInfo($birthTime, SolarTime::fromYmdHms($sm->getYear()->getYear(), $sm->getMonth(), $d, $h, $mi, $birthTime->getSecond()), $year, $month, $day, $hour, $minute);
+ return new ChildLimitInfo($birthTime, SolarTime::fromYmdHms($sm->getYear(), $sm->getMonth(), $d, $h, $mi, $birthTime->getSecond()), $year, $month, $day, $hour, $minute);
}
}
diff --git a/src/festival/LunarFestival.php b/src/festival/LunarFestival.php
index 13f5a1f..92142cd 100644
--- a/src/festival/LunarFestival.php
+++ b/src/festival/LunarFestival.php
@@ -84,15 +84,14 @@ static function fromYmd(int $year, int $month, int $day): ?static
$data = $matches[0][0];
$solarTerm = SolarTerm::fromIndex($year, intval(substr($data, 4, 2)));
$lunarDay = $solarTerm->getJulianDay()->getSolarDay()->getLunarDay();
- $lunarMonth = $lunarDay->getMonth();
- if ($lunarMonth->getYear()->getYear() == $year && $lunarMonth->getMonth() == $month && $lunarDay->getDay() == $day) {
+ if ($lunarDay->getYear() == $year && $lunarDay->getMonth() == $month && $lunarDay->getDay() == $day) {
return new static(FestivalType::TERM, $lunarDay, $solarTerm, $data);
}
}
if (preg_match_all('/@\\d{2}2/', static::$DATA, $matches)) {
$lunarDay = LunarDay::fromYmd($year, $month, $day);
$nextDay = $lunarDay->next(1);
- if ($nextDay->getMonth()->getMonth() == 1 && $nextDay->getDay() == 1) {
+ if ($nextDay->getMonth() == 1 && $nextDay->getDay() == 1) {
return new static(FestivalType::EVE, $lunarDay, null, $matches[0][0]);
}
}
@@ -101,10 +100,8 @@ static function fromYmd(int $year, int $month, int $day): ?static
function next(int $n): static
{
- $m = $this->day->getMonth();
- $year = $m->getYear()->getYear();
if ($n == 0) {
- return static::fromYmd($year, $m->getMonthWithLeap(), $this->day->getDay());
+ return static::fromYmd($this->day->getYear(), $this->day->getMonth(), $this->day->getDay());
}
$size = count(self::$NAMES);
$t = $this->index + $n;
@@ -112,7 +109,7 @@ function next(int $n): static
if ($t < 0) {
$t -= $size;
}
- return static::fromIndex($year + intdiv($t, $size), $offset);
+ return static::fromIndex($this->day->getYear() + intdiv($t, $size), $offset);
}
function __toString(): string
diff --git a/src/festival/SolarFestival.php b/src/festival/SolarFestival.php
index 518ca6a..8c12c99 100644
--- a/src/festival/SolarFestival.php
+++ b/src/festival/SolarFestival.php
@@ -85,10 +85,8 @@ static function fromYmd(int $year, int $month, int $day): ?static
function next(int $n): static
{
- $m = $this->day->getMonth();
- $year = $m->getYear()->getYear();
if ($n == 0) {
- return static::fromYmd($year, $m->getMonth(), $this->day->getDay());
+ return static::fromYmd($this->day->getYear(), $this->day->getMonth(), $this->day->getDay());
}
$size = count(static::$NAMES);
$t = $this->index + $n;
@@ -96,7 +94,7 @@ function next(int $n): static
if ($t < 0) {
$t -= $size;
}
- return static::fromIndex($year + intdiv($t, $size), $offset);
+ return static::fromIndex($this->day->getYear() + intdiv($t, $size), $offset);
}
function __toString(): string
diff --git a/src/holiday/LegalHoliday.php b/src/holiday/LegalHoliday.php
index bd38f93..b398f39 100644
--- a/src/holiday/LegalHoliday.php
+++ b/src/holiday/LegalHoliday.php
@@ -49,9 +49,8 @@ static function fromYmd(int $year, int $month, int $day): ?static
function next(int $n): ?static
{
- $m = $this->day->getMonth();
- $year = $m->getYear()->getYear();
- $month = $m->getMonth();
+ $year = $this->day->getYear();
+ $month = $this->day->getMonth();
if ($n == 0) {
return static::fromYmd($year, $month, $this->day->getDay());
}
diff --git a/src/lunar/LunarDay.php b/src/lunar/LunarDay.php
index 2170458..802d9e7 100644
--- a/src/lunar/LunarDay.php
+++ b/src/lunar/LunarDay.php
@@ -7,11 +7,13 @@
use com\tyme\culture\Direction;
use com\tyme\culture\Duty;
use com\tyme\culture\fetus\FetusDay;
+use com\tyme\culture\God;
use com\tyme\culture\Phase;
use com\tyme\culture\star\nine\NineStar;
use com\tyme\culture\star\six\SixStar;
use com\tyme\culture\star\twelve\TwelveStar;
use com\tyme\culture\star\twentyeight\TwentyEightStar;
+use com\tyme\culture\Taboo;
use com\tyme\culture\Week;
use com\tyme\festival\LunarFestival;
use com\tyme\sixtycycle\EarthBranch;
@@ -56,15 +58,35 @@ static function fromYmd(int $year, int $month, int $day): static
}
/**
- * 月
+ * 农历月
*
- * @return LunarMonth 月
+ * @return LunarMonth 农历月
*/
- function getMonth(): LunarMonth
+ function getLunarMonth(): LunarMonth
{
return $this->month;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->month->getYear();
+ }
+
+ /**
+ * 月
+ *
+ * @return int 月,闰月为负数
+ */
+ function getMonth(): int
+ {
+ return $this->month->getMonthWithLeap();
+ }
+
/**
* 日
*
@@ -88,24 +110,24 @@ function __toString(): string
function next(int $n): LunarDay
{
if ($n == 0) {
- return self::fromYmd($this->month->getYear()->getYear(), $this->month->getMonthWithLeap(), $this->day);
+ return self::fromYmd($this->getYear(), $this->getMonth(), $this->day);
}
$d = $this->day + $n;
$m = $this->month;
- $daysInMonth = $m->getDayCount();
+ $dayCount = $m->getDayCount();
$forward = $n > 0;
$add = $forward ? 1 : -1;
- while ($forward ? ($d > $daysInMonth) : ($d <= 0)) {
+ while ($forward ? ($d > $dayCount) : ($d <= 0)) {
if ($forward) {
- $d -= $daysInMonth;
+ $d -= $dayCount;
}
$m = $m->next($add);
- $daysInMonth = $m->getDayCount();
+ $dayCount = $m->getDayCount();
if (!$forward) {
- $d += $daysInMonth;
+ $d += $dayCount;
}
}
- return self::fromYmd($m->getYear()->getYear(), $m->getMonthWithLeap(), $d);
+ return self::fromYmd($m->getYear(), $m->getMonthWithLeap(), $d);
}
/**
@@ -116,17 +138,15 @@ function next(int $n): LunarDay
*/
function isBefore(LunarDay $target): bool
{
- $bMonth = $target->getMonth();
- $aYear = $this->month->getYear()->getYear();
- $bYear = $bMonth->getYear()->getYear();
+ $aYear = $this->getYear();
+ $bYear = $target->getYear();
if ($aYear != $bYear) {
return $aYear < $bYear;
}
- if ($this->month->getMonth() != $bMonth->getMonth()) {
- return $this->month->getMonth() < $bMonth->getMonth();
- }
- if ($this->month->isLeap() && !$bMonth->isLeap()) {
- return false;
+ $aMonth = $this->getMonth();
+ $bMonth = $target->getMonth();
+ if ($aMonth != $bMonth) {
+ return abs($aMonth) < abs($bMonth);
}
return $this->day < $target->getDay();
}
@@ -139,17 +159,15 @@ function isBefore(LunarDay $target): bool
*/
function isAfter(LunarDay $target): bool
{
- $targetMonth = $target->getMonth();
- $aYear = $this->month->getYear()->getYear();
- $bYear = $targetMonth->getYear()->getYear();
+ $aYear = $this->getYear();
+ $bYear = $target->getYear();
if ($aYear != $bYear) {
return $aYear > $bYear;
}
- if ($this->month->getMonth() != $targetMonth->getMonth()) {
- return $this->month->getMonth() > $targetMonth->getMonth();
- }
- if ($this->month->isLeap() && !$targetMonth->isLeap()) {
- return true;
+ $aMonth = $this->getMonth();
+ $bMonth = $target->getMonth();
+ if ($aMonth != $bMonth) {
+ return abs($aMonth) >= abs($bMonth);
}
return $this->day > $target->getDay();
}
@@ -172,9 +190,9 @@ function getWeek(): Week
function getYearSixtyCycle(): SixtyCycle
{
$solarDay = $this->getSolarDay();
- $solarYear = $solarDay->getMonth()->getYear()->getYear();
+ $solarYear = $solarDay->getYear();
$springSolarDay = SolarTerm::fromIndex($solarYear, 3)->getJulianDay()->getSolarDay();
- $lunarYear = $this->month->getYear();
+ $lunarYear = $this->month->getLunarYear();
$year = $lunarYear->getYear();
$sixtyCycle = $lunarYear->getSixtyCycle();
if ($year == $solarYear) {
@@ -197,7 +215,7 @@ function getYearSixtyCycle(): SixtyCycle
function getMonthSixtyCycle(): SixtyCycle
{
$solarDay = $this->getSolarDay();
- $year = $solarDay->getMonth()->getYear()->getYear();
+ $year = $solarDay->getYear();
$term = $solarDay->getTerm();
$index = $term->getIndex() - 3;
if ($index < 0 && $term->getJulianDay()->getSolarDay()->isAfter(SolarTerm::fromIndex($year, 3)->getJulianDay()->getSolarDay())) {
@@ -245,7 +263,7 @@ function getTwelveStar(): TwelveStar
function getNineStar(): NineStar
{
$solar = $this->getSolarDay();
- $dongZhi = SolarTerm::fromIndex($solar->getMonth()->getYear()->getYear(), 0);
+ $dongZhi = SolarTerm::fromIndex($solar->getYear(), 0);
$xiaZhi = $dongZhi->next(12);
$dongZhi2 = $dongZhi->next(24);
$dongZhiSolar = $dongZhi->getJulianDay()->getSolarDay();
@@ -281,7 +299,7 @@ function getJupiterDirection(): Direction
if ($index % 12 < 6) {
return Direction::fromIndex([2, 8, 4, 6, 0][intdiv($index, 12)]);
}
- return $this->month->getYear()->getJupiterDirection();
+ return $this->month->getLunarYear()->getJupiterDirection();
}
/**
@@ -331,7 +349,7 @@ function getTwentyEightStar(): TwentyEightStar
*/
function getFestival(): ?LunarFestival
{
- return LunarFestival::fromYmd($this->month->getYear()->getYear(), $this->month->getMonthWithLeap(), $this->day);
+ return LunarFestival::fromYmd($this->getYear(), $this->getMonth(), $this->day);
}
/**
@@ -340,8 +358,8 @@ function getFestival(): ?LunarFestival
*/
function getHours(): array
{
- $y = $this->month->getYear()->getYear();
- $m = $this->month->getMonth();
+ $y = $this->getYear();
+ $m = $this->getMonth();
$l = array();
$l[] = LunarHour::fromYmdHms($y, $m, $this->day, 0, 0, 0);
for ($i = 0; $i < 24; $i += 2) {
@@ -350,6 +368,33 @@ function getHours(): array
return $l;
}
+ /**
+ * 神煞列表(吉神宜趋,凶神宜忌)
+ * @return God[] 神煞列表
+ */
+ function getGods(): array
+ {
+ return God::getDayGods($this->getMonthSixtyCycle(), $this->getSixtyCycle());
+ }
+
+ /**
+ * 宜
+ * @return Taboo[] 宜忌列表
+ */
+ function getRecommends(): array
+ {
+ return Taboo::getDayRecommends($this->getMonthSixtyCycle(), $this->getSixtyCycle());
+ }
+
+ /**
+ * 忌
+ * @return Taboo[] 宜忌列表
+ */
+ function getAvoids(): array
+ {
+ return Taboo::getDayAvoids($this->getMonthSixtyCycle(), $this->getSixtyCycle());
+ }
+
/**
* 六曜
* @return SixStar 六曜
diff --git a/src/lunar/LunarHour.php b/src/lunar/LunarHour.php
index 92e83c1..d19520e 100644
--- a/src/lunar/LunarHour.php
+++ b/src/lunar/LunarHour.php
@@ -5,6 +5,7 @@
use com\tyme\AbstractTyme;
use com\tyme\culture\star\nine\NineStar;
+use com\tyme\culture\Taboo;
use com\tyme\eightchar\EightChar;
use com\tyme\sixtycycle\EarthBranch;
use com\tyme\sixtycycle\HeavenStem;
@@ -67,11 +68,41 @@ static function fromYmdHms(int $year, int $month, int $day, int $hour, int $minu
*
* @return LunarDay 农历日
*/
- function getDay(): LunarDay
+ function getLunarDay(): LunarDay
{
return $this->day;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->day->getYear();
+ }
+
+ /**
+ * 月
+ *
+ * @return int 月,闰月为负数
+ */
+ function getMonth(): int
+ {
+ return $this->day->getMonth();
+ }
+
+ /**
+ * 日
+ *
+ * @return int 日
+ */
+ function getDay(): int
+ {
+ return $this->day->getDay();
+ }
+
/**
* 时
*
@@ -125,8 +156,8 @@ function getIndexInDay(): int
*/
function isBefore(LunarHour $target): bool
{
- if (!$this->day->equals($target->getDay())) {
- return $this->day->isBefore($target->getDay());
+ if (!$this->day->equals($target->getLunarDay())) {
+ return $this->day->isBefore($target->getLunarDay());
}
if ($this->hour != $target->getHour()) {
return $this->hour < $target->getHour();
@@ -142,8 +173,8 @@ function isBefore(LunarHour $target): bool
*/
function isAfter(LunarHour $target): bool
{
- if (!$this->day->equals($target->getDay())) {
- return $this->day->isAfter($target->getDay());
+ if (!$this->day->equals($target->getLunarDay())) {
+ return $this->day->isAfter($target->getLunarDay());
}
if ($this->hour != $target->getHour()) {
return $this->hour > $target->getHour();
@@ -163,8 +194,7 @@ function next(int $n): LunarHour
$days--;
}
$d = $this->day->next($days);
- $month = $d->getMonth();
- return self::fromYmdHms($month->getYear()->getYear(), $month->getMonthWithLeap(), $d->getDay(), $hour, $this->minute, $this->second);
+ return self::fromYmdHms($d->getYear(), $d->getMonth(), $d->getDay(), $hour, $this->minute, $this->second);
}
/**
@@ -175,9 +205,9 @@ function next(int $n): LunarHour
function getYearSixtyCycle(): SixtyCycle
{
$solarTime = $this->getSolarTime();
- $solarYear = $this->day->getSolarDay()->getMonth()->getYear()->getYear();
+ $solarYear = $this->day->getSolarDay()->getYear();
$springSolarTime = SolarTerm::fromIndex($solarYear, 3)->getJulianDay()->getSolarTime();
- $lunarYear = $this->day->getMonth()->getYear();
+ $lunarYear = $this->day->getLunarMonth()->getLunarYear();
$year = $lunarYear->getYear();
$sixtyCycle = $lunarYear->getSixtyCycle();
if ($year == $solarYear) {
@@ -200,7 +230,7 @@ function getYearSixtyCycle(): SixtyCycle
function getMonthSixtyCycle(): SixtyCycle
{
$solarTime = $this->getSolarTime();
- $year = $solarTime->getDay()->getMonth()->getYear()->getYear();
+ $year = $solarTime->getYear();
$term = $solarTime->getTerm();
$index = $term->getIndex() - 3;
if ($index < 0 && $term->getJulianDay()->getSolarTime()->isAfter(SolarTerm::fromIndex($year, 3)->getJulianDay()->getSolarTime())) {
@@ -240,7 +270,7 @@ function getSixtyCycle(): SixtyCycle
function getNineStar(): NineStar
{
$solar = $this->day->getSolarDay();
- $dongZhi = SolarTerm::fromIndex($solar->getMonth()->getYear()->getYear(), 0);
+ $dongZhi = SolarTerm::fromIndex($solar->getYear(), 0);
$xiaZhi = $dongZhi->next(12);
$asc = !$solar->isBefore($dongZhi->getJulianDay()->getSolarDay()) && $solar->isBefore($xiaZhi->getJulianDay()->getSolarDay());
$start = [8, 5, 2][$this->day->getSixtyCycle()->getEarthBranch()->getIndex() % 3];
@@ -259,8 +289,7 @@ function getNineStar(): NineStar
function getSolarTime(): SolarTime
{
$d = $this->day->getSolarDay();
- $m = $d->getMonth();
- return SolarTime::fromYmdHms($m->getYear()->getYear(), $m->getMonth(), $d->getDay(), $this->hour, $this->minute, $this->second);
+ return SolarTime::fromYmdHms($d->getYear(), $d->getMonth(), $d->getDay(), $this->hour, $this->minute, $this->second);
}
/**
@@ -273,6 +302,24 @@ function getEightChar(): EightChar
return new EightChar($this->getYearSixtyCycle(), $this->getMonthSixtyCycle(), $this->getDaySixtyCycle(), $this->getSixtyCycle());
}
+ /**
+ * 宜
+ * @return Taboo[] 宜忌列表
+ */
+ function getRecommends(): array
+ {
+ return Taboo::getHourRecommends($this->getDaySixtyCycle(), $this->getSixtyCycle());
+ }
+
+ /**
+ * 忌
+ * @return Taboo[] 宜忌列表
+ */
+ function getAvoids(): array
+ {
+ return Taboo::getHourAvoids($this->getDaySixtyCycle(), $this->getSixtyCycle());
+ }
+
function equals(mixed $o): bool
{
if (!($o instanceof LunarHour)) {
diff --git a/src/lunar/LunarMonth.php b/src/lunar/LunarMonth.php
index 3b99f3a..4f9937b 100644
--- a/src/lunar/LunarMonth.php
+++ b/src/lunar/LunarMonth.php
@@ -114,11 +114,21 @@ static function fromYm(int $year, int $month): static
*
* @return LunarYear 农历年
*/
- function getYear(): LunarYear
+ function getLunarYear(): LunarYear
{
return $this->year;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->year->getYear();
+ }
+
/**
* 月
*
@@ -218,7 +228,7 @@ function __toString(): string
function next(int $n): LunarMonth
{
if ($n == 0) {
- return static::fromYm($this->year->getYear(), $this->getMonthWithLeap());
+ return static::fromYm($this->getYear(), $this->getMonthWithLeap());
}
$m = $this->indexInYear + 1 + $n;
$y = $this->year;
@@ -257,7 +267,7 @@ function next(int $n): LunarMonth
function getDays(): array
{
$size = $this->getDayCount();
- $y = $this->year->getYear();
+ $y = $this->getYear();
$m = $this->getMonthWithLeap();
$l = array();
for ($i = 0; $i < $size; $i++) {
@@ -275,7 +285,7 @@ function getDays(): array
function getWeeks(int $start): array
{
$size = $this->getWeekCount($start);
- $y = $this->year->getYear();
+ $y = $this->getYear();
$m = $this->getMonthWithLeap();
$l = array();
for ($i = 0; $i < $size; $i++) {
@@ -331,7 +341,7 @@ function equals(mixed $o): bool
if (!($o instanceof LunarMonth)) {
return false;
}
- return $this->year->equals($o->getYear()) && $this->getMonthWithLeap() == $o->getMonthWithLeap();
+ return $this->getYear() == $o->getYear() && $this->getMonthWithLeap() == $o->getMonthWithLeap();
}
}
diff --git a/src/lunar/LunarWeek.php b/src/lunar/LunarWeek.php
index 4f62165..707a516 100644
--- a/src/lunar/LunarWeek.php
+++ b/src/lunar/LunarWeek.php
@@ -54,15 +54,35 @@ static function fromYm(int $year, int $month, int $index, int $start): static
}
/**
- * 月
+ * 农历月
*
- * @return LunarMonth 月
+ * @return LunarMonth 农历月
*/
- function getMonth(): LunarMonth
+ function getLunarMonth(): LunarMonth
{
return $this->month;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->month->getYear();
+ }
+
+ /**
+ * 月
+ *
+ * @return int 月
+ */
+ function getMonth(): int
+ {
+ return $this->month->getMonthWithLeap();
+ }
+
/**
* 索引
*
@@ -96,34 +116,34 @@ function __toString(): string
function next(int $n): static
{
if ($n == 0) {
- return static::fromYm($this->month->getYear()->getYear(), $this->month->getMonthWithLeap(), $this->index, $this->start->getIndex());
+ return static::fromYm($this->getYear(), $this->getMonth(), $this->index, $this->start->getIndex());
}
$d = $this->index + $n;
$m = $this->month;
$startIndex = $this->start->getIndex();
- $weeksInMonth = $m->getWeekCount($startIndex);
+ $weekCount = $m->getWeekCount($startIndex);
$forward = $n > 0;
$add = $forward ? 1 : -1;
- while ($forward ? ($d >= $weeksInMonth) : ($d < 0)) {
+ while ($forward ? ($d >= $weekCount) : ($d < 0)) {
if ($forward) {
- $d -= $weeksInMonth;
+ $d -= $weekCount;
} else {
- if (!LunarDay::fromYmd($m->getYear()->getYear(), $m->getMonthWithLeap(), 1)->getWeek()->equals($this->start)) {
+ if (!LunarDay::fromYmd($m->getYear(), $m->getMonthWithLeap(), 1)->getWeek()->equals($this->start)) {
$d += $add;
}
}
$m = $m->next($add);
if ($forward) {
- if (!LunarDay::fromYmd($m->getYear()->getYear(), $m->getMonthWithLeap(), 1)->getWeek()->equals($this->start)) {
+ if (!LunarDay::fromYmd($m->getYear(), $m->getMonthWithLeap(), 1)->getWeek()->equals($this->start)) {
$d += $add;
}
}
- $weeksInMonth = $m->getWeekCount($startIndex);
+ $weekCount = $m->getWeekCount($startIndex);
if (!$forward) {
- $d += $weeksInMonth;
+ $d += $weekCount;
}
}
- return static::fromYm($m->getYear()->getYear(), $m->getMonthWithLeap(), $d, $startIndex);
+ return static::fromYm($m->getYear(), $m->getMonthWithLeap(), $d, $startIndex);
}
/**
@@ -133,7 +153,7 @@ function next(int $n): static
*/
function getFirstDay(): LunarDay
{
- $firstDay = LunarDay::fromYmd($this->month->getYear()->getYear(), $this->month->getMonthWithLeap(), 1);
+ $firstDay = LunarDay::fromYmd($this->getYear(), $this->getMonth(), 1);
return $firstDay->next($this->index * 7 - $this->indexOf($firstDay->getWeek()->getIndex() - $this->start->getIndex(), null, 7));
}
diff --git a/src/solar/SolarDay.php b/src/solar/SolarDay.php
index f31e7a1..81d83e2 100644
--- a/src/solar/SolarDay.php
+++ b/src/solar/SolarDay.php
@@ -63,15 +63,35 @@ static function fromYmd(int $year, int $month, int $day): static
}
/**
- * 月
+ * 公历月
*
- * @return SolarMonth 月
+ * @return SolarMonth 公历月
*/
- function getMonth(): SolarMonth
+ function getSolarMonth(): SolarMonth
{
return $this->month;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->month->getYear();
+ }
+
+ /**
+ * 月
+ *
+ * @return int 月
+ */
+ function getMonth(): int
+ {
+ return $this->month->getMonth();
+ }
+
/**
* 日
*
@@ -100,7 +120,7 @@ function getWeek(): Week
function getConstellation(): Constellation
{
$index = 11;
- $y = $this->month->getMonth() * 100 + $this->day;
+ $y = $this->getMonth() * 100 + $this->day;
if ($y >= 321 && $y <= 419) {
$index = 0;
} else if ($y >= 420 && $y <= 520) {
@@ -150,13 +170,14 @@ function next(int $n): SolarDay
*/
function isBefore(SolarDay $target): bool
{
- $bMonth = $target->getMonth();
- $aYear = $this->month->getYear()->getYear();
- $bYear = $bMonth->getYear()->getYear();
+ $aYear = $this->getYear();
+ $bYear = $target->getYear();
if ($aYear != $bYear) {
return $aYear < $bYear;
}
- return $this->month->getMonth() != $bMonth->getMonth() ? $this->month->getMonth() < $bMonth->getMonth() : $this->day < $target->getDay();
+ $aMonth = $this->getMonth();
+ $bMonth = $target->getMonth();
+ return $aMonth != $bMonth ? $aMonth < $bMonth : $this->day < $target->getDay();
}
/**
@@ -167,13 +188,14 @@ function isBefore(SolarDay $target): bool
*/
function isAfter(SolarDay $target): bool
{
- $bMonth = $target->getMonth();
- $aYear = $this->month->getYear()->getYear();
- $bYear = $bMonth->getYear()->getYear();
+ $aYear = $this->getYear();
+ $bYear = $target->getYear();
if ($aYear != $bYear) {
return $aYear > $bYear;
}
- return $this->month->getMonth() != $bMonth->getMonth() ? $this->month->getMonth() > $bMonth->getMonth() : $this->day > $target->getDay();
+ $aMonth = $this->getMonth();
+ $bMonth = $target->getMonth();
+ return $aMonth != $bMonth ? $aMonth > $bMonth : $this->day > $target->getDay();
}
/**
@@ -193,8 +215,8 @@ function getTerm(): SolarTerm
*/
function getTermDay(): SolarTermDay
{
- $y = $this->month->getYear()->getYear();
- $i = $this->month->getMonth() * 2;
+ $y = $this->getYear();
+ $i = $this->getMonth() * 2;
if ($i == 24) {
$y += 1;
$i = 0;
@@ -216,8 +238,8 @@ function getTermDay(): SolarTermDay
*/
function getSolarWeek(int $start): SolarWeek
{
- $y = $this->month->getYear()->getYear();
- $m = $this->month->getMonth();
+ $y = $this->getYear();
+ $m = $this->getMonth();
return SolarWeek::fromYm($y, $m, (int)ceil(($this->day + SolarDay::fromYmd($y, $m, 1)->getWeek()->next(-$start)->getIndex()) / 7.0) - 1, $start);
}
@@ -245,7 +267,7 @@ function getPhenologyDay(): PhenologyDay
*/
function getDogDay(): ?DogDay
{
- $xiaZhi = SolarTerm::fromIndex($this->month->getYear()->getYear(), 12);
+ $xiaZhi = SolarTerm::fromIndex($this->getYear(), 12);
// 第1个庚日
$start = $xiaZhi->getJulianDay()->getSolarDay();
$add = 6 - $start->getLunarDay()->getSixtyCycle()->getHeavenStem()->getIndex();
@@ -293,7 +315,7 @@ function getDogDay(): ?DogDay
*/
function getNineDay(): ?NineDay
{
- $year = $this->month->getYear()->getYear();
+ $year = $this->getYear();
$start = SolarTerm::fromIndex($year + 1, 0)->getJulianDay()->getSolarDay();
if ($this->isBefore($start)) {
$start = SolarTerm::fromIndex($year, 0)->getJulianDay()->getSolarDay();
@@ -313,7 +335,7 @@ function getNineDay(): ?NineDay
function getPlumRainDay(): ?PlumRainDay
{
// 芒种
- $grainInEar = SolarTerm::fromIndex($this->month->getYear()->getYear(), 11);
+ $grainInEar = SolarTerm::fromIndex($this->getYear(), 11);
$start = $grainInEar->getJulianDay()->getSolarDay();
$add = 2 - $start->getLunarDay()->getSixtyCycle()->getHeavenStem()->getIndex();
if ($add < 0) {
@@ -345,7 +367,7 @@ function getPlumRainDay(): ?PlumRainDay
*/
function getIndexInYear(): int
{
- return $this->subtract(self::fromYmd($this->month->getYear()->getYear(), 1, 1));
+ return $this->subtract(self::fromYmd($this->getYear(), 1, 1));
}
/**
@@ -366,7 +388,7 @@ function subtract(SolarDay $target): int
*/
function getJulianDay(): JulianDay
{
- return JulianDay::fromYmdHms($this->month->getYear()->getYear(), $this->month->getMonth(), $this->day, 0, 0, 0);
+ return JulianDay::fromYmdHms($this->getYear(), $this->getMonth(), $this->day, 0, 0, 0);
}
/**
@@ -376,13 +398,13 @@ function getJulianDay(): JulianDay
*/
function getLunarDay(): LunarDay
{
- $m = LunarMonth::fromYm($this->month->getYear()->getYear(), $this->month->getMonth());
+ $m = LunarMonth::fromYm($this->getYear(), $this->getMonth());
$days = $this->subtract($m->getFirstJulianDay()->getSolarDay());
while ($days < 0) {
$m = $m->next(-1);
$days = $this->subtract($m->getFirstJulianDay()->getSolarDay());
}
- return LunarDay::fromYmd($m->getYear()->getYear(), $m->getMonthWithLeap(), $days + 1);
+ return LunarDay::fromYmd($m->getYear(), $m->getMonthWithLeap(), $days + 1);
}
/**
@@ -392,7 +414,7 @@ function getLunarDay(): LunarDay
*/
function getLegalHoliday(): ?LegalHoliday
{
- return LegalHoliday::fromYmd($this->month->getYear()->getYear(), $this->month->getMonth(), $this->day);
+ return LegalHoliday::fromYmd($this->getYear(), $this->getMonth(), $this->day);
}
/**
@@ -402,7 +424,7 @@ function getLegalHoliday(): ?LegalHoliday
*/
function getFestival(): ?SolarFestival
{
- return SolarFestival::fromYmd($this->month->getYear()->getYear(), $this->month->getMonth(), $this->day);
+ return SolarFestival::fromYmd($this->getYear(), $this->getMonth(), $this->day);
}
}
diff --git a/src/solar/SolarHalfYear.php b/src/solar/SolarHalfYear.php
index 4cc817f..461e41a 100644
--- a/src/solar/SolarHalfYear.php
+++ b/src/solar/SolarHalfYear.php
@@ -40,14 +40,23 @@ static function fromIndex(int $year, int $index): static
}
/**
- * 年
- * @return SolarYear 年
+ * 公历年
+ * @return SolarYear 公历年
*/
- function getYear(): SolarYear
+ function getSolarYear(): SolarYear
{
return $this->year;
}
+ /**
+ * 年
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->year->getYear();
+ }
+
/**
* 索引
*
@@ -71,10 +80,10 @@ function __toString(): string
function next(int $n): static
{
if ($n == 0) {
- return self::fromIndex($this->year->getYear(), $this->index);
+ return self::fromIndex($this->getYear(), $this->index);
}
$i = $this->index + $n;
- $y = $this->year->getYear() + intdiv($i, 2);
+ $y = $this->getYear() + intdiv($i, 2);
$i %= 2;
if ($i < 0) {
$i += 2;
@@ -91,7 +100,7 @@ function next(int $n): static
function getMonths(): array
{
$l = array();
- $y = $this->year->getYear();
+ $y = $this->getYear();
for ($i = 0; $i < 6; $i++) {
$l[] = SolarMonth::fromYm($y, $this->index * 6 + $i + 1);
}
@@ -106,7 +115,7 @@ function getMonths(): array
function getSeasons(): array
{
$l = array();
- $y = $this->year->getYear();
+ $y = $this->getYear();
for ($i = 0; $i < 2; $i++) {
$l[] = SolarSeason::fromIndex($y, $this->index * 2 + $i);
}
diff --git a/src/solar/SolarMonth.php b/src/solar/SolarMonth.php
index c13e69e..7373fbc 100644
--- a/src/solar/SolarMonth.php
+++ b/src/solar/SolarMonth.php
@@ -45,14 +45,23 @@ static function fromYm(int $year, int $month): static
}
/**
- * 年
- * @return SolarYear 年
+ * 公历年
+ * @return SolarYear 公历年
*/
- function getYear(): SolarYear
+ function getSolarYear(): SolarYear
{
return $this->year;
}
+ /**
+ * 年
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->year->getYear();
+ }
+
/**
* 月
*
@@ -70,7 +79,7 @@ function getMonth(): int
*/
function getDayCount(): int
{
- if (1582 == $this->year->getYear() && 10 == $this->month) {
+ if (1582 == $this->getYear() && 10 == $this->month) {
return 21;
}
$d = self::$DAYS[$this->getIndexInYear()];
@@ -98,7 +107,7 @@ function getIndexInYear(): int
*/
function getSeason(): SolarSeason
{
- return SolarSeason::fromIndex($this->year->getYear(), intdiv($this->getIndexInYear(), 3));
+ return SolarSeason::fromIndex($this->getYear(), intdiv($this->getIndexInYear(), 3));
}
/**
@@ -109,7 +118,7 @@ function getSeason(): SolarSeason
*/
function getWeekCount(int $start): int
{
- return (int)ceil(($this->indexOf(SolarDay::fromYmd($this->year->getYear(), $this->month, 1)->getWeek()->getIndex() - $start, null, 7) + $this->getDayCount()) / 7);
+ return (int)ceil(($this->indexOf(SolarDay::fromYmd($this->getYear(), $this->month, 1)->getWeek()->getIndex() - $start, null, 7) + $this->getDayCount()) / 7);
}
function getName(): string
@@ -125,10 +134,10 @@ function __toString(): string
function next(int $n): SolarMonth
{
if ($n == 0) {
- return self::fromYm($this->year->getYear(), $this->month);
+ return self::fromYm($this->getYear(), $this->month);
}
$m = $this->month + $n;
- $y = $this->year->getYear() + intdiv($m, 12);
+ $y = $this->getYear() + intdiv($m, 12);
$m %= 12;
if ($m < 1) {
$m += 12;
@@ -146,7 +155,7 @@ function next(int $n): SolarMonth
function getWeeks(int $start): array
{
$size = $this->getWeekCount($start);
- $y = $this->year->getYear();
+ $y = $this->getYear();
$l = array();
for ($i = 0; $i < $size; $i++) {
$l[] = SolarWeek::fromYm($y, $this->month, $i, $start);
@@ -162,7 +171,7 @@ function getWeeks(int $start): array
function getDays(): array
{
$size = $this->getDayCount();
- $y = $this->year->getYear();
+ $y = $this->getYear();
$l = array();
for ($i = 0; $i < $size; $i++) {
$l[] = SolarDay::fromYmd($y, $this->month, $i + 1);
diff --git a/src/solar/SolarSeason.php b/src/solar/SolarSeason.php
index b98db3c..8ac8544 100644
--- a/src/solar/SolarSeason.php
+++ b/src/solar/SolarSeason.php
@@ -40,14 +40,23 @@ static function fromIndex(int $year, int $index): static
}
/**
- * 年
- * @return SolarYear 年
+ * 公历年
+ * @return SolarYear 公历年
*/
- function getYear(): SolarYear
+ function getSolarYear(): SolarYear
{
return $this->year;
}
+ /**
+ * 年
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->year->getYear();
+ }
+
/**
* 索引
*
@@ -71,10 +80,10 @@ function __toString(): string
function next(int $n): static
{
if ($n == 0) {
- return self::fromIndex($this->year->getYear(), $this->index);
+ return self::fromIndex($this->getYear(), $this->index);
}
$i = $this->index + $n;
- $y = $this->year->getYear() + intdiv($i, 4);
+ $y = $this->getYear() + intdiv($i, 4);
$i %= 4;
if ($i < 0) {
$i += 4;
@@ -91,7 +100,7 @@ function next(int $n): static
function getMonths(): array
{
$l = array();
- $y = $this->year->getYear();
+ $y = $this->getYear();
for ($i = 0; $i < 3; $i++) {
$l[] = SolarMonth::fromYm($y, $this->index * 3 + $i + 1);
}
diff --git a/src/solar/SolarTime.php b/src/solar/SolarTime.php
index c868122..537423e 100644
--- a/src/solar/SolarTime.php
+++ b/src/solar/SolarTime.php
@@ -58,15 +58,45 @@ static function fromYmdHms(int $year, int $month, int $day, int $hour, int $minu
}
/**
- * 日
+ * 公历日
*
- * @return SolarDay 日
+ * @return SolarDay 公历日
*/
- function getDay(): SolarDay
+ function getSolarDay(): SolarDay
{
return $this->day;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->day->getYear();
+ }
+
+ /**
+ * 月
+ *
+ * @return int 月
+ */
+ function getMonth(): int
+ {
+ return $this->day->getMonth();
+ }
+
+ /**
+ * 日
+ *
+ * @return int 日
+ */
+ function getDay(): int
+ {
+ return $this->day->getDay();
+ }
+
/**
* 时
*
@@ -115,8 +145,8 @@ function __toString(): string
*/
function isBefore(SolarTime $target): bool
{
- if (!$this->day->equals($target->getDay())) {
- return $this->day->isBefore($target->getDay());
+ if (!$this->day->equals($target->getSolarDay())) {
+ return $this->day->isBefore($target->getSolarDay());
}
if ($this->hour != $target->getHour()) {
return $this->hour < $target->getHour();
@@ -132,8 +162,8 @@ function isBefore(SolarTime $target): bool
*/
function isAfter(SolarTime $target): bool
{
- if (!$this->day->equals($target->getDay())) {
- return $this->day->isAfter($target->getDay());
+ if (!$this->day->equals($target->getSolarDay())) {
+ return $this->day->isAfter($target->getSolarDay());
}
if ($this->hour != $target->getHour()) {
return $this->hour > $target->getHour();
@@ -148,9 +178,8 @@ function isAfter(SolarTime $target): bool
*/
function getTerm(): SolarTerm
{
- $m = $this->day->getMonth();
- $y = $m->getYear()->getYear();
- $i = $m->getMonth() * 2;
+ $y = $this->getYear();
+ $i = $this->getMonth() * 2;
if ($i == 24) {
$y += 1;
$i = 0;
@@ -169,8 +198,7 @@ function getTerm(): SolarTerm
*/
function getJulianDay(): JulianDay
{
- $month = $this->day->getMonth();
- return JulianDay::fromYmdHms($month->getYear()->getYear(), $month->getMonth(), $this->day->getDay(), $this->hour, $this->minute, $this->second);
+ return JulianDay::fromYmdHms($this->getYear(), $this->getMonth(), $this->getDay(), $this->hour, $this->minute, $this->second);
}
/**
@@ -181,7 +209,7 @@ function getJulianDay(): JulianDay
*/
function subtract(SolarTime $target): int
{
- $days = $this->day->subtract($target->getDay());
+ $days = $this->day->subtract($target->getSolarDay());
$cs = $this->hour * 3600 + $this->minute * 60 + $this->second;
$ts = $target->getHour() * 3600 + $target->getMinute() * 60 + $target->getSecond();
$seconds = $cs - $ts;
@@ -202,8 +230,7 @@ function subtract(SolarTime $target): int
function next(int $n): SolarTime
{
if ($n == 0) {
- $m = $this->day->getMonth();
- return self::fromYmdHms($m->getYear()->getYear(), $m->getMonth(), $this->day->getDay(), $this->hour, $this->minute, $this->second);
+ return self::fromYmdHms($this->getYear(), $this->getMonth(), $this->getDay(), $this->hour, $this->minute, $this->second);
}
$ts = $this->second + $n;
$tm = $this->minute + intdiv($ts, 60);
@@ -226,8 +253,7 @@ function next(int $n): SolarTime
}
$d = $this->day->next($td);
- $m = $d->getMonth();
- return self::fromYmdHms($m->getYear()->getYear(), $m->getMonth(), $d->getDay(), $th, $tm, $ts);
+ return self::fromYmdHms($d->getYear(), $d->getMonth(), $d->getDay(), $th, $tm, $ts);
}
/**
@@ -238,8 +264,7 @@ function next(int $n): SolarTime
function getLunarHour(): LunarHour
{
$d = $this->day->getLunarDay();
- $m = $d->getMonth();
- return LunarHour::fromYmdHms($m->getYear()->getYear(), $m->getMonthWithLeap(), $d->getDay(), $this->hour, $this->minute, $this->second);
+ return LunarHour::fromYmdHms($d->getYear(), $d->getMonth(), $d->getDay(), $this->hour, $this->minute, $this->second);
}
}
diff --git a/src/solar/SolarWeek.php b/src/solar/SolarWeek.php
index d6abe98..a71344e 100644
--- a/src/solar/SolarWeek.php
+++ b/src/solar/SolarWeek.php
@@ -54,15 +54,35 @@ static function fromYm(int $year, int $month, int $index, int $start): static
}
/**
- * 月
+ * 公历月
*
- * @return SolarMonth 月
+ * @return SolarMonth 公历月
*/
- function getMonth(): SolarMonth
+ function getSolarMonth(): SolarMonth
{
return $this->month;
}
+ /**
+ * 年
+ *
+ * @return int 年
+ */
+ function getYear(): int
+ {
+ return $this->month->getYear();
+ }
+
+ /**
+ * 月
+ *
+ * @return int 月
+ */
+ function getMonth(): int
+ {
+ return $this->month->getMonth();
+ }
+
/**
* 索引
*
@@ -82,7 +102,7 @@ function getIndexInYear(): int
{
$i = 0;
// 今年第1周
- $w = self::fromYm($this->month->getYear()->getYear(), 1, 0, $this->start->getIndex());
+ $w = self::fromYm($this->getYear(), 1, 0, $this->start->getIndex());
while (!$w->equals($this)) {
$w = $w->next(1);
$i += 1;
@@ -113,7 +133,7 @@ function __toString(): string
function next(int $n): static
{
if ($n == 0) {
- return static::fromYm($this->month->getYear()->getYear(), $this->month->getMonth(), $this->index, $this->start->getIndex());
+ return static::fromYm($this->getYear(), $this->getMonth(), $this->index, $this->start->getIndex());
}
$d = $this->index + $n;
$m = $this->month;
@@ -125,13 +145,13 @@ function next(int $n): static
if ($forward) {
$d -= $weekCount;
} else {
- if (!SolarDay::fromYmd($m->getYear()->getYear(), $m->getMonth(), 1)->getWeek()->equals($this->start)) {
+ if (!SolarDay::fromYmd($m->getYear(), $m->getMonth(), 1)->getWeek()->equals($this->start)) {
$d += $add;
}
}
$m = $m->next($add);
if ($forward) {
- if (!SolarDay::fromYmd($m->getYear()->getYear(), $m->getMonth(), 1)->getWeek()->equals($this->start)) {
+ if (!SolarDay::fromYmd($m->getYear(), $m->getMonth(), 1)->getWeek()->equals($this->start)) {
$d += $add;
}
}
@@ -140,7 +160,7 @@ function next(int $n): static
$d += $weekCount;
}
}
- return static::fromYm($m->getYear()->getYear(), $m->getMonth(), $d, $startIndex);
+ return static::fromYm($m->getYear(), $m->getMonth(), $d, $startIndex);
}
/**
@@ -150,8 +170,7 @@ function next(int $n): static
*/
function getFirstDay(): SolarDay
{
- $m = $this->getMonth();
- $firstDay = SolarDay::fromYmd($m->getYear()->getYear(), $m->getMonth(), 1);
+ $firstDay = SolarDay::fromYmd($this->getYear(), $this->getMonth(), 1);
return $firstDay->next($this->index * 7 - $this->indexOf($firstDay->getWeek()->getIndex() - $this->start->getIndex(), null, 7));
}
diff --git a/test/EightCharTest.php b/test/EightCharTest.php
index a2dcddd..e2685fd 100644
--- a/test/EightCharTest.php
+++ b/test/EightCharTest.php
@@ -274,9 +274,9 @@ function test13()
// 童限结束(即开始起运)的公历时刻
$this->assertEquals('1989年5月4日 18:24:00', $childLimit->getEndTime()->__toString());
// 童限开始(即出生)的农历年干支
- $this->assertEquals('癸亥', $childLimit->getStartTime()->getLunarHour()->getDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('癸亥', $childLimit->getStartTime()->getLunarHour()->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
// 童限结束(即开始起运)的农历年干支
- $this->assertEquals('己巳', $childLimit->getEndTime()->getLunarHour()->getDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('己巳', $childLimit->getEndTime()->getLunarHour()->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
// 第1轮大运
$decadeFortune = $childLimit->getStartDecadeFortune();
@@ -325,9 +325,9 @@ function test14()
// 童限结束(即开始起运)的公历时刻
$this->assertEquals('2001年2月11日 18:58:00', $childLimit->getEndTime()->__toString());
// 童限开始(即出生)的农历年干支
- $this->assertEquals('辛未', $childLimit->getStartTime()->getLunarHour()->getDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('辛未', $childLimit->getStartTime()->getLunarHour()->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
// 童限结束(即开始起运)的农历年干支
- $this->assertEquals('辛巳', $childLimit->getEndTime()->getLunarHour()->getDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('辛巳', $childLimit->getEndTime()->getLunarHour()->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
// 第1轮大运
$decadeFortune = $childLimit->getStartDecadeFortune();
diff --git a/test/GodTest.php b/test/GodTest.php
new file mode 100644
index 0000000..0dc885b
--- /dev/null
+++ b/test/GodTest.php
@@ -0,0 +1,102 @@
+getLunarDay();
+ $gods = $lunar->getGods();
+ $ji = array();
+ foreach ($gods as $god) {
+ if ('吉' == $god->getLuck()->getName()) {
+ $ji[] = $god->getName();
+ }
+ }
+
+ $xiong = array();
+ foreach ($gods as $god) {
+ if ('凶' == $god->getLuck()->getName()) {
+ $xiong[] = $god->getName();
+ }
+ }
+ $this->assertEquals(array('天恩', '续世', '明堂'), $ji);
+ $this->assertEquals(array('月煞', '月虚', '血支', '天贼', '五虚', '土符', '归忌', '血忌'), $xiong);
+ }
+
+
+ function test1()
+ {
+ $lunar = SolarDay::fromYmd(2029, 11, 16)->getLunarDay();
+ $gods = $lunar->getGods();
+ $ji = array();
+ foreach ($gods as $god) {
+ if ('吉' == $god->getLuck()->getName()) {
+ $ji[] = $god->getName();
+ }
+ }
+
+ $xiong = array();
+ foreach ($gods as $god) {
+ if ('凶' == $god->getLuck()->getName()) {
+ $xiong[] = $god->getName();
+ }
+ }
+ $this->assertEquals(array('天德合', '月空', '天恩', '益后', '金匮'), $ji);
+ $this->assertEquals(array('月煞', '月虚', '血支', '五虚'), $xiong);
+ }
+
+
+ function test2()
+ {
+ $lunar = SolarDay::fromYmd(1954, 7, 16)->getLunarDay();
+ $gods = $lunar->getGods();
+
+ // 吉神宜趋
+ $ji = array();
+ foreach ($gods as $god) {
+ if ('吉' == $god->getLuck()->getName()) {
+ $ji[] = $god->getName();
+ }
+ }
+
+ // 凶神宜忌
+ $xiong = array();
+ foreach ($gods as $god) {
+ if ('凶' == $god->getLuck()->getName()) {
+ $xiong[] = $god->getName();
+ }
+ }
+
+ $this->assertEquals(array('民日', '天巫', '福德', '天仓', '不将', '续世', '除神', '鸣吠'), $ji);
+ $this->assertEquals(array('劫煞', '天贼', '五虚', '五离'), $xiong);
+ }
+
+
+ function test3()
+ {
+ $lunar = SolarDay::fromYmd(2024, 12, 27)->getLunarDay();
+ $gods = $lunar->getGods();
+ $ji = array();
+ foreach ($gods as $god) {
+ if ('吉' == $god->getLuck()->getName()) {
+ $ji[] = $god->getName();
+ }
+ }
+
+ $xiong = array();
+ foreach ($gods as $god) {
+ if ('凶' == $god->getLuck()->getName()) {
+ $xiong[] = $god->getName();
+ }
+ }
+ $this->assertEquals(array('天恩', '四相', '阴德', '守日', '吉期', '六合', '普护', '宝光'), $ji);
+ $this->assertEquals(array('三丧', '鬼哭'), $xiong);
+ }
+}
diff --git a/test/LunarDayTest.php b/test/LunarDayTest.php
index 90667ad..07d6e69 100644
--- a/test/LunarDayTest.php
+++ b/test/LunarDayTest.php
@@ -116,12 +116,12 @@ function test21()
function test22()
{
- $this->assertEquals('甲辰', LunarDay::fromYmd(2024, 1, 1)->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('甲辰', LunarDay::fromYmd(2024, 1, 1)->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
}
function test23()
{
- $this->assertEquals('癸卯', LunarDay::fromYmd(2023, 12, 30)->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('癸卯', LunarDay::fromYmd(2023, 12, 30)->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
}
/**
@@ -160,7 +160,7 @@ function test25()
function test26()
{
$lunar = LunarDay::fromYmd(2005, 11, 23);
- $this->assertEquals('戊子', $lunar->getMonth()->getSixtyCycle()->getName());
+ $this->assertEquals('戊子', $lunar->getLunarMonth()->getSixtyCycle()->getName());
$this->assertEquals('戊子', $lunar->getMonthSixtyCycle()->getName());
}
}
diff --git a/test/LunarHourTest.php b/test/LunarHourTest.php
index 80fe8d9..137add5 100644
--- a/test/LunarHourTest.php
+++ b/test/LunarHourTest.php
@@ -64,16 +64,16 @@ function test8()
$this->assertEquals('甲子', $h->getSixtyCycle()->getName());
$this->assertEquals('己未', $h->getDaySixtyCycle()->getName());
- $this->assertEquals('戊午', $h->getDay()->getSixtyCycle()->getName());
- $this->assertEquals('农历癸卯年十一月十四', $h->getDay()->__toString());
+ $this->assertEquals('戊午', $h->getLunarDay()->getSixtyCycle()->getName());
+ $this->assertEquals('农历癸卯年十一月十四', $h->getLunarDay()->__toString());
$this->assertEquals('甲子', $h->getMonthSixtyCycle()->getName());
- $this->assertEquals('农历癸卯年十一月', $h->getDay()->getMonth()->__toString());
- $this->assertEquals('乙丑', $h->getDay()->getMonth()->getSixtyCycle()->getName());
+ $this->assertEquals('农历癸卯年十一月', $h->getLunarDay()->getLunarMonth()->__toString());
+ $this->assertEquals('乙丑', $h->getLunarDay()->getLunarMonth()->getSixtyCycle()->getName());
$this->assertEquals('癸卯', $h->getYearSixtyCycle()->getName());
- $this->assertEquals('农历癸卯年', $h->getDay()->getMonth()->getYear()->__toString());
- $this->assertEquals('癸卯', $h->getDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('农历癸卯年', $h->getLunarDay()->getLunarMonth()->getLunarYear()->__toString());
+ $this->assertEquals('癸卯', $h->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
}
function test9()
@@ -82,15 +82,15 @@ function test9()
$this->assertEquals('乙卯', $h->getSixtyCycle()->getName());
$this->assertEquals('戊午', $h->getDaySixtyCycle()->getName());
- $this->assertEquals('戊午', $h->getDay()->getSixtyCycle()->getName());
- $this->assertEquals('农历癸卯年十一月十四', $h->getDay()->__toString());
+ $this->assertEquals('戊午', $h->getLunarDay()->getSixtyCycle()->getName());
+ $this->assertEquals('农历癸卯年十一月十四', $h->getLunarDay()->__toString());
$this->assertEquals('甲子', $h->getMonthSixtyCycle()->getName());
- $this->assertEquals('农历癸卯年十一月', $h->getDay()->getMonth()->__toString());
- $this->assertEquals('乙丑', $h->getDay()->getMonth()->getSixtyCycle()->getName());
+ $this->assertEquals('农历癸卯年十一月', $h->getLunarDay()->getLunarMonth()->__toString());
+ $this->assertEquals('乙丑', $h->getLunarDay()->getLunarMonth()->getSixtyCycle()->getName());
$this->assertEquals('癸卯', $h->getYearSixtyCycle()->getName());
- $this->assertEquals('农历癸卯年', $h->getDay()->getMonth()->getYear()->__toString());
- $this->assertEquals('癸卯', $h->getDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('农历癸卯年', $h->getLunarDay()->getLunarMonth()->getLunarYear()->__toString());
+ $this->assertEquals('癸卯', $h->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
}
}
diff --git a/test/LunarMonthTest.php b/test/LunarMonthTest.php
index b0caf1e..fe4fed3 100644
--- a/test/LunarMonthTest.php
+++ b/test/LunarMonthTest.php
@@ -163,36 +163,36 @@ function test28()
function test29()
{
$d = SolarDay::fromYmd(2023, 10, 7)->getLunarDay();
- $this->assertEquals('壬戌', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('壬戌', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('辛酉', $d->getMonthSixtyCycle()->__toString());
}
function test30()
{
$d = SolarDay::fromYmd(2023, 10, 8)->getLunarDay();
- $this->assertEquals('壬戌', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('壬戌', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('壬戌', $d->getMonthSixtyCycle()->__toString());
}
function test31()
{
$d = SolarDay::fromYmd(2023, 10, 15)->getLunarDay();
- $this->assertEquals('九月', $d->getMonth()->getName());
- $this->assertEquals('癸亥', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('九月', $d->getLunarMonth()->getName());
+ $this->assertEquals('癸亥', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('壬戌', $d->getMonthSixtyCycle()->__toString());
}
function test32()
{
$d = SolarDay::fromYmd(2023, 11, 7)->getLunarDay();
- $this->assertEquals('癸亥', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('癸亥', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('壬戌', $d->getMonthSixtyCycle()->__toString());
}
function test33()
{
$d = SolarDay::fromYmd(2023, 11, 8)->getLunarDay();
- $this->assertEquals('癸亥', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('癸亥', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('癸亥', $d->getMonthSixtyCycle()->__toString());
}
@@ -220,21 +220,21 @@ function test35()
function test36()
{
$d = SolarDay::fromYmd(1983, 2, 15)->getLunarDay();
- $this->assertEquals('甲寅', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('甲寅', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('甲寅', $d->getMonthSixtyCycle()->__toString());
}
function test37()
{
$d = SolarDay::fromYmd(2023, 10, 30)->getLunarDay();
- $this->assertEquals('癸亥', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('癸亥', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('壬戌', $d->getMonthSixtyCycle()->__toString());
}
function test38()
{
$d = SolarDay::fromYmd(2023, 10, 19)->getLunarDay();
- $this->assertEquals('癸亥', $d->getMonth()->getSixtyCycle()->__toString());
+ $this->assertEquals('癸亥', $d->getLunarMonth()->getSixtyCycle()->__toString());
$this->assertEquals('壬戌', $d->getMonthSixtyCycle()->__toString());
}
diff --git a/test/PlumRainDayTest.php b/test/PlumRainDayTest.php
index 11df687..9aba149 100644
--- a/test/PlumRainDayTest.php
+++ b/test/PlumRainDayTest.php
@@ -19,24 +19,24 @@ function test0()
function test1()
{
$d = SolarDay::fromYmd(2024, 6, 11)->getPlumRainDay();
- $this->assertEquals("入梅", $d->getName());
- $this->assertEquals("入梅", $d->getPlumRain()->__toString());
- $this->assertEquals("入梅第1天", $d->__toString());
+ $this->assertEquals('入梅', $d->getName());
+ $this->assertEquals('入梅', $d->getPlumRain()->__toString());
+ $this->assertEquals('入梅第1天', $d->__toString());
}
function test2()
{
$d = SolarDay::fromYmd(2024, 7, 6)->getPlumRainDay();
- $this->assertEquals("出梅", $d->getName());
- $this->assertEquals("出梅", $d->getPlumRain()->__toString());
- $this->assertEquals("出梅", $d->__toString());
+ $this->assertEquals('出梅', $d->getName());
+ $this->assertEquals('出梅', $d->getPlumRain()->__toString());
+ $this->assertEquals('出梅', $d->__toString());
}
function test3()
{
$d = SolarDay::fromYmd(2024, 7, 5)->getPlumRainDay();
- $this->assertEquals("入梅", $d->getName());
- $this->assertEquals("入梅", $d->getPlumRain()->__toString());
- $this->assertEquals("入梅第25天", $d->__toString());
+ $this->assertEquals('入梅', $d->getName());
+ $this->assertEquals('入梅', $d->getPlumRain()->__toString());
+ $this->assertEquals('入梅第25天', $d->__toString());
}
}
diff --git a/test/SolarDayTest.php b/test/SolarDayTest.php
index dfb6c58..a44aefd 100644
--- a/test/SolarDayTest.php
+++ b/test/SolarDayTest.php
@@ -82,11 +82,21 @@ function test11()
function test22()
{
- $this->assertEquals('甲辰', SolarDay::fromYmd(2024, 2, 10)->getLunarDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('甲辰', SolarDay::fromYmd(2024, 2, 10)->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
}
function test23()
{
- $this->assertEquals('癸卯', SolarDay::fromYmd(2024, 2, 9)->getLunarDay()->getMonth()->getYear()->getSixtyCycle()->getName());
+ $this->assertEquals('癸卯', SolarDay::fromYmd(2024, 2, 9)->getLunarDay()->getLunarMonth()->getLunarYear()->getSixtyCycle()->getName());
+ }
+
+ function test24()
+ {
+ // 扩展方法
+ SolarDay::extend('myMethod', function () {
+ return sprintf('%04d-%02d-%02d', $this->getYear(), $this->getMonth(), $this->getDay());
+ });
+
+ $this->assertEquals('2024-02-09', SolarDay::fromYmd(2024, 2, 9)->myMethod());
}
}
diff --git a/test/SolarTermTest.php b/test/SolarTermTest.php
index 08834aa..e1f6c4d 100644
--- a/test/SolarTermTest.php
+++ b/test/SolarTermTest.php
@@ -70,13 +70,13 @@ function test3()
function test4()
{
// 大雪当天
- $this->assertEquals("大雪第1天", SolarDay::fromYmd(2023, 12, 7)->getTermDay()->__toString());
+ $this->assertEquals('大雪第1天', SolarDay::fromYmd(2023, 12, 7)->getTermDay()->__toString());
// 天数索引
$this->assertEquals(0, SolarDay::fromYmd(2023, 12, 7)->getTermDay()->getDayIndex());
- $this->assertEquals("大雪第2天", SolarDay::fromYmd(2023, 12, 8)->getTermDay()->__toString());
- $this->assertEquals("大雪第15天", SolarDay::fromYmd(2023, 12, 21)->getTermDay()->__toString());
+ $this->assertEquals('大雪第2天', SolarDay::fromYmd(2023, 12, 8)->getTermDay()->__toString());
+ $this->assertEquals('大雪第15天', SolarDay::fromYmd(2023, 12, 21)->getTermDay()->__toString());
- $this->assertEquals("冬至第1天", SolarDay::fromYmd(2023, 12, 22)->getTermDay()->__toString());
+ $this->assertEquals('冬至第1天', SolarDay::fromYmd(2023, 12, 22)->getTermDay()->__toString());
}
}
diff --git a/test/TabooTest.php b/test/TabooTest.php
new file mode 100644
index 0000000..9462c8e
--- /dev/null
+++ b/test/TabooTest.php
@@ -0,0 +1,87 @@
+getLunarDay()->getRecommends() as $t) {
+ $taboos[] = $t->getName();
+ }
+
+ $this->assertEquals(array('嫁娶', '祭祀', '理发', '作灶', '修饰垣墙', '平治道涂', '整手足甲', '沐浴', '冠笄'), $taboos);
+ }
+
+
+ function test1()
+ {
+ $taboos = array();
+ foreach (SolarDay::fromYmd(2024, 6, 26)->getLunarDay()->getAvoids() as $t) {
+ $taboos[] = $t->getName();
+ }
+
+ $this->assertEquals(array('破土', '出行', '栽种'), $taboos);
+ }
+
+
+ function test2()
+ {
+ $taboos = array();
+ foreach (SolarTime::fromYmdHms(2024, 6, 25, 4, 0, 0)->getLunarHour()->getRecommends() as $t) {
+ $taboos[] = $t->getName();
+ }
+
+ $this->assertEquals(array(), $taboos);
+ }
+
+
+ function test3()
+ {
+ $taboos = array();
+ foreach (SolarTime::fromYmdHms(2024, 6, 25, 4, 0, 0)->getLunarHour()->getAvoids() as $t) {
+ $taboos[] = $t->getName();
+ }
+
+ $this->assertEquals(array('诸事不宜'), $taboos);
+ }
+
+
+ function test4()
+ {
+ $taboos = array();
+ foreach (SolarTime::fromYmdHms(2024, 4, 22, 0, 0, 0)->getLunarHour()->getRecommends() as $t) {
+ $taboos[] = $t->getName();
+ }
+
+ $this->assertEquals(array('嫁娶', '交易', '开市', '安床', '祭祀', '求财'), $taboos);
+ }
+
+
+ function test5()
+ {
+ $taboos = array();
+ foreach (SolarTime::fromYmdHms(2024, 4, 22, 0, 0, 0)->getLunarHour()->getAvoids() as $t) {
+ $taboos[] = $t->getName();
+ }
+
+ $this->assertEquals(array('出行', '移徙', '赴任', '词讼', '祈福', '修造', '求嗣'), $taboos);
+ }
+
+
+ function test6()
+ {
+ $taboos = array();
+ foreach (SolarDay::fromYmd(2021, 3, 7)->getLunarDay()->getRecommends() as $t) {
+ $taboos[] = $t->getName();
+ }
+ $this->assertEquals(array('裁衣', '经络', '伐木', '开柱眼', '拆卸', '修造', '动土', '上梁', '合脊', '合寿木', '入殓', '除服', '成服', '移柩', '破土', '安葬', '启钻', '修坟', '立碑'), $taboos);
+ }
+}
diff --git a/test/WeekTest.php b/test/WeekTest.php
index 458f7fd..bc8fdbc 100644
--- a/test/WeekTest.php
+++ b/test/WeekTest.php
@@ -1,9 +1,7 @@
getSolarWeek($start);
$this->assertEquals('2024年2月第四周', $week->__toString());
}
-
- public function show()
- {
- $this->getMonthDayList(2024, 6, 20, 1);
- }
-
-
- /**
- * 获取日历
- */
- protected function getMonthDayList(int $yyyy, int $mmmm, int $dddd, int $weekStart = 0): array
- {
- $month = SolarMonth::fromYm($yyyy, $mmmm);
- $weekHeads = [];
- $w = Week::fromIndex($weekStart);
- for ($i = 0; $i < 7; $i++) {
- $weekHeads[] = [
- 'isWeekend' => $w->getIndex() === 6 || $w->getIndex() === 0,
- 'name' => $w->getName()
- ];
- $w = $w->next(1);
- }
- $weeks = [];
- $monthWeeks = $month->getWeeks($weekStart);
- for ($i = 0, $j = count($monthWeeks); $i < $j; $i++) {
- $days = [];
- $weekDays = $monthWeeks[$i]->getDays();
- for ($x = 0, $y = count($weekDays); $x < $y; $x++) {
- $solarDay = $weekDays[$x];
-
- $lunar_day = $solarDay->getLunarDay();
-
- $holiday = $solarDay->getLegalHoliday();
- $weekIndex = $solarDay->getWeek()->getIndex();
- $weekend = $weekIndex === 6 || $weekIndex === 0;
- if ($holiday && $holiday->isWork()) {
- $weekend = false;
- }
-
- $text = $lunar_day->getName();
-
- $f = $solarDay->getFestival();
- if ($f) {
- $text = $f->getName();
- }
-
- $f = $lunar_day->getFestival();
- if ($f) {
- $text = $f->getName();
- }
-
- if (1 === $lunar_day->getDay()) {
- $lunarMonth = $lunar_day->getMonth();
- $text = $lunarMonth->getName();
- if (1 === $lunarMonth->getMonthWithLeap()) {
- $text = $lunarMonth->getYear()->getSixtyCycle()->getName() . '年' . $text;
- }
- }
-
- $jq = $solarDay->getTermDay();
- if ($jq->getDayIndex() == 0) {
- $text = $jq->getName();
- }
- $days[] = [
- 'date' => $solarDay->__toString(),
- 'day' => $solarDay->getDay(),
- 'solar_month' => $solarDay->getMonth(),
- 'month' => $month,
- 'holiday' => $holiday ? ['isWork' => $holiday->isWork()] : null,
- 'isCurrentMonth' => $solarDay->getMonth()->equals($month),
- 'isToday' => $solarDay->getDay() == 20 && $solarDay->getMonth()->getMonth() == 6,
- 'isCurrentDay' => $solarDay->getDay() == 20 && $solarDay->getMonth()->equals($month),
- 'isWeekend' => $weekend,
- 'text' => $text
- ];
- }
- $weeks[] = ['days' => $days];
- }
- return [
- 'month' => [
- 'name' => $month->__toString(),
- 'weeks' => $weeks
- ],
- 'weeks' => $weekHeads
- ];
- }
-
- function test24() {
- $this->show();
- $this->assertTrue(!false);
- }
}
diff --git a/tools/build-standalone.php b/tools/build-standalone.php
index b0212a5..e0570c3 100644
--- a/tools/build-standalone.php
+++ b/tools/build-standalone.php
@@ -66,7 +66,7 @@ function parseDirectory($path): void
if ('../src' == $path) {
usort($files, function ($a, $b) {
$sorts = array();
- foreach (['Culture', 'Tyme', 'AbstractCulture', 'AbstractCultureDay', 'AbstractTyme', 'LoopTyme'] as $name) {
+ foreach (['ExtendTrait', 'Culture', 'Tyme', 'AbstractCulture', 'AbstractCultureDay', 'AbstractTyme', 'LoopTyme'] as $name) {
$sorts[] = '../src/'. $name . '.php';
}
return array_search($a, $sorts) - array_search($b, $sorts);