.gitignore 0000644 00000000127 14641217602 0006537 0 ustar 00 .idea/ vendor/ composer.lock composer.phar .phpunit.result.cache .DS_Store package.xml CHANGELOG.md 0000644 00000000432 14641217602 0006357 0 ustar 00 # Changelog ## [1.3.14] - 2024-02-29 1. 修复节气当天获取下一节气仍为当前节气的问题。 2. 修复每日宜忌存在重复项的问题。 3. 修复八字转阳历存在遗漏的问题。 ## [1.3.15] - 2024-03-19 1. 修复八字转阳历存在遗漏的问题。 LICENSE 0000644 00000002045 14641217602 0005555 0 ustar 00 MIT License Copyright (c) 2018 6tail Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. README.md 0000644 00000003416 14641217602 0006032 0 ustar 00 # lunar [](https://github.com/6tail/lunar-php/blob/master/LICENSE) lunar是一款无第三方依赖的日历工具,支持公历(阳历)、农历(阴历、老黄历)、佛历和道历,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。 此版本基于composer,如果您不会,可以使用[单文件版本](https://github.com/6tail/lunar-php-standalone)。 > 基于php5.3开发。 [English](https://github.com/6tail/lunar-php/blob/master/README_EN.md) ## 示例 composer require 6tail/lunar-php toFullString()."\n"; echo $lunar->getSolar()->toFullString()."\n"; 输出结果: 一九八六年四月廿一 丙寅(虎)年 癸巳(蛇)月 癸酉(鸡)日 子(鼠)时 纳音[炉中火 长流水 剑锋金 桑柘木] 星期四 北方玄武 星宿[斗木獬](吉) 彭祖百忌[癸不词讼理弱敌强 酉不会客醉坐颠狂] 喜神方位[巽](东南) 阳贵神方位[巽](东南) 阴贵神方位[震](正东) 福神方位[兑](正西) 财神方位[离](正南) 冲[(丁卯)兔] 煞[东] 1986-05-29 00:00:00 星期四 双子座 ## 文档 请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html") ## Star History [](https://star-history.com/#6tail/lunar-php&Date) README_EN.md 0000644 00000002566 14641217602 0006421 0 ustar 00 # lunar [](https://github.com/6tail/lunar-php/blob/master/LICENSE) lunar is a calendar library for Solar and Chinese Lunar. This version is based on composer, you can use [single file version](https://github.com/6tail/lunar-php-standalone) also。 [简体中文](https://github.com/6tail/lunar-php/blob/master/README.md) ## Example composer require 6tail/lunar-php toFullString()."\n"; echo $lunar->getSolar()->toFullString()."\n"; Output: 一九八六年四月廿一 丙寅(虎)年 癸巳(蛇)月 癸酉(鸡)日 子(鼠)时 纳音[炉中火 长流水 剑锋金 桑柘木] 星期四 北方玄武 星宿[斗木獬](吉) 彭祖百忌[癸不词讼理弱敌强 酉不会客醉坐颠狂] 喜神方位[巽](东南) 阳贵神方位[巽](东南) 阴贵神方位[震](正东) 福神方位[兑](正西) 财神方位[离](正南) 冲[(丁卯)兔] 煞[东] 1986-05-29 00:00:00 星期四 双子座 ## Documentation Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html") ## Star History [](https://star-history.com/#6tail/lunar-php&Date) composer.json 0000644 00000003260 14641217602 0007272 0 ustar 00 { "name": "6tail/lunar-php", "type": "library", "license": "MIT", "authors": [ { "name": "6tail", "email": "6tail@6tail.cn", "homepage": "https://6tail.cn" } ], "minimum-stability": "stable", "require": { "php": ">=5.3", "ext-bcmath": "*" }, "require-dev": { "phpunit/phpunit": "*" }, "autoload": { "psr-4": { "com\\nlf\\calendar\\": "src/" } }, "homepage": "https://github.com/6tail/lunar-php", "keywords": [ "calendar", "lunar", "solar", "节假日", "星座", "儒略日", "干支", "生肖", "节气", "节日", "彭祖百忌", "每日宜忌", "时辰宜忌", "吉神宜趋", "凶煞宜忌", "喜神", "福神", "财神", "阳贵神", "阴贵神", "胎神", "冲煞", "纳音", "星宿", "八字", "五行", "十神", "建除十二值星", "青龙名堂等十二神", "黄道日" ], "description": "lunar是一款无第三方依赖的日历工具,支持公历(阳历)、农历(阴历、老黄历)、佛历和道历,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。lunar is a calendar library for Solar and Chinese Lunar." } demo.php 0000644 00000021575 14641217602 0006216 0 ustar 00 toFullString() . "\n"; echo $lunar->getSolar()->toFullString() . "\n"; // 节假日 echo HolidayUtil::getHoliday('2020-05-02') . "\n"; // 儒略日 $solar = Solar::fromYmd(2020, 7, 15); echo $solar->getJulianDay() . "\n"; $solar = Solar::fromJulianDay(2459045.5); echo $solar->toFullString() . "\n"; // 遍历节气表 $lunar = Lunar::fromDate(new DateTime()); $jieQi = $lunar->getJieQiTable(); foreach ($jieQi as $key => $value) { echo $key . ' = ' . $value->toYmdHms() . "\n"; } // 遍历日吉神(宜趋) foreach ($lunar->getDayJiShen() as $js) { echo $js . ' '; } echo "\n"; // 遍历时辰宜 foreach ($lunar->getTimeYi() as $yi) { echo $yi . ' '; } echo "\n"; // 八字 $baZi = $lunar->getEightChar(); echo $baZi . ' '; echo "\n"; // 八字五行 echo $baZi->getYearWuXing() . ' ' . $baZi->getMonthWuXing() . ' ' . $baZi->getDayWuXing() . ' ' . $baZi->getTimeWuXing(); echo "\n"; // 八字纳音 echo $baZi->getYearNaYin() . ' ' . $baZi->getMonthNaYin() . ' ' . $baZi->getDayNaYin() . ' ' . $baZi->getTimeNaYin(); echo "\n"; // 八字天干十神 echo $baZi->getYearShiShenGan() . ' ' . $baZi->getMonthShiShenGan() . ' ' . $baZi->getDayShiShenGan() . ' ' . $baZi->getTimeShiShenGan(); echo "\n"; // 遍历八字年支十神 foreach ($baZi->getYearShiShenZhi() as $shen) { echo $shen . ' '; } echo "\n"; // 遍历八字月支十神 foreach ($baZi->getMonthShiShenZhi() as $shen) { echo $shen . ' '; } echo "\n"; // 遍历八字日支十神 foreach ($baZi->getDayShiShenZhi() as $shen) { echo $shen . ' '; } echo "\n"; // 遍历八字时支十神 foreach ($baZi->getTimeShiShenZhi() as $shen) { echo $shen . ' '; } echo "\n"; // 八字胎元 echo $baZi->getTaiYuan(); echo "\n"; // 八字命宫 echo $baZi->getMingGong(); echo "\n"; // 八字身宫 echo $baZi->getShenGong(); echo "\n"; // 时辰吉神方位 echo $lunar->getTimePositionFu() . "\n"; echo $lunar->getTimePositionXi() . "\n"; echo $lunar->getTimePositionCai() . "\n"; echo $lunar->getTimePositionYinGui() . "\n"; echo $lunar->getTimePositionYangGui() . "\n"; echo $lunar->getTimePositionFuDesc() . "\n"; echo $lunar->getTimePositionXiDesc() . "\n"; echo $lunar->getTimePositionCaiDesc() . "\n"; echo $lunar->getTimePositionYinGuiDesc() . "\n"; echo $lunar->getTimePositionYangGuiDesc() . "\n"; // 指定阳历时间得到八字信息 $solar = Solar::fromYmdHms(1988, 2, 15, 23, 0, 0); $lunar = $solar->getLunar(); $baZi = $lunar->getEightChar(); echo $baZi->getYear() . ' ' . $baZi->getMonth() . ' ' . $baZi->getDay() . ' ' . $baZi->getTime() . "\n"; $solar = Solar::fromYmdHms(1988, 3, 20, 18, 0, 0); $lunar = $solar->getLunar(); $baZi = $lunar->getEightChar(); // 男运 $yun = $baZi->getYun(1); echo "\n"; echo '阳历' . $solar->toYmdHms() . '出生\n'; echo '出生' . $yun->getStartYear() . '年' . $yun->getStartMonth() . '个月' . $yun->getStartDay() . '天后起运' . "\n"; echo '阳历' . $yun->getStartSolar()->toYmd() . '后起运' . "\n"; echo "\n"; // 大运 $daYunArr = $yun->getDaYun(); for ($i = 0; $i < count($daYunArr); $i++) { $daYun = $daYunArr[$i]; echo '大运[' . $daYun->getIndex() . '] = ' . $daYun->getStartYear() . '年 ' . $daYun->getStartAge() . '岁 ' . $daYun->getGanZhi() . "\n"; } echo "\n"; // 第1次大运流年 $liuNianArr = $daYunArr[1]->getLiuNian(); for ($i = 0; $i < count($liuNianArr); $i++) { $liuNian = $liuNianArr[$i]; echo '流年[' . $liuNian->getIndex() . '] = ' . $liuNian->getYear() . '年 ' . $liuNian->getAge() . '岁 ' . $liuNian->getGanZhi() . "\n"; } echo "\n"; // 第1次大运小运 $xiaoYunArr = $daYunArr[1]->getXiaoYun(); for ($i = 0; $i < count($xiaoYunArr); $i++) { $xiaoYun = $xiaoYunArr[$i]; echo '小运[' . $xiaoYun->getIndex() . '] = ' . $xiaoYun->getYear() . '年 ' . $xiaoYun->getAge() . '岁 ' . $xiaoYun->getGanZhi() . "\n"; } echo "\n"; // 第1次大运首个流年的流月 $liuYueArr = $liuNianArr[0]->getLiuYue(); for ($i = 0; $i < count($liuYueArr); $i++) { $liuYue = $liuYueArr[$i]; echo '流月[' . $liuYue->getIndex() . '] = ' . $liuYue->getMonthInChinese() . '月 ' . $liuYue->getGanZhi() . "\n"; } echo "\n"; // 八字转阳历 try { $l = Solar::fromBaZi('庚子', '癸未', '乙丑', '丁亥'); foreach ($l as $d) { echo $d->toFullString() . "\n"; } } catch (Exception $e) { echo $e->getMessage(); } // 阳历日期推移 $date = Solar::fromYmd(2020, 1, 23); echo strcmp('2020-01-24', $date->next(1)->toYmd()); // 仅工作日,跨越春节假期 echo strcmp('2020-02-03', $date->nextWorkday(1)->toYmd()); $date = Solar::fromYmd(2020, 2, 3); echo strcmp('2020-01-31', $date->next(-3)->toYmd()); // 仅工作日,跨越春节假期 echo strcmp('2020-01-21', $date->nextWorkday(-3)->toYmd()); $date = Solar::fromYmd(2020, 2, 9); echo strcmp('2020-02-15', $date->next(6)->toYmd()); // 仅工作日,跨越周末 echo strcmp('2020-02-17', $date->nextWorkday(6)->toYmd()); $date = Solar::fromYmd(2020, 1, 17); echo strcmp('2020-01-18', $date->next(1)->toYmd()); // 仅工作日,周日调休按上班算 echo strcmp('2020-01-19', $date->nextWorkday(1)->toYmd()) . "\n"; // 节假日数据修改 echo strcmp('2020-01-01 元旦节 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . ''); // 将2020-01-01修改为春节 HolidayUtil::fix(null, '202001011120200101'); echo strcmp('2020-01-01 春节 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . ''); // 追加2099-01-01为元旦节 HolidayUtil::fix(null, '209901010120990101'); echo strcmp('2099-01-01 元旦节 2099-01-01', HolidayUtil::getHoliday('2099-01-01') . ''); // 将2020-01-01修改为春节,并追加2099-01-01为元旦节 HolidayUtil::fix(null, '202001011120200101209901010120990101'); echo strcmp('2020-01-01 春节 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . ''); echo strcmp('2099-01-01 元旦节 2099-01-01', HolidayUtil::getHoliday('2099-01-01') . ''); // 更改节假日名称 $names = HolidayUtil::$NAMES; $names[0] = '元旦'; $names[1] = '大年初一'; HolidayUtil::fix($names, null); echo strcmp('2020-01-01 大年初一 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . ''); echo strcmp('2099-01-01 元旦 2099-01-01', HolidayUtil::getHoliday('2099-01-01') . ''); // 追加节假日名称和数据 $names = array(); for ($i = 0, $j = count(HolidayUtil::$NAMES); $i < $j; $i++) { $names[$i] = HolidayUtil::$NAMES[$i]; } $names[9] = '我的生日'; $names[10] = '结婚纪念日'; $names[11] = '她的生日'; HolidayUtil::fix($names, '20210529912021052920211111:12021111120211201;120211201'); echo strcmp('2021-05-29 我的生日 2021-05-29', HolidayUtil::getHoliday('2021-05-29') . ''); echo strcmp('2021-11-11 结婚纪念日 2021-11-11', HolidayUtil::getHoliday('2021-11-11') . ''); echo strcmp('2021-12-01 她的生日 2021-12-01', HolidayUtil::getHoliday('2021-12-01') . '') . "\n"; // 节日 $solar = Solar::fromYmd(2020, 11, 26); foreach ($solar->getFestivals() as $f) { echo $f . "\n"; } $solar = Solar::fromYmd(2020, 6, 21); foreach ($solar->getFestivals() as $f) { echo $f . "\n"; } $solar = Solar::fromYmd(2021, 5, 9); foreach ($solar->getFestivals() as $f) { echo $f . "\n"; } $solar = Solar::fromYmd(1986, 11, 27); foreach ($solar->getFestivals() as $f) { echo $f . "\n"; } $solar = Solar::fromYmd(1985, 6, 16); foreach ($solar->getFestivals() as $f) { echo $f . "\n"; } $solar = Solar::fromYmd(1984, 5, 13); foreach ($solar->getFestivals() as $f) { echo $f . "\n"; } // 旬 $solar = Solar::fromYmdHms(2020, 11, 19, 0, 0, 0); $lunar = $solar->getLunar(); // 甲午 echo $lunar->getYearXun() . "\n"; // 旬空(空亡) // 辰巳 echo $lunar->getYearXunKong() . "\n"; // 午未 echo $lunar->getMonthXunKong() . "\n"; // 戌亥 echo $lunar->getDayXunKong() . "\n"; // 八字日柱旬空(空亡) $solar = Solar::fromYmdHms(1990, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); // 子丑 echo $eightChar->getDayXunKong() . "\n"; // 数九 $lunar = Lunar::fromDate(new DateTime()); echo $lunar->getShuJiu() . "\n"; // 三伏 $solar = Solar::fromYmd(2020, 7, 26); $lunar = $solar->getLunar(); echo $lunar->getFu()->toFullString() . "\n"; // 六曜 $lunar = Lunar::fromDate(new DateTime()); echo $lunar->getLiuYao() . "\n"; // 物候 echo $lunar->getWuHou() . "\n"; // 时辰福神方位 $times = $lunar->getTimes(); foreach ($times as $time) { echo $time->getPositionFuBySect(2) . "\n"; } $jinYear = 2023; $solar = Solar::fromYmdHms(2023, 11, 29, 0, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYun(1); $dayuns = $yun->getDaYun(); foreach ($dayuns as $dayun) { $startYear = $dayun->getStartYear(); $endYear = $dayun->getEndYear(); echo $dayun->getGanZhi()." " .$startYear. " ". $endYear . "\n"; if ($jinYear >= $startYear && $jinYear <= $endYear) { $dangQianDaYun = $dayun; } } echo "\n"; echo $dangQianDaYun->getGanZhi(). "\n"; src/DaYun.php 0000644 00000007404 14641217602 0007074 0 ustar 00 yun = $yun; $this->lunar = $yun->getLunar(); $this->index = $index; $birthYear = $this->lunar->getSolar()->getYear(); $year = $yun->getStartSolar()->getYear(); if ($index < 1) { $this->startYear = $birthYear; $this->startAge = 1; $this->endYear = $year - 1; $this->endAge = $year - $birthYear; } else { $add = ($index - 1) * 10; $this->startYear = $year + $add; $this->startAge = $this->startYear - $birthYear + 1; $this->endYear = $this->startYear + 9; $this->endAge = $this->startAge + 9; } } /** * 获取起始年 * @return int */ public function getStartYear() { return $this->startYear; } /** * 获取结束年 * @return int */ public function getEndYear() { return $this->endYear; } /** * 获取开始年龄 * @return int */ public function getStartAge() { return $this->startAge; } /** * 获取结束年龄 * @return int */ public function getEndAge() { return $this->endAge; } /** * 获取序数 * @return int */ public function getIndex() { return $this->index; } /** * 获取运 * @return Yun */ public function getYun() { return $this->yun; } /** * 获取农历 * @return Lunar */ public function getLunar() { return $this->lunar; } /** * 获取干支 * @return string */ public function getGanZhi() { if ($this->index < 1) { return ''; } $offset = LunarUtil::getJiaZiIndex($this->lunar->getMonthInGanZhiExact()); $offset += $this->yun->isForward() ? $this->index : -$this->index; $size = count(LunarUtil::$JIA_ZI); if ($offset >= $size) { $offset -= $size; } if ($offset < 0) { $offset += $size; } return LunarUtil::$JIA_ZI[$offset]; } /** * 获取所在旬 * @return string 旬 */ public function getXun() { return LunarUtil::getXun($this->getGanZhi()); } /** * 获取旬空(空亡) * @return string 旬空(空亡) */ public function getXunKong() { return LunarUtil::getXunKong($this->getGanZhi()); } /** * 获取10轮流年 * @return LiuNian[] */ public function getLiuNian() { return $this->getLiuNianBy(10); } /** * 获取流年 * @param $n int 轮数 * @return LiuNian[] */ public function getLiuNianBy($n) { if ($this->index < 1) { $n = $this->endYear - $this->startYear + 1; } $l = array(); for ($i = 0; $i < $n; $i++) { $l[] = new LiuNian($this, $i); } return $l; } /** * 获取10轮小运 * @return XiaoYun[] */ public function getXiaoYun() { return $this->getXiaoYunBy(10); } /** * 获取小运 * @param $n int 轮数 * @return XiaoYun[] */ public function getXiaoYunBy($n) { if ($this->index < 1) { $n = $this->endYear - $this->startYear + 1; } $l = array(); for ($i = 0; $i < $n; $i++) { $l[] = new XiaoYun($this, $i, $this->yun->isForward()); } return $l; } } src/EightChar.php 0000644 00000033260 14641217602 0007711 0 ustar 00 1, '丙' => 10, '戊' => 10, '庚' => 7, '壬' => 4, '乙' => 6, '丁' => 9, '己' => 9, '辛' => 0, '癸' => 3 ); /** * @var array 月支,按正月起寅排列 */ public static $MONTH_ZHI = array('', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥', '子', '丑'); /** * @var array 长生十二神 */ public static $CHANG_SHENG = array('长生', '沐浴', '冠带', '临官', '帝旺', '衰', '病', '死', '墓', '绝', '胎', '养'); function __construct($lunar) { $this->lunar = $lunar; } public static function fromLunar($lunar) { return new EightChar($lunar); } public function toString() { return $this->getYear() . ' ' . $this->getMonth() . ' ' . $this->getDay() . ' ' . $this->getTime(); } public function __toString() { return $this->toString(); } /** * 获取流派 * @return int 流派,2晚子时日柱按当天,1晚子时日柱按明天 */ public function getSect() { return $this->sect; } /** * 设置流派 * @param int $sect 流派,2晚子时日柱按当天,1晚子时日柱按明天 */ public function setSect($sect) { $this->sect = (1 == $sect) ? 1 : 2; } /** * 获取农历对象 * @return Lunar 农历对象 */ public function getLunar() { return $this->lunar; } /** * 获取年柱 * @return string 年柱 */ public function getYear() { return $this->lunar->getYearInGanZhiExact(); } /** * 获取年干 * @return string 天干 */ public function getYearGan() { return $this->lunar->getYearGanExact(); } /** * 获取年支 * @return string 地支 */ public function getYearZhi() { return $this->lunar->getYearZhiExact(); } /** * 获取年柱地支藏干,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 天干 */ public function getYearHideGan() { return LunarUtil::$ZHI_HIDE_GAN[$this->getYearZhi()]; } /** * 获取年柱五行 * @return string 五行 */ public function getYearWuXing() { return LunarUtil::$WU_XING_GAN[$this->getYearGan()] . LunarUtil::$WU_XING_ZHI[$this->getYearZhi()]; } /** * 获取年柱纳音 * @return string 纳音 */ public function getYearNaYin() { return LunarUtil::$NAYIN[$this->getYear()]; } /** * 获取年柱天干十神 * @return string 十神 */ public function getYearShiShenGan() { return LunarUtil::$SHI_SHEN[$this->getDayGan() . $this->getYearGan()]; } /** * 获取十神地支 * @param $zhi string 地支 * @return string[] */ private function getShiShenZhi($zhi) { $hideGan = LunarUtil::$ZHI_HIDE_GAN[$zhi]; $l = array(); foreach ($hideGan as $gan) { $l[] = LunarUtil::$SHI_SHEN[$this->getDayGan() . $gan]; } return $l; } /** * 获取年柱地支十神,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 十神 */ public function getYearShiShenZhi() { return $this->getShiShenZhi($this->getYearZhi()); } private function getDiShi($zhiIndex) { $index = self::$CHANG_SHENG_OFFSET[$this->getDayGan()] + ($this->getDayGanIndex() % 2 == 0 ? $zhiIndex : 0 - $zhiIndex); if ($index >= 12) { $index -= 12; } if ($index < 0) { $index += 12; } return self::$CHANG_SHENG[$index]; } /** * 获取年柱地势(长生十二神) * @return string 地势 */ public function getYearDiShi() { return $this->getDiShi($this->lunar->getYearZhiIndexExact()); } /** * 获取月柱 * @return string 月柱 */ public function getMonth() { return $this->lunar->getMonthInGanZhiExact(); } /** * 获取月干 * @return string 天干 */ public function getMonthGan() { return $this->lunar->getMonthGanExact(); } /** * 获取月支 * @return string 地支 */ public function getMonthZhi() { return $this->lunar->getMonthZhiExact(); } /** * 获取月柱地支藏干,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 天干 */ public function getMonthHideGan() { return LunarUtil::$ZHI_HIDE_GAN[$this->getMonthZhi()]; } /** * 获取月柱五行 * @return string 五行 */ public function getMonthWuXing() { return LunarUtil::$WU_XING_GAN[$this->getMonthGan()] . LunarUtil::$WU_XING_ZHI[$this->getMonthZhi()]; } /** * 获取月柱纳音 * @return string 纳音 */ public function getMonthNaYin() { return LunarUtil::$NAYIN[$this->getMonth()]; } /** * 获取月柱天干十神 * @return string 十神 */ public function getMonthShiShenGan() { return LunarUtil::$SHI_SHEN[$this->getDayGan() . $this->getMonthGan()]; } /** * 获取月柱地支十神,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 十神 */ public function getMonthShiShenZhi() { return $this->getShiShenZhi($this->getMonthZhi()); } /** * 获取月柱地势(长生十二神) * @return string 地势 */ public function getMonthDiShi() { return $this->getDiShi($this->lunar->getMonthZhiIndexExact()); } /** * 获取日柱 * @return string 日柱 */ public function getDay() { return (2 == $this->sect) ? $this->lunar->getDayInGanZhiExact2() : $this->lunar->getDayInGanZhiExact(); } /** * 获取日干 * @return string 天干 */ public function getDayGan() { return (2 == $this->sect) ? $this->lunar->getDayGanExact2() : $this->lunar->getDayGanExact(); } /** * 获取日支 * @return string 地支 */ public function getDayZhi() { return (2 == $this->sect) ? $this->lunar->getDayZhiExact2() : $this->lunar->getDayZhiExact(); } /** * 获取日柱地支藏干,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 天干 */ public function getDayHideGan() { return LunarUtil::$ZHI_HIDE_GAN[$this->getDayZhi()]; } /** * 获取日柱五行 * @return string 五行 */ public function getDayWuXing() { return LunarUtil::$WU_XING_GAN[$this->getDayGan()] . LunarUtil::$WU_XING_ZHI[$this->getDayZhi()]; } /** * 获取日柱纳音 * @return string 纳音 */ public function getDayNaYin() { return LunarUtil::$NAYIN[$this->getDay()]; } /** * 获取日柱天干十神,也称日元、日干 * @return string 十神 */ public function getDayShiShenGan() { return '日主'; } /** * 获取日柱地支十神,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 十神 */ public function getDayShiShenZhi() { return $this->getShiShenZhi($this->getDayZhi()); } /** * 获取日柱天干序号 * @return int 日柱天干序号,0-9 */ public function getDayGanIndex() { return (2 == $this->sect) ? $this->lunar->getDayGanIndexExact2() : $this->lunar->getDayGanIndexExact(); } /** * 获取日柱地支序号 * @return int 日柱地支序号,0-11 */ public function getDayZhiIndex() { return (2 == $this->sect) ? $this->lunar->getDayZhiIndexExact2() : $this->lunar->getDayZhiIndexExact(); } /** * 获取日柱地势(长生十二神) * @return string 地势 */ public function getDayDiShi() { return $this->getDiShi($this->getDayZhiIndex()); } /** * 获取时柱 * @return string 时柱 */ public function getTime() { return $this->lunar->getTimeInGanZhi(); } /** * 获取时干 * @return string 天干 */ public function getTimeGan() { return $this->lunar->getTimeGan(); } /** * 获取时支 * @return string 地支 */ public function getTimeZhi() { return $this->lunar->getTimeZhi(); } /** * 获取时柱地支藏干,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 天干 */ public function getTimeHideGan() { return LunarUtil::$ZHI_HIDE_GAN[$this->getTimeZhi()]; } /** * 获取时柱五行 * @return string 五行 */ public function getTimeWuXing() { return LunarUtil::$WU_XING_GAN[$this->lunar->getTimeGan()] . LunarUtil::$WU_XING_ZHI[$this->lunar->getTimeZhi()]; } /** * 获取时柱纳音 * @return string 纳音 */ public function getTimeNaYin() { return LunarUtil::$NAYIN[$this->getTime()]; } /** * 获取时柱天干十神 * @return string 十神 */ public function getTimeShiShenGan() { return LunarUtil::$SHI_SHEN[$this->getDayGan() . $this->getTimeGan()]; } /** * 获取时柱地支十神,由于藏干分主气、余气、杂气,所以返回结果可能为1到3个元素 * @return string[] 十神 */ public function getTimeShiShenZhi() { return $this->getShiShenZhi($this->getTimeZhi()); } /** * 获取时柱地势(长生十二神) * @return string 地势 */ public function getTimeDiShi() { return $this->getDiShi($this->lunar->getTimeZhiIndex()); } /** * 获取胎元 * @return string 胎元 */ public function getTaiYuan() { $ganIndex = $this->lunar->getMonthGanIndexExact() + 1; if ($ganIndex >= 10) { $ganIndex -= 10; } $zhiIndex = $this->lunar->getMonthZhiIndexExact() + 3; if ($zhiIndex >= 12) { $zhiIndex -= 12; } return LunarUtil::$GAN[$ganIndex + 1] . LunarUtil::$ZHI[$zhiIndex + 1]; } /** * 获取胎元纳音 * @return string 纳音 */ public function getTaiYuanNaYin() { return LunarUtil::$NAYIN[$this->getTaiYuan()]; } /** * 获取胎息 * @return string 胎息 */ public function getTaiXi() { $ganIndex = (2 == $this->sect) ? $this->lunar->getDayGanIndexExact2() : $this->lunar->getDayGanIndexExact(); $zhiIndex = (2 == $this->sect) ? $this->lunar->getDayZhiIndexExact2() : $this->lunar->getDayZhiIndexExact(); return LunarUtil::$HE_GAN_5[$ganIndex] . LunarUtil::$HE_ZHI_6[$zhiIndex]; } /** * 获取胎息纳音 * @return string 纳音 */ public function getTaiXiNaYin() { return LunarUtil::$NAYIN[$this->getTaiXi()]; } /** * 获取命宫 * @return string 命宫 */ public function getMingGong() { $offset = LunarUtil::index($this->getMonthZhi(), self::$MONTH_ZHI, 0) + LunarUtil::index($this->getTimeZhi(), self::$MONTH_ZHI, 0); $offset = ($offset >= 14 ? 26 : 14) - $offset; $ganIndex = ($this->lunar->getYearGanIndexExact() + 1) * 2 + $offset; while ($ganIndex > 10) { $ganIndex -= 10; } return sprintf('%s%s', LunarUtil::$GAN[$ganIndex], self::$MONTH_ZHI[$offset]); } /** * 获取命宫纳音 * @return string 纳音 */ public function getMingGongNaYin() { return LunarUtil::$NAYIN[$this->getMingGong()]; } /** * 获取身宫 * @return string 身宫 */ public function getShenGong() { $offset = LunarUtil::index($this->getMonthZhi(), self::$MONTH_ZHI, 0) + LunarUtil::index($this->getTimeZhi(), LunarUtil::$ZHI, 0); while ($offset > 12) { $offset -= 12; } $ganIndex = ($this->lunar->getYearGanIndexExact() + 1) * 2 + ($offset % 12); while ($ganIndex > 10) { $ganIndex -= 10; } return sprintf('%s%s', LunarUtil::$GAN[$ganIndex], self::$MONTH_ZHI[$offset]); } /** * 获取身宫纳音 * @return string 纳音 */ public function getShenGongNaYin() { return LunarUtil::$NAYIN[$this->getShenGong()]; } /** * 获取运 * @param int $gender 性别,1男,0女 * @return Yun 运 */ public function getYun($gender) { return $this->getYunBySect($gender, 1); } /** * 获取运 * @param int $gender 性别,1男,0女 * @param int $sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算 * @return Yun 运 */ public function getYunBySect($gender, $sect) { return new Yun($this, $gender, $sect); } /** * 获取年柱所在旬 * @return string 旬 */ public function getYearXun() { return $this->lunar->getYearXunExact(); } /** * 获取年柱旬空(空亡) * @return string 旬空(空亡) */ public function getYearXunKong() { return $this->lunar->getYearXunKongExact(); } /** * 获取月柱所在旬 * @return string 旬 */ public function getMonthXun() { return $this->lunar->getMonthXunExact(); } /** * 获取月柱旬空(空亡) * @return string 旬空(空亡) */ public function getMonthXunKong() { return $this->lunar->getMonthXunKongExact(); } /** * 获取日柱所在旬 * @return string 旬 */ public function getDayXun() { return (2 == $this->sect) ? $this->lunar->getDayXunExact2() : $this->lunar->getDayXunExact(); } /** * 获取日柱旬空(空亡) * @return string 旬空(空亡) */ public function getDayXunKong() { return (2 == $this->sect) ? $this->lunar->getDayXunKongExact2() : $this->lunar->getDayXunKongExact(); } /** * 获取时柱所在旬 * @return string 旬 */ public function getTimeXun() { return $this->lunar->getTimeXun(); } /** * 获取时柱旬空(空亡) * @return string 旬空(空亡) */ public function getTimeXunKong() { return $this->lunar->getTimeXunKong(); } } src/Foto.php 0000644 00000011133 14641217602 0006755 0 ustar 00 lunar = $lunar; } public static function fromLunar($lunar) { return new Foto($lunar); } public static function fromYmdHms($year, $month, $day, $hour, $minute, $second) { return Foto::fromLunar(Lunar::fromYmdHms($year + Foto::$DEAD_YEAR - 1, $month, $day, $hour, $minute, $second)); } public static function fromYmd($year, $month, $day) { return Foto::fromYmdHms($year, $month, $day, 0, 0, 0); } public function getLunar() { return $this->lunar; } public function getYear() { $sy = $this->lunar->getSolar()->getYear(); $y = $sy - Foto::$DEAD_YEAR; if ($sy == $this->lunar->getYear()) { $y++; } return $y; } public function getMonth() { return $this->lunar->getMonth(); } public function getDay() { return $this->lunar->getDay(); } public function getYearInChinese() { $y = $this->getYear() . ''; $s = ''; for ($i = 0, $j = strlen($y); $i < $j; $i++) { $s .= LunarUtil::$NUMBER[ord(substr($y, $i, 1)) - 48]; } return $s; } public function getMonthInChinese() { return $this->lunar->getMonthInChinese(); } public function getDayInChinese() { return $this->lunar->getDayInChinese(); } /** * 获取因果犯忌 * * @return FotoFestival[] 因果犯忌列表 */ public function getFestivals() { return FotoUtil::getFestivals(abs($this->getMonth()) . '-' . $this->getDay()); } /** * 获取纪念日 * * @return string[] 纪念日列表 */ public function getOtherFestivals() { $l = array(); $key = $this->getMonth() . '-' . $this->getDay(); if (!empty(FotoUtil::$OTHER_FESTIVAL[$key])) { foreach (FotoUtil::$OTHER_FESTIVAL[$key] as $f) { $l[] = $f; } } return $l; } public function isMonthZhai() { $m = $this->getMonth(); return 1 == $m || 5 == $m || 9 == $m; } public function isDayYangGong() { foreach ($this->getFestivals() as $f) { if (strcmp('杨公忌', $f->getName()) == 0) { return true; } } return false; } public function isDayZhaiShuoWang() { $d = $this->getDay(); return 1 == $d || 15 == $d; } public function isDayZhaiSix() { $d = $this->getDay(); if (8 == $d || 14 == $d || 15 == $d || 23 == $d || 29 == $d || 30 == $d) { return true; } else if (28 == $d) { $m = LunarMonth::fromYm($this->lunar->getYear(), $this->getMonth()); return null != $m && 30 != $m->getDayCount(); } return false; } public function isDayZhaiTen() { $d = $this->getDay(); return 1 == $d || 8 == $d || 14 == $d || 15 == $d || 18 == $d || 23 == $d || 24 == $d || 28 == $d || 29 == $d || 30 == $d; } public function isDayZhaiGuanYin() { $k = $this->getMonth() . '-' . $this->getDay(); foreach (FotoUtil::$DAY_ZHAI_GUAN_YIN as $d) { if (strcmp($k, $d) == 0) { return true; } } return false; } /** * 获取星宿 * * @return string 星宿 */ public function getXiu() { return FotoUtil::getXiu($this->getMonth(), $this->getDay()); } /** * 获取宿吉凶 * * @return string 吉/凶 */ public function getXiuLuck() { return LunarUtil::$XIU_LUCK[$this->getXiu()]; } /** * 获取宿歌诀 * * @return string 宿歌诀 */ public function getXiuSong() { return LunarUtil::$XIU_SONG[$this->getXiu()]; } /** * 获取政 * * @return string 政 */ public function getZheng() { return LunarUtil::$ZHENG[$this->getXiu()]; } /** * 获取动物 * * @return string 动物 */ public function getAnimal() { return LunarUtil::$ANIMAL[$this->getXiu()]; } /** * 获取宫 * * @return string 宫 */ public function getGong() { return LunarUtil::$GONG[$this->getXiu()]; } /** * 获取兽 * * @return string 兽 */ public function getShou() { return LunarUtil::$SHOU[$this->getGong()]; } public function toString() { return sprintf('%s年%s月%s', $this->getYearInChinese(), $this->getMonthInChinese(), $this->getDayInChinese()); } public function __toString() { return $this->toString(); } public function toFullString() { $s = $this->toString(); foreach ($this->getFestivals() as $f) { $s .= ' (' . $f . ')'; } return $s; } } src/FotoFestival.php 0000644 00000002157 14641217602 0010461 0 ustar 00 name = $name; $this->result = null == $result ? '' : $result; $this->everyMonth = $everyMonth; $this->remark = null == $remark ? '' : $remark; } public function getName() { return $this->name; } public function getResult() { return $this->result; } public function isEveryMonth() { return $this->everyMonth; } public function getRemark() { return $this->remark; } public function toString() { return $this->name; } public function toFullString() { $s = $this->name; if (null != $this->result && strlen($this->result) > 0) { $s .= ' ' . $this->result; } if (null != $this->remark && strlen($this->remark) > 0) { $s .= ' ' . $this->remark; } return $s; } public function __toString() { return $this->toString(); } } src/Fu.php 0000644 00000002027 14641217602 0006422 0 ustar 00 name = $name; $this->index = $index; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getIndex() { return $this->index; } public function setIndex($index) { $this->index = $index; } public function toString() { return $this->name; } public function __toString() { return $this->toString(); } public function toFullString() { return $this->name . '第' . $this->index . '天'; } } src/Holiday.php 0000644 00000003142 14641217602 0007440 0 ustar 00 day = $day; } else { $this->day = substr($day, 0, 4) . '-' . substr($day, 4, 2) . '-' . substr($day, 6); } $this->name = $name; $this->work = $work; if (strpos($day, '-') !== false) { $this->target = $target; } else { $this->target = substr($target, 0, 4) . '-' . substr($target, 4, 2) . '-' . substr($target, 6); } } public function setDay($day) { $this->day = $day; } public function setName($name) { $this->name = $name; } public function setWork($work) { $this->work = $work; } public function setTarget($target) { $this->target = $target; } public function getDay() { return $this->day; } public function getName() { return $this->name; } public function isWork() { return $this->work; } public function getTarget() { return $this->target; } public function toString() { return $this->day . ' ' . $this->name . ($this->work ? '调休' : '') . ' ' . $this->target; } public function __toString() { return $this->toString(); } } src/JieQi.php 0000644 00000002673 14641217602 0007060 0 ustar 00 setName($name); $this->solar = $solar; } /** * 获取名称 * @return string */ public function getName() { return $this->name; } /** * 设置名称 * @param string $name 名称 */ public function setName($name) { $this->name = $name; for ($i = 0, $j = count(Lunar::$JIE_QI); $i < $j; $i++) { if (strcmp($name, Lunar::$JIE_QI[$i]) == 0) { if ($i % 2 == 0) { $this->qi = true; } else { $this->jie = true; } return; } } } /** * 获取公历日期 * @return Solar */ public function getSolar() { return $this->solar; } /** * 设置公历日期 * @param Solar $solar 公历日期 */ public function setSolar($solar) { $this->solar = $solar; } /** * 是否节令 * @return true/false */ public function isJie() { return $this->jie; } /** * 是否气令 * @return true/false */ public function isQi() { return $this->qi; } public function toString() { return $this->name; } public function __toString() { return $this->toString(); } } src/LiuNian.php 0000644 00000004323 14641217602 0007410 0 ustar 00 daYun = $daYun; $this->lunar = $daYun->getLunar(); $this->index = $index; $this->year = $daYun->getStartYear() + $index; $this->age = $daYun->getStartAge() + $index; } /** * 获取序数 * @return int */ public function getIndex() { return $this->index; } /** * 获取大运 * @return DaYun */ public function getDaYun() { return $this->daYun; } /** * 获取年 * @return int */ public function getYear() { return $this->year; } /** * 获取年龄 * @return int */ public function getAge() { return $this->age; } /** * 获取农历 * @return Lunar */ public function getLunar() { return $this->lunar; } /** * 获取干支 * @return string */ public function getGanZhi() { $jieQi = $this->lunar->getJieQiTable(); $offset = LunarUtil::getJiaZiIndex($jieQi['立春']->getLunar()->getYearInGanZhiExact()) + $this->index; if ($this->daYun->getIndex() > 0) { $offset += $this->daYun->getStartAge() - 1; } $offset %= count(LunarUtil::$JIA_ZI); return LunarUtil::$JIA_ZI[$offset]; } /** * 获取所在旬 * @return string 旬 */ public function getXun() { return LunarUtil::getXun($this->getGanZhi()); } /** * 获取旬空(空亡) * @return string 旬空(空亡) */ public function getXunKong() { return LunarUtil::getXunKong($this->getGanZhi()); } /** * 获取流月 * @return LiuYue[] */ public function getLiuYue() { $n = 12; $l = array(); for ($i = 0; $i < $n; $i++) { $l[] = new LiuYue($this, $i); } return $l; } } src/LiuYue.php 0000644 00000003544 14641217602 0007271 0 ustar 00 liuNian = $liuNian; $this->index = $index; } /** * 获取序数 * @return int */ public function getIndex() { return $this->index; } /** * 获取流年 * @return LiuNian */ public function getLiuNian() { return $this->liuNian; } /** * 获取中文的月 * @return string 中文月,如正 */ public function getMonthInChinese() { return LunarUtil::$MONTH[$this->index + 1]; } /** * 获取干支 * @return string */ public function getGanZhi() { $offset = 0; $liuNianGanZhi = $this->liuNian->getGanZhi(); $yearGan = substr($liuNianGanZhi, 0, strlen($liuNianGanZhi) / 2); if ('甲' == $yearGan || '己' == $yearGan) { $offset = 2; } else if ('乙' == $yearGan || '庚' == $yearGan) { $offset = 4; } else if ('丙' == $yearGan || '辛' == $yearGan) { $offset = 6; } else if ('丁' == $yearGan || '壬' == $yearGan) { $offset = 8; } $gan = LunarUtil::$GAN[($this->index + $offset) % 10 + 1]; $zhi = LunarUtil::$ZHI[($this->index + LunarUtil::$BASE_MONTH_ZHI_INDEX) % 12 + 1]; return $gan . $zhi; } /** * 获取所在旬 * @return string 旬 */ public function getXun() { return LunarUtil::getXun($this->getGanZhi()); } /** * 获取旬空(空亡) * @return string 旬空(空亡) */ public function getXunKong() { return LunarUtil::getXunKong($this->getGanZhi()); } } src/Lunar.php 0000644 00000211546 14641217602 0007141 0 ustar 00 year = intval($lunarYear); $this->month = intval($lunarMonth); $this->day = intval($lunarDay); $this->hour = intval($hour); $this->minute = intval($minute); $this->second = intval($second); $this->solar = $solar; $this->compute($y); } /** * 通过指定农历年月日获取农历 * @param int $lunarYear 年(农历) * @param int $lunarMonth 月(农历),1到12,闰月为负,即闰2月=-2 * @param int $lunarDay 日(农历),1到30 * @return Lunar */ public static function fromYmd($lunarYear, $lunarMonth, $lunarDay) { return self::fromYmdHms($lunarYear, $lunarMonth, $lunarDay, 0, 0, 0); } /** * 通过指定农历年月日时分秒获取农历 * @param int $lunarYear 年(农历) * @param int $lunarMonth 月(农历),1到12,闰月为负,即闰2月=-2 * @param int $lunarDay 日(农历),1到30 * @param int $hour 小时(公历) * @param int $minute 分钟(公历) * @param int $second 秒钟(公历) * @return Lunar */ public static function fromYmdHms($lunarYear, $lunarMonth, $lunarDay, $hour, $minute, $second) { $y = LunarYear::fromYear($lunarYear); $m = $y->getMonth($lunarMonth); $noon = Solar::fromJulianDay($m->getFirstJulianDay() + $lunarDay - 1); $solar = Solar::fromYmdHms($noon->getYear(), $noon->getMonth(), $noon->getDay(), $hour, $minute, $second); if ($noon->getYear() != $lunarYear) { $y = LunarYear::fromYear($noon->getYear()); } return new Lunar($lunarYear, $lunarMonth, $lunarDay, $hour, $minute, $second, $solar, $y); } /** * 通过DateTime初始化 * @param DateTime $date DateTime * @return Lunar */ public static function fromDate($date) { return self::fromSolar(Solar::fromDate($date)); } /** * 通过公历初始化 * @param Solar $solar 公历 * @return Lunar */ public static function fromSolar($solar) { $ly = LunarYear::fromYear($solar->getYear()); $lunarYear = 0; $lunarMonth = 0; $lunarDay = 0; foreach ($ly->getMonths() as $m) { $days = $solar->subtract(Solar::fromJulianDay($m->getFirstJulianDay())); if ($days < $m->getDayCount()) { $lunarYear = $m->getYear(); $lunarMonth = $m->getMonth(); $lunarDay = $days + 1; break; } } return new Lunar($lunarYear, $lunarMonth, $lunarDay, $solar->getHour(), $solar->getMinute(), $solar->getSecond(), $solar, $ly); } /** * 计算节气表 * @param LunarYear $y */ private function computeJieQi($y) { $jds = $y->getJieQiJulianDays(); for ($i = 0, $j = count(self::$JIE_QI_IN_USE); $i < $j; $i++) { $this->jieQi[self::$JIE_QI_IN_USE[$i]] = Solar::fromJulianDay($jds[$i]); } } /** * 计算干支纪年 */ private function computeYear() { //以正月初一开始 $offset = $this->year - 4; $yearGanIndex = $offset % 10; $yearZhiIndex = $offset % 12; if ($yearGanIndex < 0) { $yearGanIndex += 10; } if ($yearZhiIndex < 0) { $yearZhiIndex += 12; } //以立春作为新一年的开始的干支纪年 $g = $yearGanIndex; $z = $yearZhiIndex; //精确的干支纪年,以立春交接时刻为准 $gExact = $yearGanIndex; $zExact = $yearZhiIndex; $solarYear = $this->solar->getYear(); $solarYmd = $this->solar->toYmd(); $solarYmdHms = $this->solar->toYmdHms(); //获取立春的公历时刻 $liChun = $this->jieQi['立春']; if ($liChun->getYear() != $solarYear) { $liChun = $this->jieQi['LI_CHUN']; } $liChunYmd = $liChun->toYmd(); $liChunYmdHms = $liChun->toYmdHms(); //公历和农历年份相同代表正月初一及以后 if ($this->year === $solarYear) { //立春日期判断 if (strcmp($solarYmd, $liChunYmd) < 0) { $g--; $z--; } //立春交接时刻判断 if (strcmp($solarYmdHms, $liChunYmdHms) < 0) { $gExact--; $zExact--; } } else if ($this->year < $solarYear) { if (strcmp($solarYmd, $liChunYmd) >= 0) { $g++; $z++; } if (strcmp($solarYmdHms, $liChunYmdHms) >= 0) { $gExact++; $zExact++; } } $this->yearGanIndex = $yearGanIndex; $this->yearZhiIndex = $yearZhiIndex; $this->yearGanIndexByLiChun = ($g < 0 ? $g + 10 : $g) % 10; $this->yearZhiIndexByLiChun = ($z < 0 ? $z + 12 : $z) % 12; $this->yearGanIndexExact = ($gExact < 0 ? $gExact + 10 : $gExact) % 10; $this->yearZhiIndexExact = ($zExact < 0 ? $zExact + 12 : $zExact) % 12; } /** * 干支纪月计算 */ private function computeMonth() { $start = null; $ymd = $this->solar->toYmd(); $time = $this->solar->toYmdHms(); $size = count(self::$JIE_QI_IN_USE); //序号:大雪以前-3,大雪到小寒之间-2,小寒到立春之间-1,立春之后0 $index = -3; for ($i = 0; $i < $size; $i += 2) { $end = $this->jieQi[self::$JIE_QI_IN_USE[$i]]; $symd = (null == $start) ? $ymd : $start->toYmd(); if (strcmp($ymd, $symd) >= 0 && strcmp($ymd, $end->toYmd()) < 0) { break; } $start = $end; $index++; } //干偏移值(以立春当天起算) $offset = ((($this->yearGanIndexByLiChun + ($index < 0 ? 1 : 0)) % 5 + 1) * 2) % 10; $this->monthGanIndex = (($index < 0 ? $index + 10 : $index) + $offset) % 10; $this->monthZhiIndex = (($index < 0 ? $index + 12 : $index) + LunarUtil::$BASE_MONTH_ZHI_INDEX) % 12; $start = null; $index = -3; for ($i = 0; $i < $size; $i += 2) { $end = $this->jieQi[self::$JIE_QI_IN_USE[$i]]; $stime = null == $start ? $time : $start->toYmdHms(); if (strcmp($time, $stime) >= 0 && strcmp($time, $end->toYmdHms()) < 0) { break; } $start = $end; $index++; } //干偏移值(以立春交接时刻起算) $offset = ((($this->yearGanIndexExact + ($index < 0 ? 1 : 0)) % 5 + 1) * 2) % 10; $this->monthGanIndexExact = (($index < 0 ? $index + 10 : $index) + $offset) % 10; $this->monthZhiIndexExact = (($index < 0 ? $index + 12 : $index) + LunarUtil::$BASE_MONTH_ZHI_INDEX) % 12; } /** * 干支纪日计算 */ private function computeDay() { $noon = Solar::fromYmdHms($this->solar->getYear(), $this->solar->getMonth(), $this->solar->getDay(), 12, 0, 0); $offset = (int)$noon->getJulianDay() - 11; $dayGanIndex = $offset % 10; $dayZhiIndex = $offset % 12; $this->dayGanIndex = $dayGanIndex; $this->dayZhiIndex = $dayZhiIndex; $dayGanExact = $dayGanIndex; $dayZhiExact = $dayZhiIndex; $this->dayGanIndexExact2 = $dayGanExact; $this->dayZhiIndexExact2 = $dayZhiExact; $hm = ($this->hour < 10 ? '0' : '') . $this->hour . ':' . ($this->minute < 10 ? '0' : '') . $this->minute; if (strcmp($hm, '23:00') >= 0 && strcmp($hm, '23:59') <= 0) { $dayGanExact++; if ($dayGanExact >= 10) { $dayGanExact -= 10; } $dayZhiExact++; if ($dayZhiExact >= 12) { $dayZhiExact -= 12; } } $this->dayGanIndexExact = $dayGanExact; $this->dayZhiIndexExact = $dayZhiExact; } /** * 干支纪时计算 */ private function computeTime() { $this->timeZhiIndex = LunarUtil::getTimeZhiIndex(($this->hour < 10 ? '0' : '') . $this->hour . ':' . ($this->minute < 10 ? '0' : '') . $this->minute); $this->timeGanIndex = ($this->dayGanIndexExact % 5 * 2 + $this->timeZhiIndex) % 10; } /** * 星期计算 */ private function computeWeek() { $this->weekIndex = $this->solar->getWeek(); } private function compute($y) { $this->computeJieQi($y); $this->computeYear(); $this->computeMonth(); $this->computeDay(); $this->computeTime(); $this->computeWeek(); } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } public function getDay() { return $this->day; } public function getHour() { return $this->hour; } public function getMinute() { return $this->minute; } public function getSecond() { return $this->second; } public function getSolar() { return $this->solar; } /** * 获取年份的天干(以正月初一作为新年的开始) * @return string 天干,如辛 */ public function getYearGan() { return LunarUtil::$GAN[$this->yearGanIndex + 1]; } /** * 获取年份的天干(以立春当天作为新年的开始) * * @return string 天干,如辛 */ public function getYearGanByLiChun() { return LunarUtil::$GAN[$this->yearGanIndexByLiChun + 1]; } /** * 获取最精确的年份天干(以立春交接的时刻作为新年的开始) * * @return string 天干,如辛 */ public function getYearGanExact() { return LunarUtil::$GAN[$this->yearGanIndexExact + 1]; } /** * 获取年份的地支(以正月初一作为新年的开始) * * @return string 地支,如亥 */ public function getYearZhi() { return LunarUtil::$ZHI[$this->yearZhiIndex + 1]; } /** * 获取年份的地支(以立春当天作为新年的开始) * * @return string 地支,如亥 */ public function getYearZhiByLiChun() { return LunarUtil::$ZHI[$this->yearZhiIndexByLiChun + 1]; } /** * 获取最精确的年份地支(以立春交接的时刻作为新年的开始) * * @return string 地支,如亥 */ public function getYearZhiExact() { return LunarUtil::$ZHI[$this->yearZhiIndexExact + 1]; } /** * 获取干支纪年(年柱)(以正月初一作为新年的开始) * @return string 年份的干支(年柱),如辛亥 */ public function getYearInGanZhi() { return $this->getYearGan() . $this->getYearZhi(); } /** * 获取干支纪年(年柱)(以立春当天作为新年的开始) * @return string 年份的干支(年柱),如辛亥 */ public function getYearInGanZhiByLiChun() { return $this->getYearGanByLiChun() . $this->getYearZhiByLiChun(); } /** * 获取干支纪年(年柱)(以立春交接的时刻作为新年的开始) * @return string 年份的干支(年柱),如辛亥 */ public function getYearInGanZhiExact() { return $this->getYearGanExact() . $this->getYearZhiExact(); } /** * 获取干支纪月(月柱)(以节交接当天起算) *
月天干口诀:甲己丙寅首,乙庚戊寅头。丙辛从庚寅,丁壬壬寅求,戊癸甲寅居,周而复始流。
*月地支:正月起寅
* * @return string 干支纪月(月柱),如己卯 */ public function getMonthInGanZhi() { return $this->getMonthGan() . $this->getMonthZhi(); } /** * 获取精确的干支纪月(月柱)(以节交接时刻起算) *月天干口诀:甲己丙寅首,乙庚戊寅头。丙辛从庚寅,丁壬壬寅求,戊癸甲寅居,周而复始流。
*月地支:正月起寅
* * @return string 干支纪月(月柱),如己卯 */ public function getMonthInGanZhiExact() { return $this->getMonthGanExact() . $this->getMonthZhiExact(); } /** * 获取月天干(以节交接当天起算) * @return string 月天干,如己 */ public function getMonthGan() { return LunarUtil::$GAN[$this->monthGanIndex + 1]; } /** * 获取精确的月天干(以节交接时刻起算) * @return string 月天干,如己 */ public function getMonthGanExact() { return LunarUtil::$GAN[$this->monthGanIndexExact + 1]; } /** * 获取月地支(以节交接当天起算) * @return string 月地支,如卯 */ public function getMonthZhi() { return LunarUtil::$ZHI[$this->monthZhiIndex + 1]; } /** * 获取精确的月地支(以节交接时刻起算) * @return string 月地支,如卯 */ public function getMonthZhiExact() { return LunarUtil::$ZHI[$this->monthZhiIndexExact + 1]; } /** * 获取干支纪日(日柱) * * @return string 干支纪日(日柱),如己卯 */ public function getDayInGanZhi() { return $this->getDayGan() . $this->getDayZhi(); } /** * 获取干支纪日(日柱,八字流派1,晚子时日柱算明天) * @return string 干支纪日(日柱),如己卯 */ public function getDayInGanZhiExact() { return $this->getDayGanExact() . $this->getDayZhiExact(); } /** * 获取干支纪日(日柱,八字流派2,晚子时日柱算当天) * @return string 干支纪日(日柱),如己卯 */ public function getDayInGanZhiExact2() { return $this->getDayGanExact2() . $this->getDayZhiExact2(); } /** * 获取日天干 * * @return string 日天干,如甲 */ public function getDayGan() { return LunarUtil::$GAN[$this->dayGanIndex + 1]; } /** * 获取日天干(八字流派1,晚子时日柱算明天) * @return string 日天干,如甲 */ public function getDayGanExact() { return LunarUtil::$GAN[$this->dayGanIndexExact + 1]; } /** * 获取日天干(八字流派1,晚子时日柱算当天) * @return string 日天干,如甲 */ public function getDayGanExact2() { return LunarUtil::$GAN[$this->dayGanIndexExact2 + 1]; } /** * 获取日地支 * * @return string 日地支,如卯 */ public function getDayZhi() { return LunarUtil::$ZHI[$this->dayZhiIndex + 1]; } /** * 获取日地支(八字流派1,晚子时日柱算明天) * @return string 日地支,如卯 */ public function getDayZhiExact() { return LunarUtil::$ZHI[$this->dayZhiIndexExact + 1]; } /** * 获取日地支(八字流派1,晚子时日柱算当天) * @return string 日地支,如卯 */ public function getDayZhiExact2() { return LunarUtil::$ZHI[$this->dayZhiIndexExact2 + 1]; } /** * 获取年生肖(以正月初一起算) * * @return string 年生肖,如虎 */ public function getYearShengXiao() { return LunarUtil::$SHENG_XIAO[$this->yearZhiIndex + 1]; } /** * 获取年生肖(以立春当天起算) * * @return string 年生肖,如虎 */ public function getYearShengXiaoByLiChun() { return LunarUtil::$SHENG_XIAO[$this->yearZhiIndexByLiChun + 1]; } /** * 获取精确的年生肖(以立春交接时刻起算) * * @return string 年生肖,如虎 */ public function getYearShengXiaoExact() { return LunarUtil::$SHENG_XIAO[$this->yearZhiIndexExact + 1]; } /** * 获取月生肖 * * @return string 月生肖,如虎 */ public function getMonthShengXiao() { return LunarUtil::$SHENG_XIAO[$this->monthZhiIndex + 1]; } /** * 获取日生肖 * * @return string 日生肖,如虎 */ public function getDayShengXiao() { return LunarUtil::$SHENG_XIAO[$this->dayZhiIndex + 1]; } /** * 获取时辰生肖 * * @return string 时辰生肖,如虎 */ public function getTimeShengXiao() { return LunarUtil::$SHENG_XIAO[$this->timeZhiIndex + 1]; } /** * 获取中文的年 * * @return string 中文年,如二零零一 */ public function getYearInChinese() { $y = $this->year . ''; $s = ''; for ($i = 0, $j = strlen($y); $i < $j; $i++) { $s .= LunarUtil::$NUMBER[ord(substr($y, $i, 1)) - 48]; } return $s; } /** * 获取中文的月 * * @return string 中文月,如正 */ public function getMonthInChinese() { return ($this->month < 0 ? '闰' : '') . LunarUtil::$MONTH[abs($this->month)]; } /** * 获取中文日 * * @return string 中文日,如初一 */ public function getDayInChinese() { return LunarUtil::$DAY[$this->day]; } /** * 获取时辰(地支) * @return string 时辰(地支) */ public function getTimeZhi() { return LunarUtil::$ZHI[$this->timeZhiIndex + 1]; } /** * 获取时辰(天干) * @return string 时辰(天干) */ public function getTimeGan() { return LunarUtil::$GAN[$this->timeGanIndex + 1]; } /** * 获取时辰干支(时柱) * @return string 时辰干支(时柱) */ public function getTimeInGanZhi() { return $this->getTimeGan() . $this->getTimeZhi(); } /** * 获取季节 * @return string 农历季节 */ public function getSeason() { return LunarUtil::$SEASON[abs($this->month)]; } private function convertJieQi($name) { $jq = $name; if (strcmp('DONG_ZHI', $jq) === 0) { $jq = '冬至'; } else if (strcmp('DA_HAN', $jq) === 0) { $jq = '大寒'; } else if (strcmp('XIAO_HAN', $jq) === 0) { $jq = '小寒'; } else if (strcmp('LI_CHUN', $jq) === 0) { $jq = '立春'; } else if (strcmp('DA_XUE', $jq) === 0) { $jq = '大雪'; } else if (strcmp('YU_SHUI', $jq) === 0) { $jq = '雨水'; } else if (strcmp('JING_ZHE', $jq) === 0) { $jq = '惊蛰'; } return $jq; } /** * 获取节 * * @return string 节 */ public function getJie() { for ($i = 0, $j = count(self::$JIE_QI_IN_USE); $i < $j; $i += 2) { $key = self::$JIE_QI_IN_USE[$i]; $d = $this->jieQi[$key]; if ($d->getYear() === $this->solar->getYear() && $d->getMonth() === $this->solar->getMonth() && $d->getDay() === $this->solar->getDay()) { return $this->convertJieQi($key); } } return ''; } /** * 获取气 * * @return string 气 */ public function getQi() { for ($i = 1, $j = count(self::$JIE_QI_IN_USE); $i < $j; $i += 2) { $key = self::$JIE_QI_IN_USE[$i]; $d = $this->jieQi[$key]; if ($d->getYear() === $this->solar->getYear() && $d->getMonth() === $this->solar->getMonth() && $d->getDay() === $this->solar->getDay()) { return $this->convertJieQi($key); } } return ''; } /** * 获取星期,0代表周日,1代表周一 * * @return int 0123456 */ public function getWeek() { return $this->weekIndex; } /** * 获取星期的中文 * * @return string 日一二三四五六 */ public function getWeekInChinese() { return SolarUtil::$WEEK[$this->getWeek()]; } /** * 获取宿 * * @return string 宿 */ public function getXiu() { return LunarUtil::$XIU[$this->getDayZhi() . $this->getWeek()]; } /** * 获取宿吉凶 * * @return string 吉/凶 */ public function getXiuLuck() { return LunarUtil::$XIU_LUCK[$this->getXiu()]; } /** * 获取宿歌诀 * * @return string 宿歌诀 */ public function getXiuSong() { return LunarUtil::$XIU_SONG[$this->getXiu()]; } /** * 获取政 * * @return string 政 */ public function getZheng() { return LunarUtil::$ZHENG[$this->getXiu()]; } /** * 获取动物 * @return string 动物 */ public function getAnimal() { return LunarUtil::$ANIMAL[$this->getXiu()]; } /** * 获取宫 * @return string 宫 */ public function getGong() { return LunarUtil::$GONG[$this->getXiu()]; } /** * 获取兽 * @return string 兽 */ public function getShou() { return LunarUtil::$SHOU[$this->getGong()]; } /** * 获取节日,有可能一天会有多个节日 * * @return string[] 节日列表,如春节 */ public function getFestivals() { $l = array(); $key = $this->month . '-' . $this->day; if (!empty(LunarUtil::$FESTIVAL[$key])) { $l[] = LunarUtil::$FESTIVAL[$key]; } if (abs($this->month) === 12 && $this->day >= 29 && $this->year != $this->next(1)->getYear()) { $l[] = '除夕'; } return $l; } /** * 获取非正式的节日,有可能一天会有多个节日 * * @return string[] 非正式的节日列表,如中元节 */ public function getOtherFestivals() { $l = array(); $key = $this->month . '-' . $this->day; if (!empty(LunarUtil::$OTHER_FESTIVAL[$key])) { foreach (LunarUtil::$OTHER_FESTIVAL[$key] as $f) { $l[] = $f; } } $jq = $this->jieQi['清明']; $solarYmd = $this->solar->toYmd(); if (strcmp($solarYmd, $jq->next(-1)->toYmd()) === 0) { $l[] = '寒食节'; } $jq = $this->jieQi['立春']; $offset = 4 - $jq->getLunar()->getDayGanIndex(); if ($offset < 0) { $offset += 10; } if (strcmp($solarYmd, $jq->next($offset + 40)->toYmd()) === 0) { $l[] = '春社'; } $jq = $this->jieQi['立秋']; $offset = 4 - $jq->getLunar()->getDayGanIndex(); if ($offset < 0) { $offset += 10; } if (strcmp($solarYmd, $jq->next($offset + 40)->toYmd()) === 0) { $l[] = '秋社'; } return $l; } /** * 获取彭祖百忌天干 * @return string 彭祖百忌天干 */ public function getPengZuGan() { return LunarUtil::$PENG_ZU_GAN[$this->dayGanIndex + 1]; } /** * 获取彭祖百忌地支 * @return string 彭祖百忌地支 */ public function getPengZuZhi() { return LunarUtil::$PENG_ZU_ZHI[$this->dayZhiIndex + 1]; } /** * 获取日喜神方位 * @return string 喜神方位,如艮 */ public function getPositionXi() { return $this->getDayPositionXi(); } /** * 获取日喜神方位描述 * @return string 喜神方位描述,如东北 */ public function getPositionXiDesc() { return $this->getDayPositionXiDesc(); } /** * 获取日喜神方位 * @return string 喜神方位,如艮 */ public function getDayPositionXi() { return LunarUtil::$POSITION_XI[$this->dayGanIndex + 1]; } /** * 获取日喜神方位描述 * @return string 喜神方位描述,如东北 */ public function getDayPositionXiDesc() { return LunarUtil::$POSITION_DESC[$this->getDayPositionXi()]; } /** * 获取时辰喜神方位 * @return string 喜神方位,如艮 */ public function getTimePositionXi() { return LunarUtil::$POSITION_XI[$this->timeGanIndex + 1]; } /** * 获取时辰喜神方位描述 * @return string 喜神方位描述,如东北 */ public function getTimePositionXiDesc() { return LunarUtil::$POSITION_DESC[$this->getTimePositionXi()]; } /** * 获取日阳贵神方位 * @return string 阳贵神方位,如艮 */ public function getPositionYangGui() { return $this->getDayPositionYangGui(); } /** * 获取日阳贵神方位描述 * @return string 阳贵神方位描述,如东北 */ public function getPositionYangGuiDesc() { return $this->getDayPositionYangGuiDesc(); } /** * 获取日阳贵神方位 * @return string 阳贵神方位,如艮 */ public function getDayPositionYangGui() { return LunarUtil::$POSITION_YANG_GUI[$this->dayGanIndex + 1]; } /** * 获取日阳贵神方位描述 * @return string 阳贵神方位描述,如东北 */ public function getDayPositionYangGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getDayPositionYangGui()]; } /** * 获取时辰阳贵神方位 * @return string 阳贵神方位,如艮 */ public function getTimePositionYangGui() { return LunarUtil::$POSITION_YANG_GUI[$this->timeGanIndex + 1]; } /** * 获取时辰阳贵神方位描述 * @return string 阳贵神方位描述,如东北 */ public function getTimePositionYangGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getTimePositionYangGui()]; } /** * 获取日阴贵神方位 * @return string 阴贵神方位,如艮 */ public function getPositionYinGui() { return $this->getDayPositionYinGui(); } /** * 获取日阴贵神方位描述 * @return string 阴贵神方位描述,如东北 */ public function getPositionYinGuiDesc() { return $this->getDayPositionYinGuiDesc(); } /** * 获取日阴贵神方位 * @return string 阴贵神方位,如艮 */ public function getDayPositionYinGui() { return LunarUtil::$POSITION_YIN_GUI[$this->dayGanIndex + 1]; } /** * 获取日阴贵神方位描述 * @return string 阴贵神方位描述,如东北 */ public function getDayPositionYinGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getDayPositionYinGui()]; } /** * 获取时辰阴贵神方位 * @return string 阴贵神方位,如艮 */ public function getTimePositionYinGui() { return LunarUtil::$POSITION_YIN_GUI[$this->timeGanIndex + 1]; } /** * 获取时辰阴贵神方位描述 * @return string 阴贵神方位描述,如东北 */ public function getTimePositionYinGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getTimePositionYinGui()]; } /** * 获取日福神方位 * @return string 福神方位,如艮 */ public function getPositionFu() { return $this->getDayPositionFu(); } /** * 获取日福神方位描述 * @return string 福神方位描述,如东北 */ public function getPositionFuDesc() { return $this->getDayPositionFuDesc(); } /** * 获取日福神方位,默认流派2 * @return string 福神方位,如艮 */ public function getDayPositionFu() { return $this->getDayPositionFuBySect(2); } /** * 获取日福神方位 * @param int $sect 流派,可选1或2 * @return string 福神方位,如艮 */ public function getDayPositionFuBySect($sect) { $fu = 1 == $sect ? LunarUtil::$POSITION_FU : LunarUtil::$POSITION_FU_2; return $fu[$this->dayGanIndex + 1]; } /** * 获取日福神方位描述,默认流派2 * @return string 福神方位描述,如东北 */ public function getDayPositionFuDesc() { return $this->getDayPositionFuDescBySect(2); } /** * 获取日福神方位描述 * @param int $sect 流派,可选1或2 * @return string 福神方位描述,如东北 */ public function getDayPositionFuDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getDayPositionFuBySect($sect)]; } /** * 获取时辰福神方位,默认流派2 * @return string 福神方位,如艮 */ public function getTimePositionFu() { return $this->getTimePositionFuBySect(2); } /** * 获取时辰福神方位 * @param int $sect 流派,可选1或2 * @return string 福神方位,如艮 */ public function getTimePositionFuBySect($sect) { $fu = 1 == $sect ? LunarUtil::$POSITION_FU : LunarUtil::$POSITION_FU_2; return $fu[$this->timeGanIndex + 1]; } /** * 获取时辰福神方位描述,默认流派2 * @return string 福神方位描述,如东北 */ public function getTimePositionFuDesc() { return $this->getTimePositionFuDescBySect(2); } /** * 获取时辰福神方位描述 * @param int $sect 流派,可选1或2 * @return string 福神方位描述,如东北 */ public function getTimePositionFuDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getTimePositionFuBySect($sect)]; } /** * 获取日财神方位 * @return string 财神方位,如艮 */ public function getPositionCai() { return $this->getDayPositionCai(); } /** * 获取日财神方位描述 * @return string 财神方位描述,如东北 */ public function getPositionCaiDesc() { return $this->getDayPositionCaiDesc(); } /** * 获取日财神方位 * @return string 财神方位,如艮 */ public function getDayPositionCai() { return LunarUtil::$POSITION_CAI[$this->dayGanIndex + 1]; } /** * 获取日财神方位描述 * @return string 财神方位描述,如东北 */ public function getDayPositionCaiDesc() { return LunarUtil::$POSITION_DESC[$this->getDayPositionCai()]; } /** * 获取时辰财神方位 * @return string 财神方位,如艮 */ public function getTimePositionCai() { return LunarUtil::$POSITION_CAI[$this->timeGanIndex + 1]; } /** * 获取时辰财神方位描述 * @return string 财神方位描述,如东北 */ public function getTimePositionCaiDesc() { return LunarUtil::$POSITION_DESC[$this->getTimePositionCai()]; } public function getYearPositionTaiSui() { return $this->getYearPositionTaiSuiBySect(2); } public function getYearPositionTaiSuiBySect($sect) { switch ($sect) { case 1: $yearZhiIndex = $this->yearZhiIndex; break; case 3: $yearZhiIndex = $this->yearZhiIndexExact; break; default: $yearZhiIndex = $this->yearZhiIndexByLiChun; } return LunarUtil::$POSITION_TAI_SUI_YEAR[$yearZhiIndex]; } public function getYearPositionTaiSuiDesc() { return $this->getYearPositionTaiSuiDescBySect(2); } public function getYearPositionTaiSuiDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getYearPositionTaiSuiBySect($sect)]; } protected function _getMonthPositionTaiSui($monthZhiIndex, $monthGanIndex) { $m = $monthZhiIndex - LunarUtil::$BASE_MONTH_ZHI_INDEX; if ($m < 0) { $m += 12; } switch ($m) { case 0: case 4: case 8: $p = '艮'; break; case 2: case 6: case 10: $p = '坤'; break; case 3: case 7: case 11: $p = '巽'; break; default: $p = LunarUtil::$POSITION_GAN[$monthGanIndex]; } return $p; } public function getMonthPositionTaiSuiBySect($sect) { switch ($sect) { case 3: $monthZhiIndex = $this->monthZhiIndexExact; $monthGanIndex = $this->monthGanIndexExact; break; default: $monthZhiIndex = $this->monthZhiIndex; $monthGanIndex = $this->monthGanIndex; } return $this->_getMonthPositionTaiSui($monthZhiIndex, $monthGanIndex); } public function getMonthPositionTaiSui() { return $this->getMonthPositionTaiSuiBySect(2); } public function getMonthPositionTaiSuiDesc() { return $this->getMonthPositionTaiSuiDescBySect(2); } public function getMonthPositionTaiSuiDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getMonthPositionTaiSuiBySect($sect)]; } protected function _getDayPositionTaiSui($dayInGanZhi, $yearZhiIndex) { if (strpos('甲子,乙丑,丙寅,丁卯,戊辰,已巳',$dayInGanZhi) !== false) { $p = '震'; } else if (strpos('丙子,丁丑,戊寅,已卯,庚辰,辛巳',$dayInGanZhi) !== false) { $p = '离'; } else if (strpos('戊子,已丑,庚寅,辛卯,壬辰,癸巳',$dayInGanZhi) !== false) { $p = '中'; } else if (strpos('庚子,辛丑,壬寅,癸卯,甲辰,乙巳',$dayInGanZhi) !== false) { $p = '兑'; } else if (strpos('壬子,癸丑,甲寅,乙卯,丙辰,丁巳',$dayInGanZhi) !== false) { $p = '坎'; } else { $p = LunarUtil::$POSITION_TAI_SUI_YEAR[$yearZhiIndex]; } return $p; } public function getDayPositionTaiSuiBySect($sect) { switch ($sect) { case 1: $dayInGanZhi = $this->getDayInGanZhi(); $yearZhiIndex = $this->yearZhiIndex; break; case 3: $dayInGanZhi = $this->getDayInGanZhi(); $yearZhiIndex = $this->yearZhiIndexExact; break; default: $dayInGanZhi = $this->getDayInGanZhiExact2(); $yearZhiIndex = $this->yearZhiIndexByLiChun; } return $this->_getDayPositionTaiSui($dayInGanZhi, $yearZhiIndex); } public function getDayPositionTaiSui() { return $this->getDayPositionTaiSuiBySect(2); } public function getDayPositionTaiSuiDesc() { return $this->getDayPositionTaiSuiDescBySect(2); } public function getDayPositionTaiSuiDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getDayPositionTaiSuiBySect($sect)]; } /** * 获取冲 * @return string 冲,如申 */ public function getChong() { return $this->getDayChong(); } /** * 获取日冲 * @return string 日冲,如申 */ public function getDayChong() { return LunarUtil::$CHONG[$this->dayZhiIndex]; } /** * 获取时冲 * @return string 时冲,如申 */ public function getTimeChong() { return LunarUtil::$CHONG[$this->timeZhiIndex]; } /** * 获取无情之克的冲天干 * @return string 无情之克的冲天干,如甲 */ public function getChongGan() { return $this->getDayChongGan(); } /** * 获取无情之克的日冲天干 * @return string 无情之克的日冲天干,如甲 */ public function getDayChongGan() { return LunarUtil::$CHONG_GAN[$this->dayGanIndex]; } /** * 获取无情之克的时冲天干 * @return string 无情之克的时冲天干,如甲 */ public function getTimeChongGan() { return LunarUtil::$CHONG_GAN[$this->timeGanIndex]; } /** * 获取有情之克的冲天干 * @return string 有情之克的冲天干,如甲 */ public function getChongGanTie() { return $this->getDayChongGanTie(); } /** * 获取有情之克的日冲天干 * @return string 有情之克的日冲天干,如甲 */ public function getDayChongGanTie() { return LunarUtil::$CHONG_GAN_TIE[$this->dayGanIndex]; } /** * 获取有情之克的时冲天干 * @return string 有情之克的时冲天干,如甲 */ public function getTimeChongGanTie() { return LunarUtil::$CHONG_GAN_TIE[$this->timeGanIndex]; } /** * 获取冲生肖 * @return string 冲生肖,如猴 */ public function getChongShengXiao() { return $this->getDayChongShengXiao(); } /** * 获取日冲生肖 * @return string 日冲生肖,如猴 */ public function getDayChongShengXiao() { $chong = $this->getDayChong(); for ($i = 0, $j = count(LunarUtil::$ZHI); $i < $j; $i++) { if (strcmp(LunarUtil::$ZHI[$i], $chong) === 0) { return LunarUtil::$SHENG_XIAO[$i]; } } return ''; } /** * 获取时冲生肖 * @return string 时冲生肖,如猴 */ public function getTimeChongShengXiao() { $chong = $this->getTimeChong(); for ($i = 0, $j = count(LunarUtil::$ZHI); $i < $j; $i++) { if (strcmp(LunarUtil::$ZHI[$i], $chong) === 0) { return LunarUtil::$SHENG_XIAO[$i]; } } return ''; } /** * 获取冲描述 * @return string 冲描述,如(壬申)猴 */ public function getChongDesc() { return $this->getDayChongDesc(); } /** * 获取日冲描述 * @return string 日冲描述,如(壬申)猴 */ public function getDayChongDesc() { return '(' . $this->getDayChongGan() . $this->getDayChong() . ')' . $this->getDayChongShengXiao(); } /** * 获取时冲描述 * @return string 时冲描述,如(壬申)猴 */ public function getTimeChongDesc() { return '(' . $this->getTimeChongGan() . $this->getTimeChong() . ')' . $this->getTimeChongShengXiao(); } /** * 获取煞 * @return string 煞,如北 */ public function getSha() { return $this->getDaySha(); } /** * 获取日煞 * @return string 日煞,如北 */ public function getDaySha() { return LunarUtil::$SHA[$this->getDayZhi()]; } /** * 获取时煞 * @return string 时煞,如北 */ public function getTimeSha() { return LunarUtil::$SHA[$this->getTimeZhi()]; } /** * 获取年纳音 * @return string 年纳音,如剑锋金 */ public function getYearNaYin() { return LunarUtil::$NAYIN[$this->getYearInGanZhi()]; } /** * 获取月纳音 * @return string 月纳音,如剑锋金 */ public function getMonthNaYin() { return LunarUtil::$NAYIN[$this->getMonthInGanZhi()]; } /** * 获取日纳音 * @return string 日纳音,如剑锋金 */ public function getDayNaYin() { return LunarUtil::$NAYIN[$this->getDayInGanZhi()]; } /** * 获取时辰纳音 * @return string 时辰纳音,如剑锋金 */ public function getTimeNaYin() { return LunarUtil::$NAYIN[$this->getTimeInGanZhi()]; } /** * 获取八字,男性也称乾造,女性也称坤造(以立春交接时刻作为新年的开始) * @return string[] 八字(男性也称乾造,女性也称坤造) */ public function getBaZi() { $baZi = $this->getEightChar(); $l = array(); $l[] = $baZi->getYear(); $l[] = $baZi->getMonth(); $l[] = $baZi->getDay(); $l[] = $baZi->getTime(); return $l; } /** * 获取八字五行 * @return string[] 八字五行 */ public function getBaZiWuXing() { $baZi = $this->getEightChar(); $l = array(); $l[] = $baZi->getYearWuXing(); $l[] = $baZi->getMonthWuXing(); $l[] = $baZi->getDayWuXing(); $l[] = $baZi->getTimeWuXing(); return $l; } /** * 获取八字纳音 * @return string[] 八字纳音 */ public function getBaZiNaYin() { $baZi = $this->getEightChar(); $l = array(); $l[] = $baZi->getYearNaYin(); $l[] = $baZi->getMonthNaYin(); $l[] = $baZi->getDayNaYin(); $l[] = $baZi->getTimeNaYin(); return $l; } /** * 获取八字天干十神,日柱十神为日主,其余三柱根据天干十神表查询 * @return string[] 八字天干十神 */ public function getBaZiShiShenGan() { $baZi = $this->getEightChar(); $l = array(); $l[] = $baZi->getYearShiShenGan(); $l[] = $baZi->getMonthShiShenGan(); $l[] = $baZi->getDayShiShenGan(); $l[] = $baZi->getTimeShiShenGan(); return $l; } /** * 获取八字地支十神,根据地支十神表查询 * @return string[] 八字地支十神 */ public function getBaZiShiShenZhi() { $baZi = $this->getEightChar(); $yearShiShenZhi = $baZi->getYearShiShenZhi(); $monthShiShenZhi = $baZi->getMonthShiShenZhi(); $dayShiShenZhi = $baZi->getDayShiShenZhi(); $timeShiShenZhi = $baZi->getTimeShiShenZhi(); $l = array(); $l[] = $yearShiShenZhi[0]; $l[] = $monthShiShenZhi[0]; $l[] = $dayShiShenZhi[0]; $l[] = $timeShiShenZhi[0]; return $l; } /** * 获取八字年支十神 * @return string[] 八字年支十神 */ public function getBaZiShiShenYearZhi() { return $this->getEightChar()->getYearShiShenZhi(); } /** * 获取八字月支十神 * @return string[] 八字月支十神 */ public function getBaZiShiShenMonthZhi() { return $this->getEightChar()->getMonthShiShenZhi(); } /** * 获取八字日支十神 * @return string[] 八字日支十神 */ public function getBaZiShiShenDayZhi() { return $this->getEightChar()->getDayShiShenZhi(); } /** * 获取八字时支十神 * @return string[] 八字时支十神 */ public function getBaZiShiShenTimeZhi() { return $this->getEightChar()->getTimeShiShenZhi(); } /** * 获取十二执星:建、除、满、平、定、执、破、危、成、收、开、闭。当月支与日支相同即为建,依次类推 * @return string 执星 */ public function getZhiXing() { $offset = $this->dayZhiIndex - $this->monthZhiIndex; if ($offset < 0) { $offset += 12; } return LunarUtil::$ZHI_XING[$offset + 1]; } /** * 获取值日天神 * @return string 值日天神 */ public function getDayTianShen() { return LunarUtil::$TIAN_SHEN[($this->dayZhiIndex + LunarUtil::$ZHI_TIAN_SHEN_OFFSET[$this->getMonthZhi()]) % 12 + 1]; } /** * 获取值时天神 * @return string 值时天神 */ public function getTimeTianShen() { return LunarUtil::$TIAN_SHEN[($this->timeZhiIndex + LunarUtil::$ZHI_TIAN_SHEN_OFFSET[$this->getDayZhiExact()]) % 12 + 1]; } /** * 获取值日天神类型:黄道/黑道 * @return string 值日天神类型:黄道/黑道 */ public function getDayTianShenType() { return LunarUtil::$TIAN_SHEN_TYPE[$this->getDayTianShen()]; } /** * 获取值时天神类型:黄道/黑道 * @return string 值时天神类型:黄道/黑道 */ public function getTimeTianShenType() { return LunarUtil::$TIAN_SHEN_TYPE[$this->getTimeTianShen()]; } /** * 获取值日天神吉凶 * @return string 吉/凶 */ public function getDayTianShenLuck() { return LunarUtil::$TIAN_SHEN_TYPE_LUCK[$this->getDayTianShenType()]; } /** * 获取值时天神吉凶 * @return string 吉/凶 */ public function getTimeTianShenLuck() { return LunarUtil::$TIAN_SHEN_TYPE_LUCK[$this->getTimeTianShenType()]; } /** * 获取逐日胎神方位 * @return string 逐日胎神方位 */ public function getDayPositionTai() { return LunarUtil::$POSITION_TAI_DAY[LunarUtil::getJiaZiIndex($this->getDayInGanZhi())]; } /** * 获取逐月胎神方位,闰月无 * @return string 逐月胎神方位 */ public function getMonthPositionTai() { if ($this->month < 0) { return ''; } return LunarUtil::$POSITION_TAI_MONTH[$this->month - 1]; } /** * 获取每日宜 * @return string[] 宜 */ public function getDayYi() { return LunarUtil::getDayYi($this->getMonthInGanZhiExact(), $this->getDayInGanZhi()); } /** * 获取时宜 * @return string[] 宜 */ public function getTimeYi() { return LunarUtil::getTimeYi($this->getDayInGanZhiExact(), $this->getTimeInGanZhi()); } /** * 获取每日忌 * @return string[] 忌 */ public function getDayJi() { return LunarUtil::getDayJi($this->getMonthInGanZhiExact(), $this->getDayInGanZhi()); } /** * 获取时忌 * @return string[] 忌 */ public function getTimeJi() { return LunarUtil::getTimeJi($this->getDayInGanZhiExact(), $this->getTimeInGanZhi()); } /** * 获取日吉神(宜趋),如果没有,返回['无'] * @return string[] 吉神 */ public function getDayJiShen() { return LunarUtil::getDayJiShen($this->getMonth(), $this->getDayInGanZhi()); } /** * 获取日凶煞(宜忌),如果没有,返回['无'] * @return string[] 凶煞 */ public function getDayXiongSha() { return LunarUtil::getDayXiongSha($this->getMonth(), $this->getDayInGanZhi()); } /** * 获取月相 * @return string 月相 */ public function getYueXiang() { return LunarUtil::$YUE_XIANG[$this->getDay()]; } protected function _getYearNineStar($yearInGanZhi) { $indexExact = LunarUtil::getJiaZiIndex($yearInGanZhi) + 1; $index = LunarUtil::getJiaZiIndex($this->getYearInGanZhi()) + 1; $yearOffset = $indexExact - $index; if ($yearOffset > 1) { $yearOffset -= 60; } else if ($yearOffset < -1) { $yearOffset += 60; } $yuan = (int)(($this->year + $yearOffset + 2696) / 60) % 3; $offset = (62 + $yuan * 3 - $indexExact) % 9; if (0 === $offset) { $offset = 9; } return NineStar::fromIndex($offset - 1); } public function getYearNineStarBySect($sect) { switch ($sect) { case 1: $yearInGanZhi = $this->getYearInGanZhi(); break; case 3: $yearInGanZhi = $this->getYearInGanZhiExact(); break; default: $yearInGanZhi = $this->getYearInGanZhiByLiChun(); } return $this->_getYearNineStar($yearInGanZhi); } /** * 获取值年九星(流年紫白星起例歌诀:年上吉星论甲子,逐年星逆中宫起;上中下作三元汇,一上四中七下兑。) * @return NineStar 值年九星 */ public function getYearNineStar() { return $this->getYearNineStarBySect(2); } public function _getMonthNineStar($yearZhiIndex, $monthZhiIndex) { $index = $yearZhiIndex % 3; $n = 27 - ($index * 3); if ($monthZhiIndex < LunarUtil::$BASE_MONTH_ZHI_INDEX) { $n -= 3; } $offset = ($n - $monthZhiIndex) % 9; return NineStar::fromIndex($offset); } public function getMonthNineStarBySect($sect) { switch ($sect) { case 1: $yearZhiIndex = $this->yearZhiIndex; $monthZhiIndex = $this->monthZhiIndex; break; case 3: $yearZhiIndex = $this->yearZhiIndexExact; $monthZhiIndex = $this->monthZhiIndexExact; break; default: $yearZhiIndex = $this->yearZhiIndexByLiChun; $monthZhiIndex = $this->monthZhiIndex; } return $this->_getMonthNineStar($yearZhiIndex, $monthZhiIndex); } /** * 获取值月九星(月紫白星歌诀:子午卯酉八白起,寅申巳亥二黑求,辰戌丑未五黄中。) * @return NineStar 值月九星 */ public function getMonthNineStar() { return $this->getMonthNineStarBySect(2); } /** * 获取值日九星(日家紫白星歌诀:日家白法不难求,二十四气六宫周;冬至雨水及谷雨,阳顺一七四中游;夏至处暑霜降后,九三六星逆行求。) * @return NineStar 值日九星 */ public function getDayNineStar() { $solarYmd = $this->solar->toYmd(); $dongZhi = $this->jieQi['冬至']; $dongZhi2 = $this->jieQi['DONG_ZHI']; $xiaZhi = $this->jieQi['夏至']; $dongZhiIndex = LunarUtil::getJiaZiIndex($dongZhi->getLunar()->getDayInGanZhi()); $dongZhiIndex2 = LunarUtil::getJiaZiIndex($dongZhi2->getLunar()->getDayInGanZhi()); $xiaZhiIndex = LunarUtil::getJiaZiIndex($xiaZhi->getLunar()->getDayInGanZhi()); if ($dongZhiIndex > 29) { $solarShunBai = $dongZhi->next(60 - $dongZhiIndex); } else { $solarShunBai = $dongZhi->next(-$dongZhiIndex); } $solarShunBaiYmd = $solarShunBai->toYmd(); if ($dongZhiIndex2 > 29) { $solarShunBai2 = $dongZhi2->next(60 - $dongZhiIndex2); } else { $solarShunBai2 = $dongZhi2->next(-$dongZhiIndex2); } $solarShunBaiYmd2 = $solarShunBai2->toYmd(); if ($xiaZhiIndex > 29) { $solarNiZi = $xiaZhi->next(60 - $xiaZhiIndex); } else { $solarNiZi = $xiaZhi->next(-$xiaZhiIndex); } $solarNiZiYmd = $solarNiZi->toYmd(); $offset = 0; if (strcmp($solarYmd, $solarShunBaiYmd) >= 0 && strcmp($solarYmd, $solarNiZiYmd) < 0) { $offset = $this->solar->subtract($solarShunBai) % 9; } else if (strcmp($solarYmd, $solarNiZiYmd) >= 0 && strcmp($solarYmd, $solarShunBaiYmd2) < 0) { $offset = 8 - ($this->solar->subtract($solarNiZi) % 9); } else if (strcmp($solarYmd, $solarShunBaiYmd2) >= 0) { $offset = $this->solar->subtract($solarShunBai2) % 9; } else if (strcmp($solarYmd, $solarShunBaiYmd) < 0) { $offset = (8 + $solarShunBai->subtract($this->solar)) % 9; } return NineStar::fromIndex($offset); } /** * 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。) * @return NineStar 值时九星 */ public function getTimeNineStar() { //顺逆 $solarYmd = $this->solar->toYmd(); $asc = false; if (strcmp($solarYmd, $this->jieQi['冬至']->toYmd()) >= 0 && strcmp($solarYmd, $this->jieQi['夏至']->toYmd()) < 0) { $asc = true; } else if (strcmp($solarYmd, $this->jieQi['DONG_ZHI']->toYmd()) >= 0) { $asc = true; } $start = $asc ? 6 : 2; $dayZhi = $this->getDayZhi(); if (strpos('子午卯酉', $dayZhi) !== false) { $start = $asc ? 0 : 8; } else if (strpos('辰戌丑未', $dayZhi) !== false) { $start = $asc ? 3 : 5; } $index = $asc ? $start + $this->timeZhiIndex : $start + 9 - $this->timeZhiIndex; return NineStar::fromIndex($index % 9); } /** * 获取节气表(节气名称:公历),节气交接时刻精确到秒,以冬至开头,按先后顺序排列 * @return Solar[] 节气表 */ public function getJieQiTable() { return $this->jieQi; } /** * 获取最近的节气,如果未找到匹配的,返回null * @param $forward bool 是否顺推,true为顺推,false为逆推 * @param $conditions array|null 过滤条件,如果设置过滤条件,仅返回匹配该名称的 * @param $wholeDay bool 是否按天计 * @return JieQi|null 节气 */ protected function getNearJieQi($forward, $conditions, $wholeDay) { $name = null; $near = null; $filter = null != $conditions && count($conditions) > 0; $today = $wholeDay ? $this->solar->toYmd() : $this->solar->toYmdHms(); foreach ($this->jieQi as $key => $solar) { $jq = $this->convertJieQi($key); if ($filter) { if (!in_array($jq, $conditions)) { continue; } } $day = $wholeDay ? $solar->toYmd() : $solar->toYmdHms(); if ($forward) { if (strcmp($day, $today) <= 0) { continue; } if (null == $near) { $name = $jq; $near = $solar; } else { $nearDay = $wholeDay ? $near->toYmd() : $near->toYmdHms(); if (strcmp($day, $nearDay) < 0) { $name = $jq; $near = $solar; } } } else { if (strcmp($day, $today) > 0) { continue; } if (null == $near) { $name = $jq; $near = $solar; } else { $nearDay = $wholeDay ? $near->toYmd() : $near->toYmdHms(); if (strcmp($day, $nearDay) > 0) { $name = $jq; $near = $solar; } } } } if (null == $near) { return null; } return new JieQi($name, $near); } public function getNextJieByWholeDay($wholeDay) { $conditions = array(); for ($i = 0, $j = count(self::$JIE_QI_IN_USE) / 2; $i < $j; $i++) { $conditions[] = self::$JIE_QI_IN_USE[$i * 2]; } return $this->getNearJieQi(true, $conditions, $wholeDay); } /** * 获取下一节(顺推的第一个节) * @return JieQi|null 节气 */ public function getNextJie() { return $this->getNextJieByWholeDay(false); } public function getPrevJieByWholeDay($wholeDay) { $conditions = array(); for ($i = 0, $j = count(self::$JIE_QI_IN_USE) / 2; $i < $j; $i++) { $conditions[] = self::$JIE_QI_IN_USE[$i * 2]; } return $this->getNearJieQi(false, $conditions, $wholeDay); } /** * 获取上一节(逆推的第一个节) * @return JieQi|null 节气 */ public function getPrevJie() { return $this->getPrevJieByWholeDay(false); } public function getNextQiByWholeDay($wholeDay) { $conditions = array(); for ($i = 0, $j = count(self::$JIE_QI_IN_USE) / 2; $i < $j; $i++) { $conditions[] = self::$JIE_QI_IN_USE[$i * 2 + 1]; } return $this->getNearJieQi(true, $conditions, $wholeDay); } /** * 获取下一气令(顺推的第一个气令) * @return JieQi|null 节气 */ public function getNextQi() { return $this->getNextQiByWholeDay(false); } public function getPrevQiByWholeDay($wholeDay) { $conditions = array(); for ($i = 0, $j = count(self::$JIE_QI_IN_USE) / 2; $i < $j; $i++) { $conditions[] = self::$JIE_QI_IN_USE[$i * 2 + 1]; } return $this->getNearJieQi(false, $conditions, $wholeDay); } /** * 获取上一气令(逆推的第一个气令) * @return JieQi|null 节气 */ public function getPrevQi() { return $this->getPrevQiByWholeDay(false); } public function getNextJieQiByWholeDay($wholeDay) { return $this->getNearJieQi(true, null, $wholeDay); } /** * 获取下一节气(顺推的第一个节气) * @return JieQi|null 节气 */ public function getNextJieQi() { return $this->getNextJieQiByWholeDay(false); } public function getPrevJieQiByWholeDay($wholeDay) { return $this->getNearJieQi(false, null, $wholeDay); } /** * 获取上一节气(逆推的第一个节气) * @return JieQi|null 节气 */ public function getPrevJieQi() { return $this->getPrevJieQiByWholeDay(false); } /** * 获取节气名称,如果无节气,返回空字符串 * @return string 节气名称 */ public function getJieQi() { foreach ($this->jieQi as $key => $d) { if ($d->getYear() === $this->solar->getYear() && $d->getMonth() === $this->solar->getMonth() && $d->getDay() === $this->solar->getDay()) { return $this->convertJieQi($key); } } return ''; } /** * 获取当天节气对象,如果无节气,返回null * @return JieQi|null 节气对象 */ public function getCurrentJieQi() { foreach ($this->jieQi as $key => $d) { if ($d->getYear() === $this->solar->getYear() && $d->getMonth() === $this->solar->getMonth() && $d->getDay() === $this->solar->getDay()) { return new JieQi($key, $d); } } return null; } /** * 获取当天节令对象,如果无节令,返回null * @return JieQi|null 节气对象 */ public function getCurrentJie() { for ($i = 0, $j = count(self::$JIE_QI_IN_USE); $i < $j; $i += 2) { $key = self::$JIE_QI_IN_USE[$i]; $d = $this->jieQi[$key]; if ($d->getYear() === $this->solar->getYear() && $d->getMonth() === $this->solar->getMonth() && $d->getDay() === $this->solar->getDay()) { return new JieQi($key, $d); } } return null; } /** * 获取当天气令对象,如果无气令,返回null * @return JieQi|null 节气对象 */ public function getCurrentQi() { for ($i = 1, $j = count(self::$JIE_QI_IN_USE); $i < $j; $i += 2) { $key = self::$JIE_QI_IN_USE[$i]; $d = $this->jieQi[$key]; if ($d->getYear() === $this->solar->getYear() && $d->getMonth() === $this->solar->getMonth() && $d->getDay() === $this->solar->getDay()) { return new JieQi($key, $d); } } return null; } public function getTimeGanIndex() { return $this->timeGanIndex; } public function getTimeZhiIndex() { return $this->timeZhiIndex; } public function getDayGanIndex() { return $this->dayGanIndex; } public function getDayZhiIndex() { return $this->dayZhiIndex; } public function getMonthGanIndex() { return $this->monthGanIndex; } public function getMonthZhiIndex() { return $this->monthZhiIndex; } public function getYearGanIndex() { return $this->yearGanIndex; } public function getYearZhiIndex() { return $this->yearZhiIndex; } public function getYearGanIndexByLiChun() { return $this->yearGanIndexByLiChun; } public function getYearZhiIndexByLiChun() { return $this->yearZhiIndexByLiChun; } public function getDayGanIndexExact() { return $this->dayGanIndexExact; } public function getDayGanIndexExact2() { return $this->dayGanIndexExact2; } public function getDayZhiIndexExact() { return $this->dayZhiIndexExact; } public function getDayZhiIndexExact2() { return $this->dayZhiIndexExact2; } public function getMonthGanIndexExact() { return $this->monthGanIndexExact; } public function getMonthZhiIndexExact() { return $this->monthZhiIndexExact; } public function getYearGanIndexExact() { return $this->yearGanIndexExact; } public function getYearZhiIndexExact() { return $this->yearZhiIndexExact; } public function getEightChar() { if (null == $this->eightChar) { $this->eightChar = EightChar::fromLunar($this); } return $this->eightChar; } /** * 获取往后推几天的农历日期,如果要往前推,则天数用负数 * @param int days 天数 * @return Lunar 农历日期 */ public function next($days) { return $this->solar->next($days)->getLunar(); } /** * @return string */ public function toFullString() { $s = ''; $s .= $this; $s .= ' '; $s .= $this->getYearInGanZhi(); $s .= '('; $s .= $this->getYearShengXiao(); $s .= ')年 '; $s .= $this->getMonthInGanZhi(); $s .= '('; $s .= $this->getMonthShengXiao(); $s .= ')月 '; $s .= $this->getDayInGanZhi(); $s .= '('; $s .= $this->getDayShengXiao(); $s .= ')日 '; $s .= $this->getTimeZhi(); $s .= '('; $s .= $this->getTimeShengXiao(); $s .= ')时 纳音['; $s .= $this->getYearNaYin(); $s .= ' '; $s .= $this->getMonthNaYin(); $s .= ' '; $s .= $this->getDayNaYin(); $s .= ' '; $s .= $this->getTimeNaYin(); $s .= '] 星期'; $s .= $this->getWeekInChinese(); foreach ($this->getFestivals() as $f) { $s .= ' (' . $f . ')'; } foreach ($this->getOtherFestivals() as $f) { $s .= ' (' . $f . ')'; } $jq = $this->getJieQi(); if (strlen($jq) > 0) { $s .= ' (' . $jq . ')'; } $s .= ' '; $s .= $this->getGong(); $s .= '方'; $s .= $this->getShou(); $s .= ' 星宿['; $s .= $this->getXiu(); $s .= $this->getZheng(); $s .= $this->getAnimal(); $s .= ']('; $s .= $this->getXiuLuck(); $s .= ') 彭祖百忌['; $s .= $this->getPengZuGan(); $s .= ' '; $s .= $this->getPengZuZhi(); $s .= '] 喜神方位['; $s .= $this->getDayPositionXi(); $s .= ']('; $s .= $this->getDayPositionXiDesc(); $s .= ') 阳贵神方位['; $s .= $this->getDayPositionYangGui(); $s .= ']('; $s .= $this->getDayPositionYangGuiDesc(); $s .= ') 阴贵神方位['; $s .= $this->getDayPositionYinGui(); $s .= ']('; $s .= $this->getDayPositionYinGuiDesc(); $s .= ') 福神方位['; $s .= $this->getDayPositionFu(); $s .= ']('; $s .= $this->getDayPositionFuDesc(); $s .= ') 财神方位['; $s .= $this->getDayPositionCai(); $s .= ']('; $s .= $this->getDayPositionCaiDesc(); $s .= ') 冲['; $s .= $this->getChongDesc(); $s .= '] 煞['; $s .= $this->getSha(); $s .= ']'; return $s; } /** * @return string */ public function toString() { return $this->getYearInChinese() . '年' . $this->getMonthInChinese() . '月' . $this->getDayInChinese(); } public function __toString() { return $this->toString(); } /** * 获取年所在旬(以正月初一作为新年的开始) * @return string 旬 */ public function getYearXun() { return LunarUtil::getXun($this->getYearInGanZhi()); } /** * 获取年所在旬(以立春当天作为新年的开始) * @return string 旬 */ public function getYearXunByLiChun() { return LunarUtil::getXun($this->getYearInGanZhiByLiChun()); } /** * 获取年所在旬(以立春交接时刻作为新年的开始) * @return string 旬 */ public function getYearXunExact() { return LunarUtil::getXun($this->getYearInGanZhiExact()); } /** * 获取值年空亡(以正月初一作为新年的开始) * @return string 空亡(旬空) */ public function getYearXunKong() { return LunarUtil::getXunKong($this->getYearInGanZhi()); } /** * 获取值年空亡(以立春当天作为新年的开始) * @return string 空亡(旬空) */ public function getYearXunKongByLiChun() { return LunarUtil::getXunKong($this->getYearInGanZhiByLiChun()); } /** * 获取值年空亡(以立春交接时刻作为新年的开始) * @return string 空亡(旬空) */ public function getYearXunKongExact() { return LunarUtil::getXunKong($this->getYearInGanZhiExact()); } /** * 获取月所在旬(以节交接当天起算) * @return string 旬 */ public function getMonthXun() { return LunarUtil::getXun($this->getMonthInGanZhi()); } /** * 获取月所在旬(以节交接时刻起算) * @return string 旬 */ public function getMonthXunExact() { return LunarUtil::getXun($this->getMonthInGanZhiExact()); } /** * 获取值月空亡(以节交接当天起算) * @return string 空亡(旬空) */ public function getMonthXunKong() { return LunarUtil::getXunKong($this->getMonthInGanZhi()); } /** * 获取值月空亡(以节交接时刻起算) * @return string 空亡(旬空) */ public function getMonthXunKongExact() { return LunarUtil::getXunKong($this->getMonthInGanZhiExact()); } /** * 获取日所在旬(以节交接当天起算) * @return string 旬 */ public function getDayXun() { return LunarUtil::getXun($this->getDayInGanZhi()); } /** * 获取日所在旬(八字流派1,晚子时日柱算明天) * @return string 旬 */ public function getDayXunExact() { return LunarUtil::getXun($this->getDayInGanZhiExact()); } /** * 获取日所在旬(八字流派2,晚子时日柱算当天) * @return string 旬 */ public function getDayXunExact2() { return LunarUtil::getXun($this->getDayInGanZhiExact2()); } /** * 获取值日空亡 * @return string 空亡(旬空) */ public function getDayXunKong() { return LunarUtil::getXunKong($this->getDayInGanZhi()); } /** * 获取值日空亡(八字流派1,晚子时日柱算明天) * @return string 空亡(旬空) */ public function getDayXunKongExact() { return LunarUtil::getXunKong($this->getDayInGanZhiExact()); } /** * 获取值日空亡(八字流派2,晚子时日柱算当天) * @return string 空亡(旬空) */ public function getDayXunKongExact2() { return LunarUtil::getXunKong($this->getDayInGanZhiExact2()); } /** * 获取时辰所在旬 * @return string 旬 */ public function getTimeXun() { return LunarUtil::getXun($this->getTimeInGanZhi()); } /** * 获取值时空亡 * @return string 空亡(旬空) */ public function getTimeXunKong() { return LunarUtil::getXunKong($this->getTimeInGanZhi()); } public function getShuJiu() { $current = Solar::fromYmd($this->solar->getYear(), $this->solar->getMonth(), $this->solar->getDay()); $start = $this->jieQi['DONG_ZHI']; $start = Solar::fromYmd($start->getYear(), $start->getMonth(), $start->getDay()); if ($current->isBefore($start)) { $start = $this->jieQi['冬至']; $start = Solar::fromYmd($start->getYear(), $start->getMonth(), $start->getDay()); } $end = Solar::fromYmd($start->getYear(), $start->getMonth(), $start->getDay())->next(81); if ($current->isBefore($start) || (!$current->isBefore($end))) { return null; } $days = $current->subtract($start); return new ShuJiu(LunarUtil::$NUMBER[(int)($days / 9) + 1] . '九', $days % 9 + 1); } public function getFu() { $current = Solar::fromYmd($this->solar->getYear(), $this->solar->getMonth(), $this->solar->getDay()); $xiaZhi = $this->jieQi['夏至']; $liQiu = $this->jieQi['立秋']; $start = Solar::fromYmd($xiaZhi->getYear(), $xiaZhi->getMonth(), $xiaZhi->getDay()); $add = 6 - $xiaZhi->getLunar()->getDayGanIndex(); if ($add < 0) { $add += 10; } $add += 20; $start = $start->next($add); if ($current->isBefore($start)) { return null; } $days = $current->subtract($start); if ($days < 10) { return new Fu('初伏', $days + 1); } $start = $start->next(10); $days = $current->subtract($start); if ($days < 10) { return new Fu('中伏', $days + 1); } $start = $start->next(10); $days = $current->subtract($start); $liQiuSolar = Solar::fromYmd($liQiu->getYear(), $liQiu->getMonth(), $liQiu->getDay()); if ($liQiuSolar->isAfter($start)) { if ($days < 10) { return new Fu('中伏', $days + 11); } $start = $start->next(10); $days = $current->subtract($start); } if ($days < 10) { return new Fu('末伏', $days + 1); } return null; } /** * 获取六曜 * @return string 六曜 */ public function getLiuYao() { return LunarUtil::$LIU_YAO[(abs($this->month) + $this->day - 2) % 6]; } /** * 获取物候 * @return string 物候 */ public function getWuHou() { $jieQi = $this->getPrevJieQiByWholeDay(true); $offset = 0; for ($i = 0, $j = count(self::$JIE_QI); $i < $j; $i++) { if (strcmp($jieQi->getName(), self::$JIE_QI[$i]) === 0) { $offset = $i; break; } } $index = (int)($this->solar->subtract($jieQi->getSolar()) / 5); if ($index > 2) { $index = 2; } return LunarUtil::$WU_HOU[($offset * 3 + $index) % count(LunarUtil::$WU_HOU)]; } public function getHou() { $jieQi = $this->getPrevJieQiByWholeDay(true); $max = count(LunarUtil::$HOU) - 1; $offset = floor($this->solar->subtract($jieQi->getSolar()) / 5); if ($offset > $max) { $offset = $max; } return $jieQi->getName() . ' ' . LunarUtil::$HOU[$offset]; } public function getDayLu() { $gan = LunarUtil::$LU[$this->getDayGan()]; $zhi = null; if (!empty(LunarUtil::$LU[$this->getDayZhi()])) { $zhi = LunarUtil::$LU[$this->getDayZhi()]; } $lu = $gan . '命互禄'; if (null != $zhi) { $lu .= ' ' . $zhi . '命进禄'; } return $lu; } /** * 获取时辰 * @return LunarTime 时辰 */ public function getTime() { return LunarTime::fromYmdHms($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second); } /** * 获取时辰列表 * @return LunarTime[] 时辰列表 */ public function getTimes() { $l = array(); $l[] = LunarTime::fromYmdHms($this->year, $this->month, $this->day, 0, 0, 0); for ($i = 0; $i < 12; $i++) { $l[] = LunarTime::fromYmdHms($this->year, $this->month, $this->day, ($i + 1) * 2 - 1, 0, 0); } return $l; } /** * 获取佛历 * @return Foto 佛历 */ public function getFoto() { return Foto::fromLunar($this); } /** * 获取道历 * @return Tao 道历 */ public function getTao() { return Tao::fromLunar($this); } } src/LunarMonth.php 0000644 00000017310 14641217602 0010140 0 ustar 00 year = intval($lunarYear); $this->month = intval($lunarMonth); $this->dayCount = intval($dayCount); $this->firstJulianDay = $firstJulianDay; $this->index = $index; $this->zhiIndex = ($index - 1 + LunarUtil::$BASE_MONTH_ZHI_INDEX) % 12; } public function toString() { return $this->year . '.' . $this->month; } public function toFullString() { return $this->year . '年' . ($this->isLeap() ? '闰' : '') . abs($this->month) . '月(' . $this->dayCount . '天)'; } public function __toString() { return $this->toString(); } /** * 通过农历年月初始化 * @param int $lunarYear 农历年 * @param int $lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2 * @return LunarMonth */ public static function fromYm($lunarYear, $lunarMonth) { return LunarYear::fromYear($lunarYear)->getMonth($lunarMonth); } /** * 获取农历年 * @return int 获取农历年 */ public function getYear() { return $this->year; } /** * 获取农历月 * @return int 农历月:1-12,闰月为负数,如闰2月为-2 */ public function getMonth() { return $this->month; } /** * 获取天数 * @return int 天数 */ public function getDayCount() { return $this->dayCount; } /** * 获取初一的儒略日 * @return double 获取初一的儒略日 */ public function getFirstJulianDay() { return $this->firstJulianDay; } public function getIndex() { return $this->index; } public function getZhiIndex() { return $this->zhiIndex; } public function getGanIndex() { $offset = (LunarYear::fromYear($this->year)->getGanIndex() + 1) % 5 * 2; return ($this->index - 1 + $offset) % 10; } public function getGan() { return LunarUtil::$GAN[$this->getGanIndex() + 1]; } public function getZhi() { return LunarUtil::$ZHI[$this->getZhiIndex() + 1]; } public function getGanZhi() { return $this->getGan() . $this->getZhi(); } /** * 获取喜神方位 * @return string 喜神方位,如艮 */ public function getPositionXi() { return LunarUtil::$POSITION_XI[$this->getGanIndex() + 1]; } /** * 获取喜神方位描述 * @return string 喜神方位描述,如东北 */ public function getPositionXiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionXi()]; } /** * 获取阳贵神方位 * @return string 阳贵神方位,如艮 */ public function getPositionYangGui() { return LunarUtil::$POSITION_YANG_GUI[$this->getGanIndex() + 1]; } /** * 获取阳贵神方位描述 * @return string 阳贵神方位描述,如东北 */ public function getPositionYangGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionYangGui()]; } /** * 获取阴贵神方位 * @return string 阴贵神方位,如艮 */ public function getPositionYinGui() { return LunarUtil::$POSITION_YIN_GUI[$this->getGanIndex() + 1]; } /** * 获取阴贵神方位描述 * @return string 阴贵神方位描述,如东北 */ public function getPositionYinGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionYinGui()]; } /** * 获取福神方位,默认流派2 * @return string 福神方位,如艮 */ public function getPositionFu() { return $this->getPositionFuBySect(2); } /** * 获取福神方位 * @param int $sect 流派,可选1或2 * @return string 福神方位,如艮 */ public function getPositionFuBySect($sect) { $fu = 1 == $sect ? LunarUtil::$POSITION_FU : LunarUtil::$POSITION_FU_2; return $fu[$this->getGanIndex() + 1]; } /** * 获取福神方位描述,默认流派2 * @return string 福神方位描述,如东北 */ public function getPositionFuDesc() { return $this->getPositionFuDescBySect(2); } /** * 获取福神方位描述 * @param int $sect 流派,可选1或2 * @return string 福神方位描述,如东北 */ public function getPositionFuDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getPositionFuBySect($sect)]; } /** * 获取财神方位 * @return string 财神方位,如艮 */ public function getPositionCai() { return LunarUtil::$POSITION_CAI[$this->getGanIndex() + 1]; } /** * 获取财神方位描述 * @return string 财神方位描述,如东北 */ public function getPositionCaiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionCai()]; } /** * 是否闰月 * @return bool true/false */ public function isLeap() { return $this->month < 0; } public function getPositionTaiSui() { $m = abs($this->month); switch ($m) { case 1: case 5: case 9: $p = '艮'; break; case 3: case 7: case 11: $p = '坤'; break; case 4: case 8: case 12: $p = '巽'; break; default: $p = LunarUtil::$POSITION_GAN[Solar::fromJulianDay($this->getFirstJulianDay())->getLunar()->getMonthGanIndex()]; } return $p; } public function getPositionTaiSuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionTaiSui()]; } public function getNineStar() { $index = LunarYear::fromYear($this->year)->getZhiIndex() % 3; $m = abs($this->month); $monthZhiIndex = (13 + $m) % 12; $n = 27 - ($index * 3); if ($monthZhiIndex < LunarUtil::$BASE_MONTH_ZHI_INDEX) { $n -= 3; } $offset = ($n - $monthZhiIndex) % 9; return NineStar::fromIndex($offset); } public function next($n) { if (0 == $n) { return LunarMonth::fromYm($this->year, $this->month); } else { $rest = abs($n); $ny = $this->year; $iy = $ny; $im = $this->month; $index = 0; $months = LunarYear::fromYear($ny)->getMonths(); if ($n > 0) { while (true) { $size = count($months); for ($i = 0; $i < $size; $i++) { $m = $months[$i]; if ($m->getYear() == $iy && $m->getMonth() == $im) { $index = $i; break; } } $more = $size - $index - 1; if ($rest < $more) { break; } $rest -= $more; $lastMonth = $months[$size - 1]; $iy = $lastMonth->getYear(); $im = $lastMonth->getMonth(); $ny++; $months = LunarYear::fromYear($ny)->getMonths(); } return $months[$index + $rest]; } else { while (true) { $size = count($months); for ($i = 0; $i < $size; $i++) { $m = $months[$i]; if ($m->getYear() == $iy && $m->getMonth() == $im) { $index = $i; break; } } if ($rest <= $index) { break; } $rest -= $index; $firstMonth = $months[0]; $iy = $firstMonth->getYear(); $im = $firstMonth->getMonth(); $ny--; $months = LunarYear::fromYear($ny)->getMonths(); } return $months[$index - $rest]; } } } } src/LunarTime.php 0000644 00000022120 14641217602 0007744 0 ustar 00 lunar = Lunar::fromYmdHms($lunarYear, $lunarMonth, $lunarDay, $hour, $minute, $second); $this->zhiIndex = LunarUtil::getTimeZhiIndex(sprintf('%02d:%02d', $hour, $minute)); $this->ganIndex = ($this->lunar->getDayGanIndexExact() % 5 * 2 + $this->zhiIndex) % 10; } /** * 通过指定农历年月日时分秒获取时辰 * @param int $lunarYear 年(农历) * @param int $lunarMonth 月(农历),1到12,闰月为负,即闰2月=-2 * @param int $lunarDay 日(农历),1到30 * @param int $hour 小时(公历) * @param int $minute 分钟(公历) * @param int $second 秒钟(公历) * @return LunarTime */ public static function fromYmdHms($lunarYear, $lunarMonth, $lunarDay, $hour, $minute, $second) { return new LunarTime($lunarYear, $lunarMonth, $lunarDay, $hour, $minute, $second); } /** * 获取时辰生肖 * * @return string 时辰生肖,如虎 */ public function getShengXiao() { return LunarUtil::$SHENG_XIAO[$this->zhiIndex + 1]; } /** * 获取时辰(地支) * @return string 时辰(地支) */ public function getZhi() { return LunarUtil::$ZHI[$this->zhiIndex + 1]; } /** * 获取时辰(天干) * @return string 时辰(天干) */ public function getGan() { return LunarUtil::$GAN[$this->ganIndex + 1]; } /** * 获取时辰干支(时柱) * @return string 时辰干支(时柱) */ public function getGanZhi() { return $this->getGan() . $this->getZhi(); } /** * 获取时辰喜神方位 * @return string 喜神方位,如艮 */ public function getPositionXi() { return LunarUtil::$POSITION_XI[$this->ganIndex + 1]; } /** * 获取时辰喜神方位描述 * @return string 喜神方位描述,如东北 */ public function getPositionXiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionXi()]; } /** * 获取时辰阳贵神方位 * @return string 阳贵神方位,如艮 */ public function getPositionYangGui() { return LunarUtil::$POSITION_YANG_GUI[$this->ganIndex + 1]; } /** * 获取时辰阳贵神方位描述 * @return string 阳贵神方位描述,如东北 */ public function getPositionYangGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionYangGui()]; } /** * 获取时辰阴贵神方位 * @return string 阴贵神方位,如艮 */ public function getPositionYinGui() { return LunarUtil::$POSITION_YIN_GUI[$this->ganIndex + 1]; } /** * 获取时辰阴贵神方位描述 * @return string 阴贵神方位描述,如东北 */ public function getPositionYinGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionYinGui()]; } /** * 获取时辰福神方位,默认流派2 * @return string 福神方位,如艮 */ public function getPositionFu() { return $this->getPositionFuBySect(2); } /** * 获取时辰福神方位 * @param int $sect 流派,可选1或2 * @return string 福神方位,如艮 */ public function getPositionFuBySect($sect) { $fu = 1 == $sect ? LunarUtil::$POSITION_FU : LunarUtil::$POSITION_FU_2; return $fu[$this->ganIndex + 1]; } /** * 获取时辰福神方位描述,默认流派2 * @return string 福神方位描述,如东北 */ public function getPositionFuDesc() { return $this->getPositionFuDescBySect(2); } /** * 获取时辰福神方位描述 * @param int $sect 流派,可选1或2 * @return string 福神方位描述,如东北 */ public function getPositionFuDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getPositionFuBySect($sect)]; } /** * 获取时辰财神方位 * @return string 财神方位,如艮 */ public function getPositionCai() { return LunarUtil::$POSITION_CAI[$this->ganIndex + 1]; } /** * 获取时辰财神方位描述 * @return string 财神方位描述,如东北 */ public function getPositionCaiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionCai()]; } /** * 获取时冲 * @return string 时冲,如申 */ public function getChong() { return LunarUtil::$CHONG[$this->zhiIndex]; } /** * 获取无情之克的时冲天干 * @return string 无情之克的时冲天干,如甲 */ public function getChongGan() { return LunarUtil::$CHONG_GAN[$this->ganIndex]; } /** * 获取有情之克的时冲天干 * @return string 有情之克的时冲天干,如甲 */ public function getChongGanTie() { return LunarUtil::$CHONG_GAN_TIE[$this->ganIndex]; } /** * 获取时冲生肖 * @return string 时冲生肖,如猴 */ public function getChongShengXiao() { $chong = $this->getChong(); for ($i = 0, $j = count(LunarUtil::$ZHI); $i < $j; $i++) { if (strcmp(LunarUtil::$ZHI[$i], $chong) === 0) { return LunarUtil::$SHENG_XIAO[$i]; } } return ''; } /** * 获取时冲描述 * @return string 时冲描述,如(壬申)猴 */ public function getChongDesc() { return '(' . $this->getChongGan() . $this->getChong() . ')' . $this->getChongShengXiao(); } /** * 获取时煞 * @return string 时煞,如北 */ public function getSha() { return LunarUtil::$SHA[$this->getZhi()]; } /** * 获取时辰纳音 * @return string 时辰纳音,如剑锋金 */ public function getNaYin() { return LunarUtil::$NAYIN[$this->getGanZhi()]; } /** * 获取值时天神 * @return string 值时天神 */ public function getTianShen() { return LunarUtil::$TIAN_SHEN[($this->zhiIndex + LunarUtil::$ZHI_TIAN_SHEN_OFFSET[$this->lunar->getDayZhiExact()]) % 12 + 1]; } /** * 获取值时天神类型:黄道/黑道 * @return string 值时天神类型:黄道/黑道 */ public function getTianShenType() { return LunarUtil::$TIAN_SHEN_TYPE[$this->getTianShen()]; } /** * 获取值时天神吉凶 * @return string 吉/凶 */ public function getTianShenLuck() { return LunarUtil::$TIAN_SHEN_TYPE_LUCK[$this->getTianShenType()]; } /** * 获取时宜 * @return string[] 宜 */ public function getYi() { return LunarUtil::getTimeYi($this->lunar->getDayInGanZhiExact(), $this->getGanZhi()); } /** * 获取时忌 * @return string[] 忌 */ public function getJi() { return LunarUtil::getTimeJi($this->lunar->getDayInGanZhiExact(), $this->getGanZhi()); } /** * 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。) * @return NineStar 值时九星 */ public function getNineStar() { //顺逆 $solarYmd = $this->lunar->getSolar()->toYmd(); $jieQi = $this->lunar->getJieQiTable(); $asc = false; if (strcmp($solarYmd, $jieQi['冬至']->toYmd()) >= 0 && strcmp($solarYmd, $jieQi['夏至']->toYmd()) < 0) { $asc = true; } $start = $asc ? 7 : 3; $dayZhi = $this->lunar->getDayZhi(); if (strpos('子午卯酉', $dayZhi) !== false) { $start = $asc ? 1 : 9; } else if (strpos('辰戌丑未', $dayZhi) !== false) { $start = $asc ? 4 : 6; } $index = $asc ? $start + $this->zhiIndex - 1 : $start - $this->zhiIndex - 1; if ($index > 8) { $index -= 9; } if ($index < 0) { $index += 9; } return new NineStar($index); } public function getGanIndex() { return $this->ganIndex; } public function getZhiIndex() { return $this->zhiIndex; } /** * @return string */ public function toString() { return $this->getGanZhi(); } public function __toString() { return $this->toString(); } /** * 获取时辰所在旬 * @return string 旬 */ public function getXun() { return LunarUtil::getXun($this->getGanZhi()); } /** * 获取值时空亡 * @return string 空亡(旬空) */ public function getXunKong() { return LunarUtil::getXunKong($this->getGanZhi()); } public function getMinHm() { $hour = $this->lunar->getHour(); if ($hour <1){ return '00:00'; } else if ($hour > 22) { return '23:00'; } return sprintf('%02d:00', $hour % 2 == 0? $hour - 1 : $hour); } public function getMaxHm() { $hour = $this->lunar->getHour(); if ($hour <1){ return '00:59'; } else if ($hour > 22) { return '23:59'; } return sprintf('%02d:59', $hour % 2 == 0? $hour : $hour + 1); } } src/LunarYear.php 0000644 00000032250 14641217602 0007753 0 ustar 00 year = $lunarYear; $offset = $lunarYear - 4; $yearGanIndex = $offset % 10; $yearZhiIndex = $offset % 12; if ($yearGanIndex < 0) { $yearGanIndex += 10; } if ($yearZhiIndex < 0) { $yearZhiIndex += 12; } $this->ganIndex = $yearGanIndex; $this->zhiIndex = $yearZhiIndex; $this->compute(); } /** * 通过农历年初始化 * @param int $lunarYear 农历年 * @return LunarYear */ public static function fromYear($lunarYear) { if (LunarYear::$CACHE_YEAR == null || LunarYear::$CACHE_YEAR->getYear() != $lunarYear) { $y = new LunarYear($lunarYear); LunarYear::$CACHE_YEAR = $y; } else { $y = LunarYear::$CACHE_YEAR; } return $y; } public function toString() { return $this->year . ''; } public function __toString() { return $this->toString(); } public function toFullString() { return $this->year . '年'; } public function getYear() { return $this->year; } public function getGanIndex() { return $this->ganIndex; } public function getZhiIndex() { return $this->zhiIndex; } public function getGan() { return LunarUtil::$GAN[$this->ganIndex + 1]; } public function getZhi() { return LunarUtil::$ZHI[$this->zhiIndex + 1]; } public function getGanZhi() { return $this->getGan() . $this->getZhi(); } /** * @return double[] */ public function getJieQiJulianDays() { return $this->jieQiJulianDays; } /** * 获取月份 * @return LunarMonth[] */ public function getMonths() { return $this->months; } /** * 获取总天数 * @return int */ public function getDayCount() { $n = 0; foreach ($this->months as $m) { if ($m->getYear() == $this->year) { $n += $m->getDayCount(); } } return $n; } /** * 获取本年的月份 * @return LunarMonth[] */ public function getMonthsInYear() { $l = array(); foreach ($this->months as $m) { if ($m->getYear() == $this->year) { $l[] = $m; } } return $l; } /** * 获取农历月 * @param int $lunarMonth 月,1-12,闰月为负数,如闰2月为-2 * @return LunarMonth|null */ public function getMonth($lunarMonth) { foreach ($this->months as $m) { if ($m->getYear() == $this->year && $m->getMonth() == $lunarMonth) { return $m; } } return null; } /** * 获取闰月 * @return int 闰月数字,1=闰1月,0=无闰月 */ public function getLeapMonth() { foreach ($this->months as $m) { if ($m->getYear() == $this->year && $m->isLeap()) { return abs($m->getMonth()); } } return 0; } private function compute() { // 节气 $jq = array(); // 合朔,即每月初一 $hs = array(); // 每月天数(长度15) $dayCounts = array(); $months = array(); $currentYear = $this->year; $jd = floor(($currentYear - 2000) * 365.2422 + 180); // 355是2000.12冬至,得到较靠近jd的冬至估计值 $w = floor(($jd - 355 + 183) / 365.2422) * 365.2422 + 355; if (ShouXingUtil::calcQi($w) > $jd) { $w -= 365.2422; } // 25个节气时刻(北京时间),从冬至开始到下一个冬至以后 for ($i = 0; $i < 26; $i++) { $jq[] = ShouXingUtil::calcQi($w + 15.2184 * $i); } // 从上年的大雪到下年的立春 for ($i = 0, $j = count(Lunar::$JIE_QI_IN_USE); $i < $j; $i++) { if ($i == 0) { $jd = ShouXingUtil::qiAccurate2($jq[0] - 15.2184); } else if ($i <= 26) { $jd = ShouXingUtil::qiAccurate2($jq[$i - 1]); } else { $jd = ShouXingUtil::qiAccurate2($jq[25] + 15.2184 * ($i - 26)); } $this->jieQiJulianDays[] = $jd + Solar::$J2000; } // 冬至前的初一,今年首朔的日月黄经差w $w = ShouXingUtil::calcShuo($jq[0]); if ($w > $jq[0]) { $w -= 29.53; } // 递推每月初一 for ($i = 0; $i < 16; $i++) { $hs[] = ShouXingUtil::calcShuo($w + 29.5306 * $i); } // 每月 for ($i = 0; $i < 15; $i++) { $dayCounts[] = intval($hs[$i + 1] - $hs[$i]); $months[] = $i; } $prevYear = $currentYear - 1; $leapIndex = 16; if (in_array($currentYear, self::$LEAP_11)) { $leapIndex = 13; } else if (in_array($currentYear, self::$LEAP_12)) { $leapIndex = 14; } else if ($hs[13] <= $jq[24]) { $i = 1; while ($hs[$i + 1] > $jq[2 * $i] && $i < 13) { $i++; } $leapIndex = $i; } for ($i = $leapIndex; $i < 15; $i++) { $months[$i] -= 1; } $fm = -1; $index = -1; $y = $prevYear; for ($i = 0; $i < 15; $i++) { $dm = $hs[$i] + Solar::$J2000; $v2 = $months[$i]; $mc = self::$YMC[$v2 % 12]; if (1724360 <= $dm && $dm < 1729794) { $mc = self::$YMC[($v2 + 1) % 12]; } else if (1807724 <= $dm && $dm < 1808699) { $mc = self::$YMC[($v2 + 1) % 12]; } else if ($dm == 1729794 || $dm == 1808699) { $mc = 12; } if ($fm == -1) { $fm = $mc; $index = $mc; } if ($mc < $fm) { $y += 1; $index = 1; } $fm = $mc; if ($i == $leapIndex) { $mc = -$mc; } else if ($dm == 1729794 || $dm == 1808699) { $mc = -11; } $this->months[] = new LunarMonth($y, $mc, $dayCounts[$i], $hs[$i] + Solar::$J2000, $index); $index++; } } protected function getZaoByGan($index, $name) { $month = $this->getMonth(1); if (null == $month) { return ''; } $offset = $index - Solar::fromJulianDay($month->getFirstJulianDay())->getLunar()->getDayGanIndex(); if ($offset < 0) { $offset += 10; } return preg_replace('/几/', LunarUtil::$NUMBER[$offset + 1], $name, 1); } protected function getZaoByZhi($index, $name) { $month = $this->getMonth(1); if (null == $month) { return ''; } $offset = $index - Solar::fromJulianDay($month->getFirstJulianDay())->getLunar()->getDayZhiIndex(); if ($offset < 0) { $offset += 12; } return preg_replace('/几/', LunarUtil::$NUMBER[$offset + 1], $name, 1); } public function getTouLiang() { return $this->getZaoByZhi(0, '几鼠偷粮'); } public function getCaoZi() { return $this->getZaoByZhi(0, '草子几分'); } public function getGengTian() { return $this->getZaoByZhi(1, '几牛耕田'); } public function getHuaShou() { return $this->getZaoByZhi(3, '花收几分'); } public function getZhiShui() { return $this->getZaoByZhi(4, '几龙治水'); } public function getTuoGu() { return $this->getZaoByZhi(6, '几马驮谷'); } public function getQiangMi() { return $this->getZaoByZhi(9, '几鸡抢米'); } public function getKanCan() { return $this->getZaoByZhi(9, '几姑看蚕'); } public function getGongZhu() { return $this->getZaoByZhi(11, '几屠共猪'); } public function getJiaTian() { return $this->getZaoByGan(0, '甲田几分'); } public function getFenBing() { return $this->getZaoByGan(2, '几人分饼'); } public function getDeJin() { return $this->getZaoByGan(7, '几日得金'); } public function getRenBing() { return $this->getZaoByGan(2, $this->getZaoByZhi(2, '几人几丙')); } public function getRenChu() { return $this->getZaoByGan(3, $this->getZaoByZhi(2, '几人几锄')); } public function getYuan() { return LunarYear::$YUAN[(int)(($this->year + 2696) / 60) % 3] . '元'; } public function getYun() { return LunarYear::$YUN[(int)(($this->year + 2696) / 20) % 9] . '运'; } public function getNineStar() { $index = LunarUtil::getJiaZiIndex($this->getGanZhi()) + 1; $yuan = intval(($this->year + 2696) / 60) % 3; $offset = (62 + $yuan * 3 - $index) % 9; if (0 === $offset) { $offset = 9; } return NineStar::fromIndex($offset - 1); } public function getPositionXi() { return LunarUtil::$POSITION_XI[$this->ganIndex + 1]; } public function getPositionXiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionXi()]; } public function getPositionYangGui() { return LunarUtil::$POSITION_YANG_GUI[$this->ganIndex + 1]; } public function getPositionYangGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionYangGui()]; } public function getPositionYinGui() { return LunarUtil::$POSITION_YIN_GUI[$this->ganIndex + 1]; } public function getPositionYinGuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionYinGui()]; } /** * 获取福神方位,默认流派2 * @return string 福神方位,如艮 */ public function getPositionFu() { return $this->getPositionFuBySect(2); } /** * 获取福神方位 * @param int $sect 流派,可选1或2 * @return string 福神方位,如艮 */ public function getPositionFuBySect($sect) { $fu = 1 == $sect ? LunarUtil::$POSITION_FU : LunarUtil::$POSITION_FU_2; return $fu[$this->ganIndex + 1]; } /** * 获取福神方位描述,默认流派2 * @return string 福神方位描述,如东北 */ public function getPositionFuDesc() { return $this->getPositionFuDescBySect(2); } /** * 获取福神方位描述 * @param int $sect 流派,可选1或2 * @return string 福神方位描述,如东北 */ public function getPositionFuDescBySect($sect) { return LunarUtil::$POSITION_DESC[$this->getPositionFuBySect($sect)]; } public function getPositionCai() { return LunarUtil::$POSITION_CAI[$this->ganIndex + 1]; } public function getPositionCaiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionCai()]; } public function getPositionTaiSui() { return LunarUtil::$POSITION_TAI_SUI_YEAR[$this->zhiIndex]; } public function getPositionTaiSuiDesc() { return LunarUtil::$POSITION_DESC[$this->getPositionTaiSui()]; } public function next($n) { return LunarYear::fromYear($this->year + $n); } } src/NineStar.php 0000644 00000017040 14641217602 0007574 0 ustar 00 index = $index; } public static function fromIndex($index) { return new NineStar($index); } /** * 获取九数 * @return string 九数 */ public function getNumber() { return NineStar::$NUMBER[$this->index]; } /** * 获取七色 * @return string 七色 */ public function getColor() { return NineStar::$COLOR[$this->index]; } /** * 获取五行 * @return string 五行 */ public function getWuXing() { return NineStar::$WU_XING[$this->index]; } /** * 获取方位 * @return string 方位 */ public function getPosition() { return NineStar::$POSITION[$this->index]; } /** * 获取方位描述 * @return string 方位描述 */ public function getPositionDesc() { return LunarUtil::$POSITION_DESC [$this->getPosition()]; } /** * 获取玄空九星名称 * @return string 玄空九星名称 */ public function getNameInXuanKong() { return NineStar::$NAME_XUAN_KONG[$this->index]; } /** * 获取北斗九星名称 * @return string 北斗九星名称 */ public function getNameInBeiDou() { return NineStar::$NAME_BEI_DOU[$this->index]; } /** * 获取奇门九星名称 * @return string 奇门九星名称 */ public function getNameInQiMen() { return NineStar::$NAME_QI_MEN[$this->index]; } /** * 获取太乙九神名称 * @return string 太乙九神名称 */ public function getNameInTaiYi() { return NineStar::$NAME_TAI_YI[$this->index]; } /** * 获取奇门九星吉凶 * @return string 大吉/小吉/大凶/小凶 */ public function getLuckInQiMen() { return NineStar::$LUCK_QI_MEN[$this->index]; } /** * 获取玄空九星吉凶 * @return string 吉/凶 */ public function getLuckInXuanKong() { return NineStar::$LUCK_XUAN_KONG[$this->index]; } /** * 获取奇门九星阴阳 * @return string 阴/阳 */ public function getYinYangInQiMen() { return NineStar::$YIN_YANG_QI_MEN[$this->index]; } /** * 获取太乙九神类型 * @return string 吉神/凶神/安神 */ public function getTypeInTaiYi() { return NineStar::$TYPE_TAI_YI[$this->index]; } /** * 获取八门(奇门遁甲) * @return string 八门 */ public function getBaMenInQiMen() { return NineStar::$BA_MEN_QI_MEN[$this->index]; } /** * 获取太乙九神歌诀 * @return string 太乙九神歌诀 */ public function getSongInTaiYi() { return NineStar::$SONG_TAI_YI[$this->index]; } /** * 获取九星序号,从0开始 * @return int 序号 */ public function getIndex() { return $this->index; } public function toString() { return $this->getNumber() . $this->getColor() . $this->getWuXing() . $this->getNameInBeiDou(); } public function __toString() { return $this->toString(); } public function toFullString() { $s = $this->getNumber(); $s .= $this->getColor(); $s .= $this->getWuXing(); $s .= ' '; $s .= $this->getPosition(); $s .= '('; $s .= $this->getPositionDesc(); $s .= ') '; $s .= $this->getNameInBeiDou(); $s .= ' 玄空['; $s .= $this->getNameInXuanKong(); $s .= ' '; $s .= $this->getLuckInXuanKong(); $s .= '] 奇门['; $s .= $this->getNameInQiMen(); $s .= ' '; $s .= $this->getLuckInQiMen(); if (strlen($this->getBaMenInQiMen()) > 0) { $s .= ' '; $s .= $this->getBaMenInQiMen(); $s .= '门'; } $s .= ' '; $s .= $this->getYinYangInQiMen(); $s .= '] 太乙['; $s .= $this->getNameInTaiYi(); $s .= ' '; $s .= $this->getTypeInTaiYi(); $s .= ']'; return $s; } } src/ShuJiu.php 0000644 00000001523 14641217602 0007257 0 ustar 00 name = $name; $this->index = $index; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getIndex() { return $this->index; } public function setIndex($index) { $this->index = $index; } public function toString() { return $this->name; } public function __toString() { return $this->toString(); } public function toFullString() { return $this->name . '第' . $this->index . '天'; } } src/Solar.php 0000644 00000045264 14641217602 0007142 0 ustar 00 4 && $day < 15) { throw new RuntimeException(sprintf('wrong solar year %d month %d day %d', $year, $month, $day)); } } if ($month < 1 || $month > 12) { throw new RuntimeException(sprintf('wrong month %d', $month)); } if ($day < 1 || $day > 31) { throw new RuntimeException(sprintf('wrong day %d', $day)); } if ($hour < 0 || $hour > 23) { throw new RuntimeException(sprintf('wrong hour %d', $hour)); } if ($minute < 0 || $minute > 59) { throw new RuntimeException(sprintf('wrong minute %d', $minute)); } if ($second < 0 || $second > 59) { throw new RuntimeException(sprintf('wrong second %d', $second)); } $this->year = $year; $this->month = $month; $this->day = $day; $this->hour = $hour; $this->minute = $minute; $this->second = $second; } public static function fromDate($date) { $calendar = DateTime::createFromFormat('Y-n-j G:i:s', $date->format('Y-n-j G:i:s'), $date->getTimezone()); $calendar->setTimezone(new DateTimezone('Asia/Shanghai')); $year = intval($calendar -> format('Y')); $month = intval($calendar -> format('n')); $day = intval($calendar -> format('j')); $hour = intval($calendar -> format('G')); $minute = intval($calendar -> format('i')); $second = intval($calendar -> format('s')); return new Solar($year, $month, $day, $hour, $minute, $second); } public static function fromJulianDay($julianDay) { $d = (int)($julianDay + 0.5); $f = $julianDay + 0.5 - $d; if ($d >= 2299161) { $c = (int)(($d - 1867216.25) / 36524.25); $d += 1 + $c - (int)($c / 4); } $d += 1524; $year = (int)(($d - 122.1) / 365.25); $d -= (int)(365.25 * $year); $month = (int)($d / 30.601); $d -= (int)(30.601 * $month); $day = $d; if ($month > 13) { $month -= 13; $year -= 4715; } else { $month -= 1; $year -= 4716; } $f *= 24; $hour = (int)$f; $f -= $hour; $f *= 60; $minute = (int)$f; $f -= $minute; $f *= 60; $second = intval(round($f)); if ($second > 59) { $second -= 60; $minute++; } if ($minute > 59) { $minute -= 60; $hour++; } if ($hour > 23) { $hour -= 24; $day++; } return self::fromYmdHms($year, $month, $day, $hour, $minute, $second); } /** * 通过八字获取公历列表(晚子时日柱按当天,起始年为1900) * @param string $yearGanZhi 年柱 * @param string $monthGanZhi 月柱 * @param string $dayGanZhi 日柱 * @param string $timeGanZhi 时柱 * @return Solar[] 符合的公历列表 */ public static function fromBaZi($yearGanZhi, $monthGanZhi, $dayGanZhi, $timeGanZhi) { return self::fromBaZiBySect($yearGanZhi, $monthGanZhi, $dayGanZhi, $timeGanZhi, 2); } /** * 通过八字获取公历列表(起始年为1900) * @param string $yearGanZhi 年柱 * @param string $monthGanZhi 月柱 * @param string $dayGanZhi 日柱 * @param string $timeGanZhi 时柱 * @param int $sect 流派,2晚子时日柱按当天,1晚子时日柱按明天 * @return Solar[] 符合的公历列表 */ public static function fromBaZiBySect($yearGanZhi, $monthGanZhi, $dayGanZhi, $timeGanZhi, $sect) { return self::fromBaZiBySectAndBaseYear($yearGanZhi, $monthGanZhi, $dayGanZhi, $timeGanZhi, $sect, 1900); } /** * 通过八字获取公历列表 * @param string $yearGanZhi 年柱 * @param string $monthGanZhi 月柱 * @param string $dayGanZhi 日柱 * @param string $timeGanZhi 时柱 * @param int $sect 流派,2晚子时日柱按当天,1晚子时日柱按明天 * @param int $baseYear 起始年 * @return Solar[] */ public static function fromBaZiBySectAndBaseYear($yearGanZhi, $monthGanZhi, $dayGanZhi, $timeGanZhi, $sect, $baseYear) { $sect = (1 == $sect) ? 1 : 2; $l = array(); // 月地支距寅月的偏移值 $m = LunarUtil::index(substr($monthGanZhi, strlen($monthGanZhi) / 2), LunarUtil::$ZHI, -1) - 2; if ($m < 0) { $m += 12; } // 月天干要一致 if (((LunarUtil::index(substr($yearGanZhi, 0, strlen($yearGanZhi) / 2), LunarUtil::$GAN, -1) + 1) * 2 + $m) % 10 != LunarUtil::index(substr($monthGanZhi, 0, strlen($monthGanZhi) / 2), LunarUtil::$GAN, -1)) { return $l; } // 1年的立春是辛酉,序号57 $y = LunarUtil::getJiaZiIndex($yearGanZhi) - 57; if ($y < 0) { $y += 60; } $y++; // 节令偏移值 $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; // 结束年 $date = new DateTime(); $calendar = DateTime::createFromFormat('Y-n-j G:i:s', $date->format('Y-n-j G:i:s'), $date->getTimezone()); $calendar->setTimezone(new DateTimezone('Asia/Shanghai')); $endYear = intval($calendar -> format('Y')); while ($y <= $endYear) { if ($y >= $startYear) { // 立春为寅月的开始 $jieQiTable = Lunar::fromYmd($y, 1, 1)->getJieQiTable(); // 节令推移,年干支和月干支就都匹配上了 $solarTime = $jieQiTable[Lunar::$JIE_QI_IN_USE[4 + $m]]; if ($solarTime->getYear() >= $baseYear) { // 日干支和节令干支的偏移值 $d = LunarUtil::getJiaZiIndex($dayGanZhi) - LunarUtil::getJiaZiIndex($solarTime->getLunar()->getDayInGanZhiExact2()); if ($d < 0) { $d += 60; } if ($d > 0) { // 从节令推移天数 $solarTime = $solarTime->next($d); } 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; } } } } $y += 60; } return $l; } public static function fromYmd($year, $month, $day) { return new Solar($year, $month, $day, 0, 0, 0); } public static function fromYmdHms($year, $month, $day, $hour, $minute, $second) { return new Solar($year, $month, $day, $hour, $minute, $second); } /** * @return string */ public function toYmd() { return sprintf('%04d-%02d-%02d', $this->year, $this->month, $this->day); } public function toYmdHms() { return $this->toYmd() . ' ' . sprintf('%02d:%02d:%02d', $this->hour, $this->minute, $this->second); } public function toFullString() { $s = $this->toYmdHms(); if ($this->isLeapYear()) { $s .= ' 闰年'; } $s .= ' 星期' . $this->getWeekInChinese(); foreach ($this->getFestivals() as $f) { $s .= ' (' . $f . ')'; } $s .= ' ' . $this->getXingZuo() . '座'; return $s; } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } public function getDay() { return $this->day; } public function getHour() { return $this->hour; } public function getMinute() { return $this->minute; } public function getSecond() { return $this->second; } public function getJulianDay() { $y = $this->year; $m = $this->month; $d = $this->day + (($this->second / 60 + $this->minute) / 60 + $this->hour) / 24; $n = 0; $g = false; if ($y * 372 + $m * 31 + (int)$d >= 588829) { $g = true; } if ($m <= 2) { $m += 12; $y--; } if ($g) { $n = (int)($y / 100); $n = 2 - $n + (int)($n / 4); } return (int)(365.25 * ($y + 4716)) + (int)(30.6001 * ($m + 1)) + $d + $n - 1524.5; } public function getLunar() { return Lunar::fromSolar($this); } public function toString() { return $this->toYmd(); } public function __toString() { return $this->toString(); } public function isLeapYear() { return SolarUtil::isLeapYear($this->year); } public function getWeekInChinese() { return SolarUtil::$WEEK[$this->getWeek()]; } public function getXingZuo() { $index = 11; $y = $this->month * 100 + $this->day; if ($y >= 321 && $y <= 419) { $index = 0; } else if ($y >= 420 && $y <= 520) { $index = 1; } else if ($y >= 521 && $y <= 621) { $index = 2; } else if ($y >= 622 && $y <= 722) { $index = 3; } else if ($y >= 723 && $y <= 822) { $index = 4; } else if ($y >= 823 && $y <= 922) { $index = 5; } else if ($y >= 923 && $y <= 1023) { $index = 6; } else if ($y >= 1024 && $y <= 1122) { $index = 7; } else if ($y >= 1123 && $y <= 1221) { $index = 8; } else if ($y >= 1222 || $y <= 119) { $index = 9; } else if ($y <= 218) { $index = 10; } return SolarUtil::$XING_ZUO[$index]; } public function getFestivals() { $l = array(); $key = $this->month . '-' . $this->day; if (!empty(SolarUtil::$FESTIVAL[$key])) { $l[] = SolarUtil::$FESTIVAL[$key]; } $weeks = intval(ceil($this->day / 7.0)); $week = $this->getWeek(); $key = $this->month . '-' . $weeks . '-' . $week; if (!empty(SolarUtil::$WEEK_FESTIVAL[$key])) { $l[] = SolarUtil::$WEEK_FESTIVAL[$key]; } if ($this->day + 7 > SolarUtil::getDaysOfMonth($this->year, $this->month)) { $key = $this->month . '-0-' . $week; if (!empty(SolarUtil::$WEEK_FESTIVAL[$key])) { $l[] = SolarUtil::$WEEK_FESTIVAL[$key]; } } return $l; } public function getOtherFestivals() { $l = array(); $key = $this->month . '-' . $this->day; if (!empty(SolarUtil::$OTHER_FESTIVAL[$key])) { foreach (SolarUtil::$OTHER_FESTIVAL[$key] as $f) { $l[] = $f; } } return $l; } /** * 公历日期相减,获得相差天数 * @param $solar Solar 公历 * @return int 天数 */ public function subtract($solar) { return SolarUtil::getDaysBetween($solar->getYear(), $solar->getMonth(), $solar->getDay(), $this->getYear(), $this->getMonth(), $this->getDay()); } /** * 公历日期相减,获得相差分钟数 * @param $solar Solar 公历 * @return int 分钟数 */ public function subtractMinute($solar) { $days = $this->subtract($solar); $cm = $this->getHour() * 60 + $this->getMinute(); $sm = $solar->getHour() * 60 + $solar->getMinute(); $m = $cm - $sm; if ($m < 0) { $m += 1440; $days--; } $m += $days * 1440; return $m; } /** * 是否在指定日期之后 * @param $solar Solar 公历 * @return bool */ public function isAfter($solar) { if ($this->year > $solar->getYear()) { return true; } if ($this->year < $solar->getYear()) { return false; } if ($this->month > $solar->getMonth()) { return true; } if ($this->month < $solar->getMonth()) { return false; } if ($this->day > $solar->getDay()) { return true; } if ($this->day < $solar->getDay()) { return false; } if ($this->hour > $solar->getHour()) { return true; } if ($this->hour < $solar->getHour()) { return false; } if ($this->minute > $solar->getMinute()) { return true; } if ($this->minute < $solar->getMinute()) { return false; } return $this->second > $solar->second; } /** * 是否在指定日期之前 * @param $solar Solar 公历 * @return bool */ public function isBefore($solar) { if ($this->year > $solar->getYear()) { return false; } if ($this->year < $solar->getYear()) { return true; } if ($this->month > $solar->getMonth()) { return false; } if ($this->month < $solar->getMonth()) { return true; } if ($this->day > $solar->getDay()) { return false; } if ($this->day < $solar->getDay()) { return true; } if ($this->hour > $solar->getHour()) { return false; } if ($this->hour < $solar->getHour()) { return true; } if ($this->minute > $solar->getMinute()) { return false; } if ($this->minute < $solar->getMinute()) { return true; } return $this->second < $solar->second; } /** * 年推移 * @param $years int 年数 * @return Solar 公历 */ public function nextYear($years) { $y = $this->year + $years; $m = $this->month; $d = $this->day; 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; } } } return self::fromYmdHms($y, $m, $d, $this->hour, $this->minute, $this->second); } /** * 月推移 * @param $months int 月数 * @return Solar 公历 */ public function nextMonth($months) { $month = SolarMonth::fromYm($this->year, $this->month)->next($months); $y = $month->getYear(); $m = $month->getMonth(); $d = $this->day; 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); } /** * 天推移 * @param $days int 天数 * @return Solar 公历 */ public function next($days) { $y = $this->year; $m = $this->month; $d = $this->day; if (1582 == $y && 10 == $m) { if ($d > 4) { $d -= 10; } } if ($days > 0) { $d += $days; $daysInMonth = SolarUtil::getDaysOfMonth($y, $m); while ($d > $daysInMonth) { $d -= $daysInMonth; $m++; if ($m > 12) { $m = 1; $y++; } $daysInMonth = SolarUtil::getDaysOfMonth($y, $m); } } else if ($days < 0) { while ($d + $days <= 0) { $m--; if ($m < 1) { $m = 12; $y--; } $d += SolarUtil::getDaysOfMonth($y, $m); } $d += $days; } if (1582 == $y && 10 == $m) { if ($d > 4) { $d += 10; } } return self::fromYmdHms($y, $m, $d, $this->hour, $this->minute, $this->second); } /** * 小时推移 * @param $hours int 小时数 * @return Solar 公历 */ public function nextHour($hours) { $h = $this->hour + $hours; $n = $h < 0 ? -1 : 1; $hour = (int)abs($h); $days = (int)($hour / 24) * $n; $hour = ($hour % 24) * $n; if ($hour < 0) { $hour += 24; $days--; } $solar = $this->next($days); return self::fromYmdHms($solar->getYear(), $solar->getMonth(), $solar->getDay(), $hour, $solar->getMinute(), $solar->getSecond()); } /** * 获取星期 * @return int 星期,0星期天,1星期一,2星期二,3星期三,4星期四,5星期五,6星期六 */ public function getWeek() { return ((int)($this->getJulianDay() + 0.5) + 7000001) % 7; } /** * 获取往后推几个工作日的公历日期,如果要往前推,则天数用负数 * @param int $days 天数 * @return Solar */ public function nextWorkday($days) { $solar = self::fromYmdHms($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second); if ($days != 0) { $rest = abs($days); $add = $days < 0 ? -1 : 1; while ($rest > 0) { $solar = $solar->next($add); $work = true; $holiday = HolidayUtil::getHolidayByYmd($solar->getYear(), $solar->getMonth(), $solar->getDay()); if (null == $holiday) { $week = $solar->getWeek(); if (0 === $week || 6 === $week) { $work = false; } } else { $work = $holiday->isWork(); } if ($work) { $rest -= 1; } } } return $solar; } /** * 获取薪资比例(感谢 https://gitee.com/smr1987) * @return int 薪资比例:1/2/3 */ public function getSalaryRate() { // 元旦节 if ($this->month == 1 && $this->day == 1) { return 3; } // 劳动节 if ($this->month == 5 && $this->day == 1) { return 3; } // 国庆 if ($this->month == 10 && $this->day >= 1 && $this->day <= 3) { return 3; } $lunar = $this->getLunar(); // 春节 if ($lunar->getMonth() == 1 && $lunar->getDay() >= 1 && $lunar->getDay() <= 3) { return 3; } // 端午 if ($lunar->getMonth() == 5 && $lunar->getDay() == 5) { return 3; } // 中秋 if ($lunar->getMonth() == 8 && $lunar->getDay() == 15) { return 3; } // 清明 if (strcmp('清明', $lunar->getJieQi()) === 0) { return 3; } $holiday = HolidayUtil::getHolidayByYmd($this->year, $this->month, $this->day); if (null != $holiday) { // 法定假日非上班 if (!$holiday->isWork()) { return 2; } } else { // 周末 $week = $this->getWeek(); if ($week == 6 || $week == 0) { return 2; } } // 工作日 return 1; } } src/SolarHalfYear.php 0000644 00000004260 14641217602 0010545 0 ustar 00 year = intval($year); $this->month = intval($month); } public function toString() { return $this->year . '.' . $this->getIndex(); } public function __toString() { return $this->toString(); } public function toFullString() { return $this->year . '年' . (1 === $this->getIndex() ? '上' : '下') . '半年'; } /** * 通过指定年月获取公历半年 * @param int $year 年 * @param int $month 月,1到12 * @return SolarHalfYear */ public static function fromYm($year, $month) { return new SolarHalfYear($year, $month); } /** * 通过指定DateTime获取公历半年 * @param DateTime $date DateTime * @return SolarHalfYear */ public static function fromDate($date) { $solar = Solar::fromDate($date); return new SolarHalfYear($solar->getYear(), $solar->getMonth()); } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } /** * 获取当月是第几半年,从1开始 * @return int */ public function getIndex() { return (int)ceil($this->month / SolarHalfYear::$MONTH_COUNT); } /** * 获取本半年的月份 * @return SolarMonth[] */ public function getMonths() { $l = array(); $index = $this->getIndex() - 1; for ($i = 0; $i < SolarHalfYear::$MONTH_COUNT; $i++) { $l[] = new SolarMonth($this->year, SolarHalfYear::$MONTH_COUNT * $index + $i + 1); } return $l; } /** * 半年推移 * @param int $halfYears 推移的半年数,负数为倒推 * @return SolarHalfYear */ public function next($halfYears) { $month = SolarMonth::fromYm($this->year, $this->month)->next(self::$MONTH_COUNT * $halfYears); return new SolarHalfYear($month->getYear(), $month->getMonth()); } } src/SolarMonth.php 0000644 00000005145 14641217602 0010142 0 ustar 00 year = intval($year); $this->month = intval($month); } public function toString() { return $this->year . '-' . $this->month; } public function __toString() { return $this->toString(); } /** * @return string */ public function toFullString() { return $this->year . '年' . $this->month . '月'; } /** * 通过指定年月获取公历月 * @param int $year 年 * @param int $month 月,1到12 * @return SolarMonth */ public static function fromYm($year, $month) { return new SolarMonth($year, $month); } /** * 通过DateTime获取公历月 * @param DateTime $date DateTime * @return SolarMonth */ public static function fromDate($date) { $solar = Solar::fromDate($date); return new SolarMonth($solar->getYear(), $solar->getMonth()); } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } /** * 获取本月的公历日期列表 * @return Solar[] */ public function getDays() { $l = array(); $d = Solar::fromYmd($this->year, $this->month, 1); $l[] = $d; $days = SolarUtil::getDaysOfMonth($this->year, $this->month); for ($i = 1; $i < $days; $i++) { $l[] = $d->next($i); } return $l; } /** * 获取本月的公历周列表 * @param int $start 星期几作为一周的开始,1234560分别代表星期一至星期天 * @return SolarWeek[] 周列表 */ public function getWeeks($start) { $l = array(); $week = SolarWeek::fromYmd($this->year, $this->month, 1, $start); while (true) { $l[] = $week; $week = $week->next(1, false); $firstDay = $week->getFirstDay(); if ($firstDay->getYear() > $this->year || $firstDay->getMonth() > $this->month) { break; } } return $l; } /** * 获取往后推几个月的公历月,如果要往前推,则月数用负数 * @param int $months 月数 * @return SolarMonth */ public function next($months) { $n = $months < 0 ? -1 : 1; $m = abs($months); $y = $this->year + (int)($m / 12) * $n; $m = $this->month + $m % 12 * $n; if ($m > 12) { $m -= 12; $y++; } else if ($m < 1) { $m += 12; $y--; } return new SolarMonth($y, $m); } } src/SolarSeason.php 0000644 00000004206 14641217602 0010302 0 ustar 00 year = intval($year); $this->month = intval($month); } public function toString() { return $this->year . '.' . $this->getIndex(); } public function __toString() { return $this->toString(); } public function toFullString() { return $this->year . '年' . $this->getIndex() . '季度'; } /** * 通过指定年月获取公历季度 * @param int $year 年 * @param int $month 月,1到12 * @return SolarSeason */ public static function fromYm($year, $month) { return new SolarSeason($year, $month); } /** * 通过指定DateTime获取公历季度 * @param DateTime $date DateTime * @return SolarSeason */ public static function fromDate($date) { $solar = Solar::fromDate($date); return new SolarSeason($solar->getYear(), $solar->getMonth()); } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } /** * 获取当月是第几季度,从1开始 * @return int */ public function getIndex() { return (int)ceil($this->month / SolarSeason::$MONTH_COUNT); } /** * 获取本季度的月份 * @return SolarMonth[] */ public function getMonths() { $l = array(); $index = $this->getIndex() - 1; for ($i = 0; $i < self::$MONTH_COUNT; $i++) { $l[] = new SolarMonth($this->year, self::$MONTH_COUNT * $index + $i + 1); } return $l; } /** * 季度推移 * @param int $seasons 推移的季度数,负数为倒推 * @return SolarSeason */ public function next($seasons) { $month = SolarMonth::fromYm($this->year, $this->month); $month = $month->next(self::$MONTH_COUNT * $seasons); return new SolarSeason($month->getYear(), $month->getMonth()); } } src/SolarWeek.php 0000644 00000014130 14641217602 0007742 0 ustar 00 year = intval($year); $this->month = intval($month); $this->day = intval($day); $this->start = intval($start); } public function toString() { return $this->year . '.' . $this->month . '.' . $this->getIndex(); } public function __toString() { return $this->toString(); } public function toFullString() { return $this->year . '年' . $this->month . '月第' . $this->getIndex() . '周'; } /** * 通过指定年月日获取公历周 * @param int $year 年 * @param int $month 月,1到12 * @param int $day 日,1到31 * @param int $start 星期几作为一周的开始,1234560分别代表星期一至星期天 * @return SolarWeek */ public static function fromYmd($year, $month, $day, $start) { return new SolarWeek($year, $month, $day, $start); } /** * 通过指定DateTime获取公历周 * @param DateTime $date DateTime * @param int $start 星期几作为一周的开始,1234560分别代表星期一至星期天 * @return SolarWeek */ public static function fromDate($date, $start) { $solar = Solar::fromDate($date); return new SolarWeek($solar->getYear(), $solar->getMonth(), $solar->getDay(), $start); } public function getYear() { return $this->year; } public function getMonth() { return $this->month; } public function getDay() { return $this->day; } public function getStart() { return $this->start; } /** * 获取当前日期是在当月第几周 * @return int */ public function getIndex() { $offset = Solar::fromYmd($this->year, $this->month, 1)->getWeek() - $this->start; if ($offset < 0) { $offset += 7; } return (int)ceil(($this->day + $offset) / 7); } /** * 获取当前日期是在当年第几周 * @return int */ public function getIndexInYear() { $offset = Solar::fromYmd($this->year, 1, 1)->getWeek() - $this->start; if ($offset < 0) { $offset += 7; } return (int)ceil((SolarUtil::getDaysInYear($this->year, $this->month, $this->day) + $offset) / 7); } /** * 周推移 * @param int $weeks 推移的周数,负数为倒推 * @param bool $separateMonth 是否按月单独计算 * @return SolarWeek */ public function next($weeks, $separateMonth) { if (0 === $weeks) { return SolarWeek::fromYmd($this->year, $this->month, $this->day, $this->start); } $solar = Solar::fromYmd($this->year, $this->month, $this->day); if ($separateMonth) { $n = $weeks; $week = SolarWeek::fromYmd($solar->getYear(), $solar->getMonth(), $solar->getDay(), $this->start); $month = $this->month; $plus = $n > 0; while (0 !== $n) { $solar = $solar->next($plus ? 7 : -7); $week = SolarWeek::fromYmd($solar->getYear(), $solar->getMonth(), $solar->getDay(), $this->start); $weekMonth = $week->getMonth(); if ($month !== $weekMonth) { $index = $week->getIndex(); if ($plus) { if (1 === $index) { $firstDay = $week->getFirstDay(); $week = SolarWeek::fromYmd($firstDay->getYear(), $firstDay->getMonth(), $firstDay->getDay(), $this->start); $weekMonth = $week->getMonth(); } else { $solar = Solar::fromYmd($week->getYear(), $week->getMonth(), 1); $week = SolarWeek::fromYmd($solar->getYear(), $solar->getMonth(), $solar->getDay(), $this->start); } } else { if (SolarUtil::getWeeksOfMonth($week->getYear(), $week->getMonth(), $week->getStart()) === $index) { $lastDay = $week->getFirstDay()->next(6); $week = SolarWeek::fromYmd($lastDay->getYear(), $lastDay->getMonth(), $lastDay->getDay(), $this->start); $weekMonth = $week->getMonth(); } else { $solar = Solar::fromYmd($week->year, $week->month, SolarUtil::getDaysOfMonth($week->getYear(), $week->getMonth())); $week = SolarWeek::fromYmd($solar->getYear(), $solar->getMonth(), $solar->getDay(), $this->start); } } $month = $weekMonth; } $n -= $plus ? 1 : -1; } return $week; } else { $solar = $solar->next($weeks * 7); return SolarWeek::fromYmd($solar->getYear(), $solar->getMonth(), $solar->getDay(), $this->start); } } /** * 获取本周第一天的公历日期(可能跨月) * @return Solar */ public function getFirstDay() { $solar = Solar::fromYmd($this->year, $this->month, $this->day); $prev = $solar->getWeek() - $this->start; if ($prev < 0) { $prev += 7; } return $solar->next(-$prev); } /** * 获取本周第一天的公历日期(仅限当月) * @return Solar */ public function getFirstDayInMonth() { $days = $this->getDays(); foreach ($days as $day) { if ($this->month === $day->getMonth()) { return $day; } } return null; } /** * 获取本周的公历日期列表(可能跨月) * @return Solar[] */ public function getDays() { $firstDay = $this->getFirstDay(); $l = array(); if (null == $firstDay) { return $l; } $l[] = $firstDay; for ($i = 1; $i < 7; $i++) { $l[] = $firstDay->next($i); } return $l; } /** * 获取本周的公历日期列表(仅限当月) * @return Solar[] */ public function getDaysInMonth() { $days = $this->getDays(); $l = array(); foreach ($days as $day) { if ($this->month !== $day->getMonth()) { continue; } $l[] = $day; } return $l; } } src/SolarYear.php 0000644 00000002731 14641217602 0007753 0 ustar 00 year = intval($year); } public function toString() { return $this->year . ''; } public function __toString() { return $this->toString(); } public function toFullString() { return $this->year . '年'; } /** * 通过指定年获取公历年 * @param int $year 年 * @return SolarYear */ public static function fromYear($year) { return new SolarYear($year); } /** * 通过指定DateTime获取公历年 * @param DateTime $date DateTime * @return SolarYear */ public static function fromDate($date) { return new SolarYear(Solar::fromDate($date)->getYear()); } public function getYear() { return $this->year; } /** * 获取本年的月份 * @return SolarMonth[] */ public function getMonths() { $l = array(); $month = SolarMonth::fromYm($this->year, 1); $l[] = $month; for ($i = 1; $i < SolarYear::$MONTH_COUNT; $i++) { $l[] = $month->next($i); } return $l; } /** * 年推移 * @param int $years 推移的年数,负数为倒推 * @return SolarYear */ public function next($years) { return new SolarYear($this->year + $years); } } src/Tao.php 0000644 00000010325 14641217602 0006573 0 ustar 00 lunar = $lunar; } public static function fromLunar($lunar) { return new Tao($lunar); } public static function fromYmdHms($year, $month, $day, $hour, $minute, $second) { return Tao::fromLunar(Lunar::fromYmdHms($year + Tao::$BIRTH_YEAR, $month, $day, $hour, $minute, $second)); } public static function fromYmd($year, $month, $day) { return Tao::fromYmdHms($year, $month, $day, 0, 0, 0); } public function getLunar() { return $this->lunar; } public function getYear() { return $this->lunar->getYear() - Tao::$BIRTH_YEAR; } public function getMonth() { return $this->lunar->getMonth(); } public function getDay() { return $this->lunar->getDay(); } public function getYearInChinese() { $y = $this->getYear() . ''; $s = ''; for ($i = 0, $j = strlen($y); $i < $j; $i++) { $s .= LunarUtil::$NUMBER[ord(substr($y, $i, 1)) - 48]; } return $s; } public function getMonthInChinese() { return $this->lunar->getMonthInChinese(); } public function getDayInChinese() { return $this->lunar->getDayInChinese(); } /** * 获取节日 * * @return TaoFestival[] 节日列表 */ public function getFestivals() { $l = TaoUtil::getFestivals($this->getMonth() . '-' . $this->getDay()); $jq = $this->lunar->getJieQi(); if (strcmp('冬至', $jq) === 0) { $l[] = new TaoFestival('元始天尊圣诞'); } else if (strcmp('夏至', $jq) === 0) { $l[] = new TaoFestival('灵宝天尊圣诞'); } // 八节日 if (!empty(TaoUtil::$BA_JIE[$jq])) { $l[] = new TaoFestival(TaoUtil::$BA_JIE[$jq]); } // 八会日 $gz = $this->lunar->getDayInGanZhi(); if (!empty(TaoUtil::$BA_HUI[$gz])) { $l[] = new TaoFestival(TaoUtil::$BA_HUI[$gz]); } return $l; } private function isDayIn($days) { $md = $this->getMonth() . '-' . $this->getDay(); foreach ($days as $d) { if (strcmp($md, $d) === 0) { return true; } } return false; } public function isDaySanHui() { return $this->isDayIn(TaoUtil::$SAN_HUI); } public function isDaySanYuan() { return $this->isDayIn(TaoUtil::$SAN_YUAN); } public function isDayWuLa() { return $this->isDayIn(TaoUtil::$WU_LA); } public function isDayBaJie() { return !empty(TaoUtil::$BA_JIE[$this->lunar->getJieQi()]); } public function isDayBaHui() { return !empty(TaoUtil::$BA_HUI[$this->lunar->getDayInGanZhi()]); } public function isDayMingWu() { return strcmp('戊', $this->lunar->getDayGan()) == 0; } public function isDayAnWu() { return strcmp($this->lunar->getDayZhi(), TaoUtil::$AN_WU[abs($this->getMonth()) - 1]) === 0; } public function isDayWu() { return $this->isDayMingWu() || $this->isDayAnWu(); } public function isDayTianShe() { $ret = false; $mz = $this->lunar->getMonthZhi(); $dgz = $this->lunar->getDayInGanZhi(); if (strpos('寅卯辰', $mz) !== false) { if ('戊寅' === $dgz) { $ret = true; } } else if (strpos('巳午未', $mz) !== false) { if ('甲午' === $dgz) { $ret = true; } } else if (strpos('申酉戌', $mz) !== false) { if ('戊申' === $dgz) { $ret = true; } } else if (strpos('亥子丑', $mz) !== false) { if ('甲子' === $dgz) { $ret = true; } } return $ret; } public function toString() { return sprintf('%s年%s月%s', $this->getYearInChinese(), $this->getMonthInChinese(), $this->getDayInChinese()); } public function __toString() { return $this->toString(); } public function toFullString() { return sprintf('道歷%s年,天運%s年,%s月,%s日。%s月%s日,%s時。', $this->getYearInChinese(), $this->lunar->getYearInGanZhi(), $this->lunar->getMonthInGanZhi(), $this->lunar->getDayInGanZhi(), $this->getMonthInChinese(), $this->getDayInChinese(), $this->lunar->getTimeZhi()); } } src/TaoFestival.php 0000644 00000001326 14641217602 0010272 0 ustar 00 name = $name; $this->remark = null == $remark ? '' : $remark; } public function getName() { return $this->name; } public function getRemark() { return $this->remark; } public function toString() { return $this->name; } public function toFullString() { $s = $this->name; if (null != $this->remark && strlen($this->remark) > 0) { $s .= '[' . $this->remark . ']'; } return $s; } public function __toString() { return $this->toString(); } } src/XiaoYun.php 0000644 00000004523 14641217602 0007447 0 ustar 00 daYun = $daYun; $this->lunar = $daYun->getLunar(); $this->index = $index; $this->year = $daYun->getStartYear() + $index; $this->age = $daYun->getStartAge() + $index; $this->forward = $forward; } /** * 获取序数 * @return int */ public function getIndex() { return $this->index; } /** * 获取大运 * @return DaYun */ public function getDaYun() { return $this->daYun; } /** * 获取年 * @return int */ public function getYear() { return $this->year; } /** * 获取年龄 * @return int */ public function getAge() { return $this->age; } /** * 获取农历 * @return Lunar */ public function getLunar() { return $this->lunar; } /** * 是否顺推 * @return bool */ public function isForward() { return $this->forward; } /** * 获取干支 * @return string */ public function getGanZhi() { $offset = LunarUtil::getJiaZiIndex($this->lunar->getTimeInGanZhi()); $add = $this->index + 1; if ($this->daYun->getIndex() > 0) { $add += $this->daYun->getStartAge() - 1; } $offset += $this->forward ? $add : -$add; $size = count(LunarUtil::$JIA_ZI); while ($offset < 0) { $offset += $size; } $offset %= $size; return LunarUtil::$JIA_ZI[$offset]; } /** * 获取所在旬 * @return string 旬 */ public function getXun() { return LunarUtil::getXun($this->getGanZhi()); } /** * 获取旬空(空亡) * @return string 旬空(空亡) */ public function getXunKong() { return LunarUtil::getXunKong($this->getGanZhi()); } } src/Yun.php 0000644 00000010205 14641217602 0006620 0 ustar 00 lunar = $eightChar->getLunar(); $this->gender = $gender; // 阳 $yang = 0 == $this->lunar->getYearGanIndexExact() % 2; // 男 $man = 1 == $gender; $this->forward = ($yang && $man) || (!$yang && !$man); $this->computeStart($sect); } private function computeStart($sect) { // 上节 $prev = $this->lunar->getPrevJie(); // 下节 $next = $this->lunar->getNextJie(); // 出生日期 $current = $this->lunar->getSolar(); // 阳男阴女顺推,阴男阳女逆推 $start = $this->forward ? $current : $prev->getSolar(); $end = $this->forward ? $next->getSolar() : $current; $hour = 0; if (2 == $sect) { $minutes = $end->subtractMinute($start); $year = (int)($minutes / 4320); $minutes -= $year * 4320; $month = (int)($minutes / 360); $minutes -= $month * 360; $day = (int)($minutes / 12); $minutes -= $day * 12; $hour = $minutes * 2; } else { $endTimeZhiIndex = ($end->getHour() == 23) ? 11 : LunarUtil::getTimeZhiIndex(substr($end->toYmdHms(), 11, 5)); $startTimeZhiIndex = ($start->getHour() == 23) ? 11 : LunarUtil::getTimeZhiIndex(substr($start->toYmdHms(), 11, 5)); // 时辰差 $hourDiff = $endTimeZhiIndex - $startTimeZhiIndex; // 天数差 $dayDiff = $end->subtract($start); if ($hourDiff < 0) { $hourDiff += 12; $dayDiff--; } $monthDiff = (int)($hourDiff * 10 / 30); $month = $dayDiff * 4 + $monthDiff; $day = $hourDiff * 10 - $monthDiff * 30; $year = (int)($month / 12); $month = $month - $year * 12; } $this->startYear = $year; $this->startMonth = $month; $this->startDay = $day; $this->startHour = $hour; } /** * 获取性别 * @return int */ public function getGender() { return $this->gender; } /** * 获取起运年数 * @return int */ public function getStartYear() { return $this->startYear; } /** * 获取起运月数 * @return int */ public function getStartMonth() { return $this->startMonth; } /** * 获取起运天数 * @return int */ public function getStartDay() { return $this->startDay; } /** * 获取起运小时数 * @return int */ public function getStartHour() { return $this->startHour; } /** * 是否顺推 * @return bool */ public function isForward() { return $this->forward; } /** * 获取农历日期 * @return Lunar */ public function getLunar() { return $this->lunar; } /** * 获取起运的公历日期 * @return Solar */ public function getStartSolar() { $solar = $this->lunar->getSolar(); $solar = $solar->nextYear($this->startYear); $solar = $solar->nextMonth($this->startMonth); $solar = $solar->next($this->startDay); return $solar->nextHour($this->startHour); } /** * 获取10轮大运 * @return DaYun[] */ public function getDaYun() { return $this->getDaYunBy(10); } /** * 获取大运 * @param $n int 轮数 * @return DaYun[] */ public function getDaYunBy($n) { $l = array(); for ($i = 0; $i < $n; $i++) { $l[] = new DaYun($this, $i); } return $l; } } src/util/FotoUtil.php 0000644 00000040415 14641217602 0010575 0 ustar 00 array('弥勒菩萨圣诞'), '1-6' => array('定光佛圣诞'), '2-8' => array('释迦牟尼佛出家'), '2-15' => array('释迦牟尼佛涅槃'), '2-19' => array('观世音菩萨圣诞'), '2-21' => array('普贤菩萨圣诞'), '3-16' => array('准提菩萨圣诞'), '4-4' => array('文殊菩萨圣诞'), '4-8' => array('释迦牟尼佛圣诞'), '4-15' => array('佛吉祥日'), '4-28' => array('药王菩萨圣诞'), '5-13' => array('伽蓝菩萨圣诞'), '6-3' => array('韦驮菩萨圣诞'), '6-19' => array('观音菩萨成道'), '7-13' => array('大势至菩萨圣诞'), '7-15' => array('佛欢喜日'), '7-24' => array('龙树菩萨圣诞'), '7-30' => array('地藏菩萨圣诞'), '8-15' => array('月光菩萨圣诞'), '8-22' => array('燃灯佛圣诞'), '9-9' => array('摩利支天菩萨圣诞'), '9-19' => array('观世音菩萨出家'), '9-30' => array('药师琉璃光佛圣诞'), '10-5' => array('达摩祖师圣诞'), '10-20' => array('文殊菩萨出家'), '11-17' => array('阿弥陀佛圣诞'), '11-19' => array('日光菩萨圣诞'), '12-8' => array('释迦牟尼佛成道'), '12-23' => array('监斋菩萨圣诞'), '12-29' => array('华严菩萨圣诞') ); /** 获取因果犯忌 * @param string $md 月-日 * @return FotoFestival[] 因果犯忌 */ public static function getFestivals($md) { if (null == self::$FESTIVAL) { self::init(); } $l = array(); if (!empty(self::$FESTIVAL[$md])) { $l = self::$FESTIVAL[$md]; } return $l; } /** * 获取27星宿 * @param int $month 佛历月 * @param int $day 佛历日 * @return string 星宿 */ public static function getXiu($month, $day) { return self::$XIU_27[(self::$XIU_OFFSET[abs($month)-1] + $day - 1) % count(self::$XIU_27)]; } private static function init() { $DJ = '犯者夺纪'; $JS = '犯者减寿'; $SS = '犯者损寿'; $XL = '犯者削禄夺纪'; $JW = '犯者三年内夫妇俱亡'; $Y = new FotoFestival('杨公忌'); $T = new FotoFestival('四天王巡行', '', true); $D = new FotoFestival('斗降', $DJ, true); $S = new FotoFestival('月朔', $DJ, true); $W = new FotoFestival('月望', $DJ, true); $H = new FotoFestival('月晦', $JS, true); $L = new FotoFestival('雷斋日', $JS, true); $J = new FotoFestival('九毒日', '犯者夭亡,奇祸不测'); $R = new FotoFestival('人神在阴', '犯者得病', true, '宜先一日即戒'); $M = new FotoFestival('司命奏事', $JS, true, '如月小,即戒廿九'); $HH = new FotoFestival('月晦', $JS, true, '如月小,即戒廿九'); self::$FESTIVAL = array( '1-1' => array(new FotoFestival('天腊,玉帝校世人神气禄命', $XL), $S), '1-3' => array(new FotoFestival('万神都会', $DJ), $D), '1-5' => array(new FotoFestival('五虚忌')), '1-6' => array(new FotoFestival('六耗忌'), $L), '1-7' => array(new FotoFestival('上会日', $SS)), '1-8' => array(new FotoFestival('五殿阎罗天子诞', $DJ), $T), '1-9' => array(new FotoFestival('玉皇上帝诞', $DJ)), '1-13' => array($Y), '1-14' => array(new FotoFestival('三元降', $JS), $T), '1-15' => array(new FotoFestival('三元降', $JS), new FotoFestival('上元神会', $DJ), $W, $T), '1-16' => array(new FotoFestival('三元降', $JS)), '1-19' => array(new FotoFestival('长春真人诞')), '1-23' => array(new FotoFestival('三尸神奏事'), $T), '1-25' => array($H, new FotoFestival('天地仓开日', '犯者损寿,子带疾')), '1-27' => array($D), '1-28' => array($R), '1-29' => array($T), '1-30' => array($HH, $M, $T), '2-1' => array(new FotoFestival('一殿秦广王诞', $DJ), $S), '2-2' => array(new FotoFestival('万神都会', $DJ), new FotoFestival('福德土地正神诞', '犯者得祸')), '2-3' => array(new FotoFestival('文昌帝君诞', $XL), $D), '2-6' => array(new FotoFestival('东华帝君诞'), $L), '2-8' => array(new FotoFestival('释迦牟尼佛出家', $DJ), new FotoFestival('三殿宋帝王诞', $DJ), new FotoFestival('张大帝诞', $DJ), $T), '2-11' => array($Y), '2-14' => array($T), '2-15' => array(new FotoFestival('释迦牟尼佛涅槃', $XL), new FotoFestival('太上老君诞', $XL), new FotoFestival('月望', $XL, true), $T), '2-17' => array(new FotoFestival('东方杜将军诞')), '2-18' => array(new FotoFestival('四殿五官王诞', $XL), new FotoFestival('至圣先师孔子讳辰', $XL)), '2-19' => array(new FotoFestival('观音大士诞', $DJ)), '2-21' => array(new FotoFestival('普贤菩萨诞')), '2-23' => array($T), '2-25' => array($H), '2-27' => array($D), '2-28' => array($R), '2-29' => array($T), '2-30' => array($HH, $M, $T), '3-1' => array(new FotoFestival('二殿楚江王诞', $DJ), $S), '3-3' => array(new FotoFestival('玄天上帝诞', $DJ), $D), '3-6' => array($L), '3-8' => array(new FotoFestival('六殿卞城王诞', $DJ), $T), '3-9' => array(new FotoFestival('牛鬼神出', '犯者产恶胎'), $Y), '3-12' => array(new FotoFestival('中央五道诞')), '3-14' => array($T), '3-15' => array(new FotoFestival('昊天上帝诞', $DJ), new FotoFestival('玄坛诞', $DJ), $W, $T), '3-16' => array(new FotoFestival('准提菩萨诞', $DJ)), '3-19' => array(new FotoFestival('中岳大帝诞'), new FotoFestival('后土娘娘诞'), new FotoFestival('三茅降')), '3-20' => array(new FotoFestival('天地仓开日', $SS), new FotoFestival('子孙娘娘诞')), '3-23' => array($T), '3-25' => array($H), '3-27' => array(new FotoFestival('七殿泰山王诞'), $D), '3-28' => array($R, new FotoFestival('苍颉至圣先师诞', $XL), new FotoFestival('东岳大帝诞')), '3-29' => array($T), '3-30' => array($HH, $M, $T), '4-1' => array(new FotoFestival('八殿都市王诞', $DJ), $S), '4-3' => array($D), '4-4' => array(new FotoFestival('万神善会', '犯者失瘼夭胎'), new FotoFestival('文殊菩萨诞')), '4-6' => array($L), '4-7' => array(new FotoFestival('南斗、北斗、西斗同降', $JS), $Y), '4-8' => array(new FotoFestival('释迦牟尼佛诞', $DJ), new FotoFestival('万神善会', '犯者失瘼夭胎'), new FotoFestival('善恶童子降', '犯者血死'), new FotoFestival('九殿平等王诞'), $T), '4-14' => array(new FotoFestival('纯阳祖师诞', $JS), $T), '4-15' => array($W, new FotoFestival('钟离祖师诞'), $T), '4-16' => array(new FotoFestival('天地仓开日', $SS)), '4-17' => array(new FotoFestival('十殿转轮王诞', $DJ)), '4-18' => array(new FotoFestival('天地仓开日', $SS), new FotoFestival('紫徽大帝诞', $SS)), '4-20' => array(new FotoFestival('眼光圣母诞')), '4-23' => array($T), '4-25' => array($H), '4-27' => array($D), '4-28' => array($R), '4-29' => array($T), '4-30' => array($HH, $M, $T), '5-1' => array(new FotoFestival('南极长生大帝诞', $DJ), $S), '5-3' => array($D), '5-5' => array(new FotoFestival('地腊', $XL), new FotoFestival('五帝校定生人官爵', $XL), $J, $Y), '5-6' => array($J, $L), '5-7' => array($J), '5-8' => array(new FotoFestival('南方五道诞'), $T), '5-11' => array(new FotoFestival('天地仓开日', $SS), new FotoFestival('天下都城隍诞')), '5-12' => array(new FotoFestival('炳灵公诞')), '5-13' => array(new FotoFestival('关圣降', $XL)), '5-14' => array(new FotoFestival('夜子时为天地交泰', $JW), $T), '5-15' => array($W, $J, $T), '5-16' => array(new FotoFestival('九毒日', $JW), new FotoFestival('天地元气造化万物之辰', $JW)), '5-17' => array($J), '5-18' => array(new FotoFestival('张天师诞')), '5-22' => array(new FotoFestival('孝娥神诞', $DJ)), '5-23' => array($T), '5-25' => array($J, $H), '5-26' => array($J), '5-27' => array($J, $D), '5-28' => array($R), '5-29' => array($T), '5-30' => array($HH, $M, $T), '6-1' => array($S), '6-3' => array(new FotoFestival('韦驮菩萨圣诞'), $D, $Y), '6-5' => array(new FotoFestival('南赡部洲转大轮', $SS)), '6-6' => array(new FotoFestival('天地仓开日', $SS), $L), '6-8' => array($T), '6-10' => array(new FotoFestival('金粟如来诞')), '6-14' => array($T), '6-15' => array($W, $T), '6-19' => array(new FotoFestival('观世音菩萨成道', $DJ)), '6-23' => array(new FotoFestival('南方火神诞', '犯者遭回禄'), $T), '6-24' => array(new FotoFestival('雷祖诞', $XL), new FotoFestival('关帝诞', $XL)), '6-25' => array($H), '6-27' => array($D), '6-28' => array($R), '6-29' => array($T), '6-30' => array($HH, $M, $T), '7-1' => array($S, $Y), '7-3' => array($D), '7-5' => array(new FotoFestival('中会日', $SS, false, '一作初七')), '7-6' => array($L), '7-7' => array(new FotoFestival('道德腊', $XL), new FotoFestival('五帝校生人善恶', $XL), new FotoFestival('魁星诞', $XL)), '7-8' => array($T), '7-10' => array(new FotoFestival('阴毒日', '', false, '大忌')), '7-12' => array(new FotoFestival('长真谭真人诞')), '7-13' => array(new FotoFestival('大势至菩萨诞', $JS)), '7-14' => array(new FotoFestival('三元降', $JS), $T), '7-15' => array($W, new FotoFestival('三元降', $DJ), new FotoFestival('地官校籍', $DJ), $T), '7-16' => array(new FotoFestival('三元降', $JS)), '7-18' => array(new FotoFestival('西王母诞', $DJ)), '7-19' => array(new FotoFestival('太岁诞', $DJ)), '7-22' => array(new FotoFestival('增福财神诞', $XL)), '7-23' => array($T), '7-25' => array($H), '7-27' => array($D), '7-28' => array($R), '7-29' => array($Y, $T), '7-30' => array(new FotoFestival('地藏菩萨诞', $DJ), $HH, $M, $T), '8-1' => array($S, new FotoFestival('许真君诞')), '8-3' => array($D, new FotoFestival('北斗诞', $XL), new FotoFestival('司命灶君诞', '犯者遭回禄')), '8-5' => array(new FotoFestival('雷声大帝诞', $DJ)), '8-6' => array($L), '8-8' => array($T), '8-10' => array(new FotoFestival('北斗大帝诞')), '8-12' => array(new FotoFestival('西方五道诞')), '8-14' => array($T), '8-15' => array($W, new FotoFestival('太明朝元', '犯者暴亡', false, '宜焚香守夜'), $T), '8-16' => array(new FotoFestival('天曹掠刷真君降', '犯者贫夭')), '8-18' => array(new FotoFestival('天人兴福之辰', '', false, '宜斋戒,存想吉事')), '8-23' => array(new FotoFestival('汉恒候张显王诞'), $T), '8-24' => array(new FotoFestival('灶君夫人诞')), '8-25' => array($H), '8-27' => array($D, new FotoFestival('至圣先师孔子诞', $XL), $Y), '8-28' => array($R, new FotoFestival('四天会事')), '8-29' => array($T), '8-30' => array(new FotoFestival('诸神考校', '犯者夺算'), $HH, $M, $T), '9-1' => array($S, new FotoFestival('南斗诞', $XL), new FotoFestival('北斗九星降世', $DJ, false, '此九日俱宜斋戒')), '9-3' => array($D, new FotoFestival('五瘟神诞')), '9-6' => array($L), '9-8' => array($T), '9-9' => array(new FotoFestival('斗母诞', $XL), new FotoFestival('酆都大帝诞'), new FotoFestival('玄天上帝飞升')), '9-10' => array(new FotoFestival('斗母降', $DJ)), '9-11' => array(new FotoFestival('宜戒')), '9-13' => array(new FotoFestival('孟婆尊神诞')), '9-14' => array($T), '9-15' => array($W, $T), '9-17' => array(new FotoFestival('金龙四大王诞', '犯者遭水厄')), '9-19' => array(new FotoFestival('日宫月宫会合', $JS), new FotoFestival('观世音菩萨诞', $JS)), '9-23' => array($T), '9-25' => array($H, $Y), '9-27' => array($D), '9-28' => array($R), '9-29' => array($T), '9-30' => array(new FotoFestival('药师琉璃光佛诞', '犯者危疾'), $HH, $M, $T), '10-1' => array($S, new FotoFestival('民岁腊', $DJ), new FotoFestival('四天王降', '犯者一年内死')), '10-3' => array($D, new FotoFestival('三茅诞')), '10-5' => array(new FotoFestival('下会日', $JS), new FotoFestival('达摩祖师诞', $JS)), '10-6' => array($L, new FotoFestival('天曹考察', $DJ)), '10-8' => array(new FotoFestival('佛涅槃日', '', false, '大忌色欲'), $T), '10-10' => array(new FotoFestival('四天王降', '犯者一年内死')), '10-11' => array(new FotoFestival('宜戒')), '10-14' => array(new FotoFestival('三元降', $JS), $T), '10-15' => array($W, new FotoFestival('三元降', $DJ), new FotoFestival('下元水府校籍', $DJ), $T), '10-16' => array(new FotoFestival('三元降', $JS), $T), '10-23' => array($Y, $T), '10-25' => array($H), '10-27' => array($D, new FotoFestival('北极紫徽大帝降')), '10-28' => array($R), '10-29' => array($T), '10-30' => array($HH, $M, $T), '11-1' => array($S), '11-3' => array($D), '11-4' => array(new FotoFestival('至圣先师孔子诞', $XL)), '11-6' => array(new FotoFestival('西岳大帝诞')), '11-8' => array($T), '11-11' => array(new FotoFestival('天地仓开日', $DJ), new FotoFestival('太乙救苦天尊诞', $DJ)), '11-14' => array($T), '11-15' => array(new FotoFestival('月望', '上半夜犯男死 下半夜犯女死'), new FotoFestival('四天王巡行', '上半夜犯男死 下半夜犯女死')), '11-17' => array(new FotoFestival('阿弥陀佛诞')), '11-19' => array(new FotoFestival('太阳日宫诞', '犯者得奇祸')), '11-21' => array($Y), '11-23' => array(new FotoFestival('张仙诞', '犯者绝嗣'), $T), '11-25' => array(new FotoFestival('掠刷大夫降', '犯者遭大凶'), $H), '11-26' => array(new FotoFestival('北方五道诞')), '11-27' => array($D), '11-28' => array($R), '11-29' => array($T), '11-30' => array($HH, $M, $T), '12-1' => array($S), '12-3' => array($D), '12-6' => array(new FotoFestival('天地仓开日', $JS), $L), '12-7' => array(new FotoFestival('掠刷大夫降', '犯者得恶疾')), '12-8' => array(new FotoFestival('王侯腊', $DJ), new FotoFestival('释迦如来成佛之辰'), $T, new FotoFestival('初旬内戊日,亦名王侯腊', $DJ)), '12-12' => array(new FotoFestival('太素三元君朝真')), '12-14' => array($T), '12-15' => array($W, $T), '12-16' => array(new FotoFestival('南岳大帝诞')), '12-19' => array($Y), '12-20' => array(new FotoFestival('天地交道', '犯者促寿')), '12-21' => array(new FotoFestival('天猷上帝诞')), '12-23' => array(new FotoFestival('五岳诞降'), $T), '12-24' => array(new FotoFestival('司今朝天奏人善恶', '犯者得大祸')), '12-25' => array(new FotoFestival('三清玉帝同降,考察善恶', '犯者得奇祸'), $H), '12-27' => array($D), '12-28' => array($R), '12-29' => array(new FotoFestival('华严菩萨诞'), $T), '12-30' => array(new FotoFestival('诸神下降,察访善恶', '犯者男女俱亡')) ); } } src/util/HolidayUtil.php 0000644 00000051273 14641217602 0011263 0 ustar 00 0) { $right = substr($right, $n); } while ((strpos($right, $key) !== 0) && strlen($right) >= self::$SIZE) { $right = substr($right, self::$SIZE); } return $right; } private static function findBackward($key) { $start = strrpos(self::$DATA, $key); if (!$start) { return null; } $left = substr(self::$DATA, 0, $start + strlen($key)); $size = strlen($left); $n = $size % self::$SIZE; if ($n > 0) { $left = substr($left, 0, $size - $n); } $size = strlen($left); while ((substr_compare($left, $key, -strlen($key)) !== 0) && $size >= self::$SIZE) { $left = substr($left, 0, $size - self::$SIZE); $size = strlen($left); } return $left; } private static function findHolidaysForward($key) { $l = array(); $s = self::findForward($key); if (null == $s) { return $l; } while (strpos($s, $key) === 0) { $l[] = self::buildHolidayForward($s); $s = substr($s, self::$SIZE); } return $l; } private static function findHolidaysBackward($key) { $l = array(); $s = self::findBackward($key); if (null == $s) { return $l; } while (substr_compare($s, $key, -strlen($key)) === 0) { $l[] = self::buildHolidayBackward($s); $s = substr($s, 0, strlen($s) - self::$SIZE); } return array_reverse($l); } /** * 获取指定年月日的节假日信息,如果不存在,返回null * @param int $year 年 * @param int $month 月,1-12 * @param int $day 日,1-31 * @return Holiday|null */ public static function getHolidayByYmd($year, $month, $day) { $l = self::findHolidaysForward($year . self::padding($month) . self::padding($day)); return empty($l) ? null : $l[0]; } /** * 获取指定年月日的节假日信息,如果不存在,返回null * @param string $ymd 年月日 * @return Holiday|null */ public static function getHoliday($ymd) { $l = self::findHolidaysForward(str_replace('-', '', $ymd)); return empty($l) ? null : $l[0]; } /** * 获取指定年月的节假日列表 * @param int $year 年 * @param int $month 月,1-12 * @return Holiday[] */ public static function getHolidaysByYm($year, $month) { return self::findHolidaysForward($year . self::padding($month)); } /** * 获取指定年的节假日列表 * @param int $year 年 * @return Holiday[] */ public static function getHolidaysByYear($year) { return self::findHolidaysForward($year . ''); } /** * 获取指定年月日的节假日列表 * @param string $ymd 年、年月、年月日 * @return Holiday[] 节假日列表 */ public static function getHolidays($ymd) { return self::findHolidaysForward(str_replace('-', '', $ymd)); } /** * 获取指定节日(仅节日当天)的相关节假日列表 * @param int $year 年 * @param int $month 月,1-12 * @param int $day 日,1-31 * @return Holiday[] */ public static function getHolidaysByTargetYmd($year, $month, $day) { return self::findHolidaysBackward($year . self::padding($month) . self::padding($day)); } /** * 获取指定节日(仅节日当天)的相关节假日列表 * @param string $ymd 年月日 * @return Holiday[] */ public static function getHolidaysByTarget($ymd) { return self::findHolidaysBackward(str_replace('-', '', $ymd)); } /** * 修正或追加节假日数据。节假日名称下标从0开始,超过9的,按ASCII码表依次往后排列;调休标识0为上班,否则放假 * @param array $names 用于替换默认的节假日名称列表,传null即可使用默认名称 * @param string $data 需要修正或追加的节假日数据,每18位表示1天依次排列,格式:当天年月日YYYYMMDD(8位)+节假日名称下标(1位)+调休标识(1位)+节假日当天YYYYMMDD(8位)。例:202005023120200501代表2020-05-02为劳动节放假,对应节假日为2020-05-01 */ public static function fix($names, $data) { if (null != $names) { self::$NAMES = $names; } if (null == $data) { return; } $append = ''; while (strlen($data) >= self::$SIZE) { $segment = substr($data, 0, self::$SIZE); $day = substr($segment, 0, 8); $remove = strcmp(self::$TAG_REMOVE, substr($segment, 8, 1)) == 0; $holiday = self::getHoliday($day); if (null == $holiday) { if (!$remove) { $append .= $segment; } } else { $nameIndex = -1; for ($i = 0, $j = count(self::$NAMES); $i < $j; $i++) { if (strcmp(self::$NAMES[$i], $holiday->getName()) == 0) { $nameIndex = $i; break; } } if ($nameIndex > -1) { $old = $day . chr($nameIndex + self::$ZERO) . ($holiday->isWork() ? '0' : '1') . str_replace('-', '', $holiday->getTarget()); self::$DATA = str_replace($old, $remove ? '' : $segment, self::$DATA); } } $data = substr($data, self::$SIZE); } if (strlen($append) > 0) { self::$DATA .= $append; } } } src/util/LunarUtil.php 0000644 00000331412 14641217602 0010747 0 ustar 00 4, '丑' => 2, '寅' => 0, '卯' => 10, '辰' => 8, '巳' => 6, '午' => 4, '未' => 2, '申' => 0, '酉' => 10, '戌' => 8, '亥' => 6 ); public static $TIAN_SHEN_TYPE = array( '青龙' => '黄道', '明堂' => '黄道', '金匮' => '黄道', '天德' => '黄道', '玉堂' => '黄道', '司命' => '黄道', '天刑' => '黑道', '朱雀' => '黑道', '白虎' => '黑道', '天牢' => '黑道', '玄武' => '黑道', '勾陈' => '黑道' ); public static $TIAN_SHEN_TYPE_LUCK = array( '黄道' => '吉', '黑道' => '凶' ); public static $LU = array( '甲' => '寅', '乙' => '卯', '丙' => '巳', '丁' => '午', '戊' => '巳', '己' => '午', '庚' => '申', '辛' => '酉', '壬' => '亥', '癸' => '子', '寅' => '甲', '卯' => '乙', '巳' => '丙,戊', '午' => '丁,己', '申' => '庚', '酉' => '辛', '亥' => '壬', '子' => '癸' ); public static $PENG_ZU_GAN = array('', '甲不开仓财物耗散', '乙不栽植千株不长', '丙不修灶必见灾殃', '丁不剃头头必生疮', '戊不受田田主不祥', '己不破券二比并亡', '庚不经络织机虚张', '辛不合酱主人不尝', '壬不泱水更难提防', '癸不词讼理弱敌强'); public static $PENG_ZU_ZHI = array('', '子不问卜自惹祸殃', '丑不冠带主不还乡', '寅不祭祀神鬼不尝', '卯不穿井水泉不香', '辰不哭泣必主重丧', '巳不远行财物伏藏', '午不苫盖屋主更张', '未不服药毒气入肠', '申不安床鬼祟入房', '酉不会客醉坐颠狂', '戌不吃犬作怪上床', '亥不嫁娶不利新郎'); public static $NUMBER = array('〇', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'); public static $MONTH = array('', '正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'); public static $SEASON = array('', '孟春', '仲春', '季春', '孟夏', '仲夏', '季夏', '孟秋', '仲秋', '季秋', '孟冬', '仲冬', '季冬'); public static $SHENG_XIAO = array('', '鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'); public static $DAY = array('', '初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'); public static $YUE_XIANG = array('', '朔', '既朔', '蛾眉新', '蛾眉新', '蛾眉', '夕', '上弦', '上弦', '九夜', '宵', '宵', '宵', '渐盈凸', '小望', '望', '既望', '立待', '居待', '寝待', '更待', '渐亏凸', '下弦', '下弦', '有明', '有明', '蛾眉残', '蛾眉残', '残', '晓', '晦'); /** * 农历日期对应的节日 * @var array */ public static $FESTIVAL = array( '1-1' => '春节', '1-15' => '元宵节', '2-2' => '龙头节', '5-5' => '端午节', '7-7' => '七夕节', '8-15' => '中秋节', '9-9' => '重阳节', '12-8' => '腊八节' ); /** * 传统节日 * @var array */ public static $OTHER_FESTIVAL = array( '1-4' => array('接神日'), '1-5' => array('隔开日'), '1-7' => array('人日'), '1-8' => array('谷日', '顺星节'), '1-9' => array('天日'), '1-10' => array('地日'), '1-20' => array('天穿节'), '1-25' => array('填仓节'), '1-30' => array('正月晦'), '2-1' => array('中和节'), '2-2' => array('社日节'), '3-3' => array('上巳节'), '5-20' => array('分龙节'), '5-25' => array('会龙节'), '6-6' => array('天贶节'), '6-24' => array('观莲节'), '6-25' => array('五谷母节'), '7-15' => array('中元节'), '7-22' => array('财神节'), '7-29' => array('地藏节'), '8-1' => array('天灸日'), '10-1' => array('寒衣节'), '10-10' => array('十成节'), '10-15' => array('下元节'), '12-7' => array('驱傩日'), '12-16' => array('尾牙'), '12-24' => array('祭灶日') ); public static $XIU = array( '申1' => '毕', '申2' => '翼', '申3' => '箕', '申4' => '奎', '申5' => '鬼', '申6' => '氐', '申0' => '虚', '子1' => '毕', '子2' => '翼', '子3' => '箕', '子4' => '奎', '子5' => '鬼', '子6' => '氐', '子0' => '虚', '辰1' => '毕', '辰2' => '翼', '辰3' => '箕', '辰4' => '奎', '辰5' => '鬼', '辰6' => '氐', '辰0' => '虚', '巳1' => '危', '巳2' => '觜', '巳3' => '轸', '巳4' => '斗', '巳5' => '娄', '巳6' => '柳', '巳0' => '房', '酉1' => '危', '酉2' => '觜', '酉3' => '轸', '酉4' => '斗', '酉5' => '娄', '酉6' => '柳', '酉0' => '房', '丑1' => '危', '丑2' => '觜', '丑3' => '轸', '丑4' => '斗', '丑5' => '娄', '丑6' => '柳', '丑0' => '房', '寅1' => '心', '寅2' => '室', '寅3' => '参', '寅4' => '角', '寅5' => '牛', '寅6' => '胃', '寅0' => '星', '午1' => '心', '午2' => '室', '午3' => '参', '午4' => '角', '午5' => '牛', '午6' => '胃', '午0' => '星', '戌1' => '心', '戌2' => '室', '戌3' => '参', '戌4' => '角', '戌5' => '牛', '戌6' => '胃', '戌0' => '星', '亥1' => '张', '亥2' => '尾', '亥3' => '壁', '亥4' => '井', '亥5' => '亢', '亥6' => '女', '亥0' => '昴', '卯1' => '张', '卯2' => '尾', '卯3' => '壁', '卯4' => '井', '卯5' => '亢', '卯6' => '女', '卯0' => '昴', '未1' => '张', '未2' => '尾', '未3' => '壁', '未4' => '井', '未5' => '亢', '未6' => '女', '未0' => '昴' ); public static $XIU_LUCK = array( '角' => '吉', '亢' => '凶', '氐' => '凶', '房' => '吉', '心' => '凶', '尾' => '吉', '箕' => '吉', '斗' => '吉', '牛' => '凶', '女' => '凶', '虚' => '凶', '危' => '凶', '室' => '吉', '壁' => '吉', '奎' => '凶', '娄' => '吉', '胃' => '吉', '昴' => '凶', '毕' => '吉', '觜' => '凶', '参' => '吉', '井' => '吉', '鬼' => '凶', '柳' => '凶', '星' => '凶', '张' => '吉', '翼' => '凶', '轸' => '吉' ); public static $XIU_SONG = array( '角' => '角星造作主荣昌,外进田财及女郎,嫁娶婚姻出贵子,文人及第见君王,惟有埋葬不可用,三年之后主瘟疫,起工修筑坟基地,堂前立见主人凶。', '亢' => '亢星造作长房当,十日之中主有殃,田地消磨官失职,接运定是虎狼伤,嫁娶婚姻用此日,儿孙新妇守空房,埋葬若还用此日,当时害祸主重伤。', '氐' => '氐星造作主灾凶,费尽田园仓库空,埋葬不可用此日,悬绳吊颈祸重重,若是婚姻离别散,夜招浪子入房中,行船必定遭沉没,更生聋哑子孙穷。', '房' => '房星造作田园进,钱财牛马遍山岗,更招外处田庄宅,荣华富贵福禄康,埋葬若然用此日,高官进职拜君王,嫁娶嫦娥至月殿,三年抱子至朝堂。', '心' => '心星造作大为凶,更遭刑讼狱囚中,忤逆官非宅产退,埋葬卒暴死相从,婚姻若是用此日,子死儿亡泪满胸,三年之内连遭祸,事事教君没始终。', '尾' => '尾星造作主天恩,富贵荣华福禄增,招财进宝兴家宅,和合婚姻贵子孙,埋葬若能依此日,男清女正子孙兴,开门放水招田宅,代代公侯远播名。', '箕' => '箕星造作主高强,岁岁年年大吉昌,埋葬修坟大吉利,田蚕牛马遍山岗,开门放水招田宅,箧满金银谷满仓,福荫高官加禄位,六亲丰禄乐安康。', '斗' => '斗星造作主招财,文武官员位鼎台,田宅家财千万进,坟堂修筑贵富来,开门放水招牛马,旺蚕男女主和谐,遇此吉宿来照护,时支福庆永无灾。', '牛' => '牛星造作主灾危,九横三灾不可推,家宅不安人口退,田蚕不利主人衰,嫁娶婚姻皆自损,金银财谷渐无之,若是开门并放水,牛猪羊马亦伤悲。', '女' => '女星造作损婆娘,兄弟相嫌似虎狼,埋葬生灾逢鬼怪,颠邪疾病主瘟惶,为事遭官财失散,泻利留连不可当,开门放水用此日,全家财散主离乡。', '虚' => '虚星造作主灾殃,男女孤眠不一双,内乱风声无礼节,儿孙媳妇伴人床,开门放水遭灾祸,虎咬蛇伤又卒亡,三三五五连年病,家破人亡不可当。', '危' => '危星不可造高楼,自遭刑吊见血光,三年孩子遭水厄,后生出外永不还,埋葬若还逢此日,周年百日取高堂,三年两载一悲伤,开门放水到官堂。', '室' => '室星修造进田牛,儿孙代代近王侯,家贵荣华天上至,寿如彭祖八千秋,开门放水招财帛,和合婚姻生贵儿,埋葬若能依此日,门庭兴旺福无休。', '壁' => '壁星造作主增财,丝蚕大熟福滔天,奴婢自来人口进,开门放水出英贤,埋葬招财官品进,家中诸事乐陶然,婚姻吉利主贵子,早播名誉著祖鞭。', '奎' => '奎星造作得祯祥,家内荣和大吉昌,若是埋葬阴卒死,当年定主两三伤,看看军令刑伤到,重重官事主瘟惶,开门放水遭灾祸,三年两次损儿郎。', '娄' => '娄星修造起门庭,财旺家和事事兴,外进钱财百日进,一家兄弟播高名,婚姻进益生贵子,玉帛金银箱满盈,放水开门皆吉利,男荣女贵寿康宁。', '胃' => '胃星造作事如何,家贵荣华喜气多,埋葬贵临官禄位,夫妇齐眉永保康,婚姻遇此家富贵,三灾九祸不逢他,从此门前多吉庆,儿孙代代拜金阶。', '昴' => '昴星造作进田牛,埋葬官灾不得休,重丧二日三人死,尽卖田园不记增,开门放水招灾祸,三岁孩儿白了头,婚姻不可逢此日,死别生离是可愁。', '毕' => '毕星造作主光前,买得田园有余钱,埋葬此日添官职,田蚕大熟永丰年,开门放水多吉庆,合家人口得安然,婚姻若得逢此日,生得孩儿福寿全。', '觜' => '觜星造作有徒刑,三年必定主伶丁,埋葬卒死多因此,取定寅年使杀人,三丧不止皆由此,一人药毒二人身,家门田地皆退败,仓库金银化作尘。', '参' => '参星造作旺人家,文星照耀大光华,只因造作田财旺,埋葬招疾哭黄沙,开门放水加官职,房房子孙见田加,婚姻许遁遭刑克,男女朝开幕落花。', '井' => '井星造作旺蚕田,金榜题名第一光,埋葬须防惊卒死,狂颠风疾入黄泉,开门放水招财帛,牛马猪羊旺莫言,贵人田塘来入宅,儿孙兴旺有余钱。', '鬼' => '鬼星起造卒人亡,堂前不见主人郎,埋葬此日官禄至,儿孙代代近君王,开门放水须伤死,嫁娶夫妻不久长,修土筑墙伤产女,手扶双女泪汪汪。', '柳' => '柳星造作主遭官,昼夜偷闭不暂安,埋葬瘟惶多疾病,田园退尽守冬寒,开门放水遭聋瞎,腰驼背曲似弓弯,更有棒刑宜谨慎,妇人随客走盘桓。', '星' => '星宿日好造新房,进职加官近帝王,不可埋葬并放水,凶星临位女人亡,生离死别无心恋,要自归休别嫁郎,孔子九曲殊难度,放水开门天命伤。', '张' => '张星日好造龙轩,年年并见进庄田,埋葬不久升官职,代代为官近帝前,开门放水招财帛,婚姻和合福绵绵,田蚕人满仓库满,百般顺意自安然。', '翼' => '翼星不利架高堂,三年二载见瘟惶,埋葬若还逢此日,子孙必定走他乡,婚姻此日不宜利,归家定是不相当,开门放水家须破,少女恋花贪外郎。', '轸' => '轸星临水造龙宫,代代为官受皇封,富贵荣华增寿禄,库满仓盈自昌隆,埋葬文昌来照助,宅舍安宁不见凶,更有为官沾帝宠,婚姻龙子入龙宫。' ); public static $SHOU = array( '东' => '青龙', '南' => '朱雀', '西' => '白虎', '北' => '玄武' ); public static $CHONG = array('午', '未', '申', '酉', '戌', '亥', '子', '丑', '寅', '卯', '辰', '巳'); public static $CHONG_GAN = array('戊', '己', '庚', '辛', '壬', '癸', '甲', '乙', '丙', '丁'); public static $CHONG_GAN_TIE = array('己', '戊', '辛', '庚', '癸', '壬', '乙', '甲', '丁', '丙'); public static $CHONG_GAN_4 = array('庚', '辛', '壬', '癸', '', '', '甲', '乙', '丙', '丁'); public static $HE_GAN_5 = array('己', '庚', '辛', '壬', '癸', '甲', '乙', '丙', '丁', '戊'); public static $HE_ZHI_6 = array('丑', '子', '亥', '戌', '酉', '申', '未', '午', '巳', '辰', '卯', '寅'); public static $SHA = array( '子' => '南', '丑' => '东', '寅' => '北', '卯' => '西', '辰' => '南', '巳' => '东', '午' => '北', '未' => '西', '申' => '南', '酉' => '东', '戌' => '北', '亥' => '西' ); public static $POSITION_DESC = array( '坎' => '正北', '艮' => '东北', '震' => '正东', '巽' => '东南', '离' => '正南', '坤' => '西南', '兑' => '正西', '乾' => '西北', '中' => '中宫' ); public static $GONG = array( '角' => '东', '井' => '南', '奎' => '西', '斗' => '北', '亢' => '东', '鬼' => '南', '娄' => '西', '牛' => '北', '氐' => '东', '柳' => '南', '胃' => '西', '女' => '北', '房' => '东', '星' => '南', '昴' => '西', '虚' => '北', '心' => '东', '张' => '南', '毕' => '西', '危' => '北', '尾' => '东', '翼' => '南', '觜' => '西', '室' => '北', '箕' => '东', '轸' => '南', '参' => '西', '壁' => '北' ); public static $ZHENG = array( '角' => '木', '井' => '木', '奎' => '木', '斗' => '木', '亢' => '金', '鬼' => '金', '娄' => '金', '牛' => '金', '氐' => '土', '柳' => '土', '胃' => '土', '女' => '土', '房' => '日', '星' => '日', '昴' => '日', '虚' => '日', '心' => '月', '张' => '月', '毕' => '月', '危' => '月', '尾' => '火', '翼' => '火', '觜' => '火', '室' => '火', '箕' => '水', '轸' => '水', '参' => '水', '壁' => '水' ); public static $ANIMAL = array( '角' => '蛟', '斗' => '獬', '奎' => '狼', '井' => '犴', '亢' => '龙', '牛' => '牛', '娄' => '狗', '鬼' => '羊', '女' => '蝠', '氐' => '貉', '胃' => '彘', '柳' => '獐', '房' => '兔', '虚' => '鼠', '昴' => '鸡', '星' => '马', '心' => '狐', '危' => '燕', '毕' => '乌', '张' => '鹿', '尾' => '虎', '室' => '猪', '觜' => '猴', '翼' => '蛇', '箕' => '豹', '壁' => '獝', '参' => '猿', '轸' => '蚓' ); public static $WU_XING_GAN = array( '甲' => '木', '乙' => '木', '丙' => '火', '丁' => '火', '戊' => '土', '己' => '土', '庚' => '金', '辛' => '金', '壬' => '水', '癸' => '水' ); public static $WU_XING_ZHI = array( '寅' => '木', '卯' => '木', '巳' => '火', '午' => '火', '辰' => '土', '丑' => '土', '戌' => '土', '未' => '土', '申' => '金', '酉' => '金', '亥' => '水', '子' => '水' ); public static $NAYIN = array( '甲子' => '海中金', '甲午' => '沙中金', '丙寅' => '炉中火', '丙申' => '山下火', '戊辰' => '大林木', '戊戌' => '平地木', '庚午' => '路旁土', '庚子' => '壁上土', '壬申' => '剑锋金', '壬寅' => '金箔金', '甲戌' => '山头火', '甲辰' => '覆灯火', '丙子' => '涧下水', '丙午' => '天河水', '戊寅' => '城头土', '戊申' => '大驿土', '庚辰' => '白蜡金', '庚戌' => '钗钏金', '壬午' => '杨柳木', '壬子' => '桑柘木', '甲申' => '泉中水', '甲寅' => '大溪水', '丙戌' => '屋上土', '丙辰' => '沙中土', '戊子' => '霹雳火', '戊午' => '天上火', '庚寅' => '松柏木', '庚申' => '石榴木', '壬辰' => '长流水', '壬戌' => '大海水', '乙丑' => '海中金', '乙未' => '沙中金', '丁卯' => '炉中火', '丁酉' => '山下火', '己巳' => '大林木', '己亥' => '平地木', '辛未' => '路旁土', '辛丑' => '壁上土', '癸酉' => '剑锋金', '癸卯' => '金箔金', '乙亥' => '山头火', '乙巳' => '覆灯火', '丁丑' => '涧下水', '丁未' => '天河水', '己卯' => '城头土', '己酉' => '大驿土', '辛巳' => '白蜡金', '辛亥' => '钗钏金', '癸未' => '杨柳木', '癸丑' => '桑柘木', '乙酉' => '泉中水', '乙卯' => '大溪水', '丁亥' => '屋上土', '丁巳' => '沙中土', '己丑' => '霹雳火', '己未' => '天上火', '辛卯' => '松柏木', '辛酉' => '石榴木', '癸巳' => '长流水', '癸亥' => '大海水' ); public static $SHI_SHEN = array( '甲甲' => '比肩', '甲乙' => '劫财', '甲丙' => '食神', '甲丁' => '伤官', '甲戊' => '偏财', '甲己' => '正财', '甲庚' => '七杀', '甲辛' => '正官', '甲壬' => '偏印', '甲癸' => '正印', '乙乙' => '比肩', '乙甲' => '劫财', '乙丁' => '食神', '乙丙' => '伤官', '乙己' => '偏财', '乙戊' => '正财', '乙辛' => '七杀', '乙庚' => '正官', '乙癸' => '偏印', '乙壬' => '正印', '丙丙' => '比肩', '丙丁' => '劫财', '丙戊' => '食神', '丙己' => '伤官', '丙庚' => '偏财', '丙辛' => '正财', '丙壬' => '七杀', '丙癸' => '正官', '丙甲' => '偏印', '丙乙' => '正印', '丁丁' => '比肩', '丁丙' => '劫财', '丁己' => '食神', '丁戊' => '伤官', '丁辛' => '偏财', '丁庚' => '正财', '丁癸' => '七杀', '丁壬' => '正官', '丁乙' => '偏印', '丁甲' => '正印', '戊戊' => '比肩', '戊己' => '劫财', '戊庚' => '食神', '戊辛' => '伤官', '戊壬' => '偏财', '戊癸' => '正财', '戊甲' => '七杀', '戊乙' => '正官', '戊丙' => '偏印', '戊丁' => '正印', '己己' => '比肩', '己戊' => '劫财', '己辛' => '食神', '己庚' => '伤官', '己癸' => '偏财', '己壬' => '正财', '己乙' => '七杀', '己甲' => '正官', '己丁' => '偏印', '己丙' => '正印', '庚庚' => '比肩', '庚辛' => '劫财', '庚壬' => '食神', '庚癸' => '伤官', '庚甲' => '偏财', '庚乙' => '正财', '庚丙' => '七杀', '庚丁' => '正官', '庚戊' => '偏印', '庚己' => '正印', '辛辛' => '比肩', '辛庚' => '劫财', '辛癸' => '食神', '辛壬' => '伤官', '辛乙' => '偏财', '辛甲' => '正财', '辛丁' => '七杀', '辛丙' => '正官', '辛己' => '偏印', '辛戊' => '正印', '壬壬' => '比肩', '壬癸' => '劫财', '壬甲' => '食神', '壬乙' => '伤官', '壬丙' => '偏财', '壬丁' => '正财', '壬戊' => '七杀', '壬己' => '正官', '壬庚' => '偏印', '壬辛' => '正印', '癸癸' => '比肩', '癸壬' => '劫财', '癸乙' => '食神', '癸甲' => '伤官', '癸丁' => '偏财', '癸丙' => '正财', '癸己' => '七杀', '癸戊' => '正官', '癸辛' => '偏印', '癸庚' => '正印' ); public static $ZHI_HIDE_GAN = array( '子' => array('癸'), '丑' => array('己', '癸', '辛'), '寅' => array('甲', '丙', '戊'), '卯' => array('乙'), '辰' => array('戊', '乙', '癸'), '巳' => array('丙', '庚', '戊'), '午' => array('丁', '己'), '未' => array('己', '丁', '乙'), '申' => array('庚', '壬', '戊'), '酉' => array('辛'), '戌' => array('戊', '辛', '丁'), '亥' => array('壬', '甲') ); /** * 获取HH:mm时刻的地支序号(0到11),非法的时刻返回0 * @param string $hm HH:mm时刻 * @return int 地支序号,0到11 */ public static function getTimeZhiIndex($hm) { if (null == $hm) { return 0; } if (strlen($hm) > 5) { $hm = substr($hm, 0, 5); } $x = 1; for ($i = 1; $i < 22; $i += 2) { if (strcmp($hm, ($i < 10 ? '0' : '') . $i . ':00') >= 0 && strcmp($hm, ($i + 1 < 10 ? '0' : '') . ($i + 1) . ':59') <= 0) { return $x; } $x++; } return 0; } /** * 将HH:mm时刻转换为时辰(地支),非法的时刻返回子 * @param string $hm HH:mm时刻 * @return string 时辰(地支),如子 */ public static function convertTime($hm) { return self::$ZHI[self::getTimeZhiIndex($hm) + 1]; } /** * 数字转十六进制 * @param int $n 数字 * @return string 十六进制 */ private static function hex($n) { $s = dechex($n); if (strlen($s) < 2) { $s = '0' . $s; } return strtoupper($s); } public static function index($name, $names, $offset) { for ($i = 0, $j = count($names); $i < $j; $i++) { if (strcmp($names[$i], $name) === 0) { return $i + $offset; } } return -1; } /** * 获取干支对应的甲子序号 * @param string $ganZhi 干支 * @return int 甲子序号 */ public static function getJiaZiIndex($ganZhi) { return self::index($ganZhi, self::$JIA_ZI, 0); } /** * 获取日宜 * @param string $monthGanZhi 月干支 * @param string $dayGanZhi 日干支 * @return string[] 宜 */ public static function getDayYi($monthGanZhi, $dayGanZhi) { $l = array(); $day = self::hex(self::getJiaZiIndex($dayGanZhi)); $month = self::hex(self::getJiaZiIndex($monthGanZhi)); $right = self::$DAY_YI_JI; $index = strpos($right, $day . '='); while ($index > -1) { $right = substr($right, $index + 3); $left = $right; if (strpos($left, '=') !== false) { $left = substr($left, 0, strpos($left, '=') - 2); } $matched = false; $months = substr($left, 0, strpos($left, ':')); for ($i = 0, $j = strlen($months); $i < $j; $i += 2) { $m = substr($months, $i, 2); if ($m == $month) { $matched = true; break; } } if ($matched) { $ys = substr($left, strpos($left, ':') + 1, strlen($left)); $ys = substr($ys, 0, strpos($ys, ',')); for ($i = 0, $j = strlen($ys); $i < $j; $i += 2) { $l[] = self::$YI_JI[hexdec(substr($ys, $i, 2))]; } break; } $index = strpos($right, $day . '='); } if (count($l) < 1) { $l[] = '无'; } return $l; } /** * 获取日忌 * @param string $monthGanZhi 月干支 * @param string $dayGanZhi 日干支 * @return string[] 忌 */ public static function getDayJi($monthGanZhi, $dayGanZhi) { $l = array(); $day = self::hex(self::getJiaZiIndex($dayGanZhi)); $month = self::hex(self::getJiaZiIndex($monthGanZhi)); $right = self::$DAY_YI_JI; $index = strpos($right, $day . '='); while ($index > -1) { $right = substr($right, $index + 3); $left = $right; if (strpos($left, '=') !== false) { $left = substr($left, 0, strpos($left, '=') - 2); } $matched = false; $months = substr($left, 0, strpos($left, ':')); for ($i = 0, $j = strlen($months); $i < $j; $i += 2) { $m = substr($months, $i, 2); if ($m == $month) { $matched = true; break; } } if ($matched) { $ys = substr($left, strpos($left, ',') + 1, strlen($left)); for ($i = 0, $j = strlen($ys); $i < $j; $i += 2) { $l[] = self::$YI_JI[hexdec(substr($ys, $i, 2))]; } break; } $index = strpos($right, $day . '='); } if (count($l) < 1) { $l[] = '无'; } return $l; } /** * 获取日吉神 * @param int $lunarMonth 月 * @param string $dayGanZhi 日干支 * @return string[] 吉神 */ public static function getDayJiShen($lunarMonth, $dayGanZhi) { $l = array(); $day = self::hex(self::getJiaZiIndex($dayGanZhi)); $month = strtoupper(dechex(abs($lunarMonth))); $index = strpos(self::$DAY_SHEN_SHA, $month . $day . '='); if ($index > -1) { $left = substr(self::$DAY_SHEN_SHA, $index + 4); if (strpos($left, '=') !== false) { $left = substr($left, 0, strpos($left, '=') - 3); } $js = substr($left, 0, strpos($left, ',')); for ($i = 0, $j = strlen($js); $i < $j; $i += 2) { $l[] = self::$SHEN_SHA[hexdec(substr($js, $i, 2))]; } } if (count($l) < 1) { $l[] = '无'; } return $l; } /** * 获取日凶煞 * @param int $lunarMonth 月 * @param string $dayGanZhi 日干支 * @return string[] 凶煞 */ public static function getDayXiongSha($lunarMonth, $dayGanZhi) { $l = array(); $day = self::hex(self::getJiaZiIndex($dayGanZhi)); $month = strtoupper(dechex(abs($lunarMonth))); $index = strpos(self::$DAY_SHEN_SHA, $month . $day . '='); if ($index > -1) { $left = substr(self::$DAY_SHEN_SHA, $index + 4); if (strpos($left, '=') !== false) { $left = substr($left, 0, strpos($left, '=') - 3); } $xs = substr($left, strpos($left, ',') + 1, strlen($left)); for ($i = 0, $j = strlen($xs); $i < $j; $i += 2) { $l[] = self::$SHEN_SHA[hexdec(substr($xs, $i, 2))]; } } if (count($l) < 1) { $l[] = '无'; } return $l; } /** * 获取时宜 * @param string $dayGanZhi 日干支 * @param string $timeGanZhi 时辰干支 * @return string[] 宜 */ public static function getTimeYi($dayGanZhi, $timeGanZhi) { $l = array(); $day = self::hex(self::getJiaZiIndex($dayGanZhi)); $time = self::hex(self::getJiaZiIndex($timeGanZhi)); $index = strpos(self::$TIME_YI_JI, $day . $time . '='); if ($index > -1) { $left = substr(self::$TIME_YI_JI, $index + 5); if (strpos($left, '=') !== false) { $left = substr($left, 0, strpos($left, '=') - 4); } $ys = substr($left, 0, strpos($left, ',')); for ($i = 0, $j = strlen($ys); $i < $j; $i += 2) { $l[] = self::$YI_JI[hexdec(substr($ys, $i, 2))]; } } if (count($l) < 1) { $l[] = '无'; } return $l; } /** * 获取时忌 * @param string $dayGanZhi 日干支 * @param string $timeGanZhi 时辰干支 * @return string[] 忌 */ public static function getTimeJi($dayGanZhi, $timeGanZhi) { $l = array(); $day = self::hex(self::getJiaZiIndex($dayGanZhi)); $time = self::hex(self::getJiaZiIndex($timeGanZhi)); $index = strpos(self::$TIME_YI_JI, $day . $time . '='); if ($index > -1) { $left = substr(self::$TIME_YI_JI, $index + 5); if (strpos($left, '=') !== false) { $left = substr($left, 0, strpos($left, '=') - 4); } $js = substr($left, strpos($left, ',') + 1, strlen($left)); for ($i = 0, $j = strlen($js); $i < $j; $i += 2) { $l[] = self::$YI_JI[hexdec(substr($js, $i, 2))]; } } if (count($l) < 1) { $l[] = '无'; } return $l; } /** * 获取干支所在旬下标,0-5 * @param string $ganZhi 干支 * @return int 旬下标,0-5 */ private static function getXunIndex($ganZhi) { $half = strlen($ganZhi) / 2; $gan = substr($ganZhi, 0, $half); $zhi = substr($ganZhi, $half); $ganIndex = 0; $zhiIndex = 0; for ($i = 0, $j = count(self::$GAN); $i < $j; $i++) { if (strcmp(self::$GAN[$i], $gan) === 0) { $ganIndex = $i; break; } } for ($i = 0, $j = count(self::$ZHI); $i < $j; $i++) { if (strcmp(self::$ZHI[$i], $zhi) === 0) { $zhiIndex = $i; break; } } $diff = $ganIndex - $zhiIndex; if ($diff < 0) { $diff += 12; } return $diff / 2; } /** * 获取干支所在旬 * @param string ganZhi 干支 * @return string 旬 */ public static function getXun($ganZhi) { return self::$XUN[self::getXunIndex($ganZhi)]; } /** * 获取干支所在旬对应的旬空(空亡) * @param string ganZhi 干支 * @return string 旬空(空亡) */ public static function getXunKong($ganZhi) { return self::$XUN_KONG[self::getXunIndex($ganZhi)]; } } src/util/ShouXingUtil.php 0000644 00000172032 14641217602 0011433 0 ustar 00 $n2) { $m = $n2; } } $c = 0; for ($j = $n1; $j < $m; $j += 3) { $c += self::$XL0[$j] * cos(self::$XL0[$j + 1] + $t * self::$XL0[$j + 2]); } $v += $c * $tn; } $v /= self::$XL0[0]; $t2 = $t * $t; $v += (-0.0728 - 2.7702 * $t - 1.1019 * $t2 - 0.0996 * $t2 * $t) / self::$SECOND_PER_RAD; return $v; } public static function mLon($t, $n) { $ob = self::$XL1; $obl = count($ob[0]); $tn = 1; $v = 0; $t2 = $t * $t; $t3 = $t2 * $t; $t4 = $t3 * $t; $t5 = $t4 * $t; $tx = $t - 10; $v += (3.81034409 + 8399.684730072 * $t - 3.319e-05 * $t2 + 3.11e-08 * $t3 - 2.033e-10 * $t4) * self::$SECOND_PER_RAD; $v += 5028.792262 * $t + 1.1124406 * $t2 + 0.00007699 * $t3 - 0.000023479 * $t4 - 0.0000000178 * $t5; if ($tx > 0) { $v += -0.866 + 1.43 * $tx + 0.054 * $tx * $tx; } $t2 /= 1e4; $t3 /= 1e8; $t4 /= 1e8; $n *= 6; if ($n < 0) { $n = $obl; } for ($i = 0, $x = count($ob); $i < $x; $i++, $tn *= $t) { $f = $ob[$i]; $l = count($f); $m = (int)($n * $l / $obl + 0.5); if ($i > 0) { $m += 6; } if ($m >= $l) { $m = $l; } for ($j = 0, $c = 0; $j < $m; $j += 6) { $c += $f[$j] * cos($f[$j + 1] + $t * $f[$j + 2] + $t2 * $f[$j + 3] + $t3 * $f[$j + 4] + $t4 * $f[$j + 5]); } $v += $c * $tn; } $v /= self::$SECOND_PER_RAD; return $v; } public static function gxcSunLon($t) { $t2 = $t * $t; $v = -0.043126 + 628.301955 * $t - 0.000002732 * $t2; $e = 0.016708634 - 0.000042037 * $t - 0.0000001267 * $t2; return -20.49552 * (1 + $e * cos($v)) / self::$SECOND_PER_RAD; } public static function ev($t) { $f = 628.307585 * $t; return 628.332 + 21 * sin(1.527 + $f) + 0.44 * sin(1.48 + $f * 2) + 0.129 * sin(5.82 + $f) * $t + 0.00055 * sin(4.21 + $f) * $t * $t; } public static function saLon($t, $n) { return self::eLon($t, $n) + self::nutationLon2($t) + self::gxcSunLon($t) + M_PI; } public static function dtExt($y, $jsd) { $dy = ($y - 1820) / 100; return -20 + $jsd * $dy * $dy; } public static function dtCalc($y) { $size = count(self::$DT_AT); $y0 = self::$DT_AT[$size - 2]; $t0 = self::$DT_AT[$size - 1]; if ($y >= $y0) { $jsd = 31; if ($y > $y0 + 100) { return self::dtExt($y, $jsd); } return self::dtExt($y, $jsd) - (self::dtExt($y0, $jsd) - $t0) * ($y0 + 100 - $y) / 100; } for ($i = 0; $i < $size; $i += 5) { if ($y < self::$DT_AT[$i + 5]) { break; } } $t1 = ($y - self::$DT_AT[$i]) / (self::$DT_AT[$i + 5] - self::$DT_AT[$i]) * 10; $t2 = $t1 * $t1; $t3 = $t2 * $t1; return self::$DT_AT[$i + 1] + self::$DT_AT[$i + 2] * $t1 + self::$DT_AT[$i + 3] * $t2 + self::$DT_AT[$i + 4] * $t3; } public static function dtT($t) { return self::dtCalc($t / 365.2425 + 2000) / self::$SECOND_PER_DAY; } public static function mv($t) { $v = 8399.71 - 914 * sin(0.7848 + 8328.691425 * $t + 0.0001523 * $t * $t); $v -= 179 * sin(2.543 + 15542.7543 * $t) + 160 * sin(0.1874 + 7214.0629 * $t) + 62 * sin(3.14 + 16657.3828 * $t) + 34 * sin(4.827 + 16866.9323 * $t) + 22 * sin(4.9 + 23871.4457 * $t) + 12 * sin(2.59 + 14914.4523 * $t) + 7 * sin(0.23 + 6585.7609 * $t) + 5 * sin(0.9 + 25195.624 * $t) + 5 * sin(2.32 - 7700.3895 * $t) + 5 * sin(3.88 + 8956.9934 * $t) + 5 * sin(0.49 + 7771.3771 * $t); return $v; } public static function saLonT($w) { $v = 628.3319653318; $t = ($w - 1.75347 - M_PI) / $v; $v = self::ev($t); $t += ($w - self::saLon($t, 10)) / $v; $v = self::ev($t); $t += ($w - self::saLon($t, -1)) / $v; return $t; } public static function saLonT2($w) { $v = 628.3319653318; $t = ($w - 1.75347 - M_PI) / $v; $t -= (0.000005297 * $t * $t + 0.0334166 * cos(4.669257 + 628.307585 * $t) + 0.0002061 * cos(2.67823 + 628.307585 * $t) * $t) / $v; $t += ($w - self::eLon($t, 8) - M_PI + (20.5 + 17.2 * sin(2.1824 - 33.75705 * $t)) / self::$SECOND_PER_RAD) / $v; return $t; } public static function msaLon($t, $mn, $sn) { return self::mLon($t, $mn) + (-3.4E-6) - (self::eLon($t, $sn) + self::gxcSunLon($t) + M_PI); } public static function msaLonT($w) { $v = 7771.37714500204; $t = ($w + 1.08472) / $v; $t += ($w - self::msaLon($t, 3, 3)) / $v; $v = self::mv($t) - self::ev($t); $t += ($w - self::msaLon($t, 20, 10)) / $v; $t += ($w - self::msaLon($t, -1, 60)) / $v; return $t; } public static function msaLonT2($w) { $v = 7771.37714500204; $t = ($w + 1.08472) / $v; $t2 = $t * $t; $t -= (-0.00003309 * $t2 + 0.10976 * cos(0.784758 + 8328.6914246 * $t + 0.000152292 * $t2) + 0.02224 * cos(0.18740 + 7214.0628654 * $t - 0.00021848 * $t2) - 0.03342 * cos(4.669257 + 628.307585 * $t)) / $v; $l = self::mLon($t, 20) - (4.8950632 + 628.3319653318 * $t + 0.000005297 * $t * $t + 0.0334166 * cos(4.669257 + 628.307585 * $t) + 0.0002061 * cos(2.67823 + 628.307585 * $t) * $t + 0.000349 * cos(4.6261 + 1256.61517 * $t) - 20.5 / self::$SECOND_PER_RAD); $v = 7771.38 - 914 * sin(0.7848 + 8328.691425 * $t + 0.0001523 * $t * $t) - 179 * sin(2.543 + 15542.7543 * $t) - 160 * sin(0.1874 + 7214.0629 * $t); $t += ($w - $l) / $v; return $t; } public static function qiHigh($w) { $t = self::saLonT2($w) * 36525; $t = $t - self::dtT($t) + self::$ONE_THIRD; $v = (intval($t + 0.5) % 1) * self::$SECOND_PER_DAY; if ($v < 1200 || $v > self::$SECOND_PER_DAY - 1200) { $t = self::saLonT($w) * 36525 - self::dtT($t) + self::$ONE_THIRD; } return $t; } public static function shuoHigh($w) { $t = self::msaLonT2($w) * 36525; $t = $t - self::dtT($t) + self::$ONE_THIRD; $v = (intval($t + 0.5) % 1) * self::$SECOND_PER_DAY; if ($v < 1800 || $v > self::$SECOND_PER_DAY - 1800) { $t = self::msaLont($w) * 36525 - self::dtT($t) + self::$ONE_THIRD; } return $t; } public static function qiLow($w) { $v = 628.3319653318; $t = ($w - 4.895062166) / $v; $t -= (53 * $t * $t + 334116 * cos(4.67 + 628.307585 * $t) + 2061 * cos(2.678 + 628.3076 * $t) * $t) / $v / 10000000; $n = 48950621.66 + 6283319653.318 * $t + 53 * $t * $t + 334166 * cos(4.669257 + 628.307585 * $t) + 3489 * cos(4.6261 + 1256.61517 * $t) + 2060.6 * cos(2.67823 + 628.307585 * $t) * $t - 994 - 834 * sin(2.1824 - 33.75705 * $t); $t -= ($n / 10000000 - $w) / 628.332 + (32 * ($t + 1.8) * ($t + 1.8) - 20) / self::$SECOND_PER_DAY / 36525; return $t * 36525 + self::$ONE_THIRD; } public static function shuoLow($w) { $v = 7771.37714500204; $t = ($w + 1.08472) / $v; $t -= (-0.0000331 * $t * $t + 0.10976 * cos(0.785 + 8328.6914 * $t) + 0.02224 * cos(0.187 + 7214.0629 * $t) - 0.03342 * cos(4.669 + 628.3076 * $t)) / $v + (32 * ($t + 1.8) * ($t + 1.8) - 20) / self::$SECOND_PER_DAY / 36525; return $t * 36525 + self::$ONE_THIRD; } public static function calcShuo($jd) { if (null == self::$SB) { self::$SB = self::decode('EqoFscDcrFpmEsF2DfFideFelFpFfFfFiaipqti1ksttikptikqckstekqttgkqttgkqteksttikptikq2fjstgjqttjkqttgkqtekstfkptikq2tijstgjiFkirFsAeACoFsiDaDiADc1AFbBfgdfikijFifegF1FhaikgFag1E2btaieeibggiffdeigFfqDfaiBkF1kEaikhkigeidhhdiegcFfakF1ggkidbiaedksaFffckekidhhdhdikcikiakicjF1deedFhFccgicdekgiFbiaikcfi1kbFibefgEgFdcFkFeFkdcfkF1kfkcickEiFkDacFiEfbiaejcFfffkhkdgkaiei1ehigikhdFikfckF1dhhdikcfgjikhfjicjicgiehdikcikggcifgiejF1jkieFhegikggcikFegiegkfjebhigikggcikdgkaFkijcfkcikfkcifikiggkaeeigefkcdfcfkhkdgkegieidhijcFfakhfgeidieidiegikhfkfckfcjbdehdikggikgkfkicjicjF1dbidikFiggcifgiejkiegkigcdiegfggcikdbgfgefjF1kfegikggcikdgFkeeijcfkcikfkekcikdgkabhkFikaffcfkhkdgkegbiaekfkiakicjhfgqdq2fkiakgkfkhfkfcjiekgFebicggbedF1jikejbbbiakgbgkacgiejkijjgigfiakggfggcibFifjefjF1kfekdgjcibFeFkijcfkfhkfkeaieigekgbhkfikidfcjeaibgekgdkiffiffkiakF1jhbakgdki1dj1ikfkicjicjieeFkgdkicggkighdF1jfgkgfgbdkicggfggkidFkiekgijkeigfiskiggfaidheigF1jekijcikickiggkidhhdbgcfkFikikhkigeidieFikggikhkffaffijhidhhakgdkhkijF1kiakF1kfheakgdkifiggkigicjiejkieedikgdfcggkigieeiejfgkgkigbgikicggkiaideeijkefjeijikhkiggkiaidheigcikaikffikijgkiahi1hhdikgjfifaakekighie1hiaikggikhkffakicjhiahaikggikhkijF1kfejfeFhidikggiffiggkigicjiekgieeigikggiffiggkidheigkgfjkeigiegikifiggkidhedeijcfkFikikhkiggkidhh1ehigcikaffkhkiggkidhh1hhigikekfiFkFikcidhh1hitcikggikhkfkicjicghiediaikggikhkijbjfejfeFhaikggifikiggkigiejkikgkgieeigikggiffiggkigieeigekijcijikggifikiggkideedeijkefkfckikhkiggkidhh1ehijcikaffkhkiggkidhh1hhigikhkikFikfckcidhh1hiaikgjikhfjicjicgiehdikcikggifikigiejfejkieFhegikggifikiggfghigkfjeijkhigikggifikiggkigieeijcijcikfksikifikiggkidehdeijcfdckikhkiggkhghh1ehijikifffffkhsFngErD1pAfBoDd1BlEtFqA2AqoEpDqElAEsEeB2BmADlDkqBtC1FnEpDqnEmFsFsAFnllBbFmDsDiCtDmAB2BmtCgpEplCpAEiBiEoFqFtEqsDcCnFtADnFlEgdkEgmEtEsCtDmADqFtAFrAtEcCqAE1BoFqC1F1DrFtBmFtAC2ACnFaoCgADcADcCcFfoFtDlAFgmFqBq2bpEoAEmkqnEeCtAE1bAEqgDfFfCrgEcBrACfAAABqAAB1AAClEnFeCtCgAADqDoBmtAAACbFiAAADsEtBqAB2FsDqpFqEmFsCeDtFlCeDtoEpClEqAAFrAFoCgFmFsFqEnAEcCqFeCtFtEnAEeFtAAEkFnErAABbFkADnAAeCtFeAfBoAEpFtAABtFqAApDcCGJ'); } $size = count(self::$SHUO_KB); $d = 0; $pc = 14; $jd += Solar::$J2000; $f1 = self::$SHUO_KB[0] - $pc; $f2 = self::$SHUO_KB[$size - 1] - $pc; $f3 = 2436935; if ($jd < $f1 || $jd >= $f3) { $d = floor(self::shuoHigh(floor(($jd + $pc - 2451551) / 29.5306) * M_PI * 2) + 0.5); } else if ($jd >= $f1 && $jd < $f2) { for ($i = 0; $i < $size; $i += 2) { if ($jd + $pc < self::$SHUO_KB[$i + 2]) { break; } } $d = self::$SHUO_KB[$i] + self::$SHUO_KB[$i + 1] * floor(($jd + $pc - self::$SHUO_KB[$i]) / self::$SHUO_KB[$i + 1]); $d = floor($d + 0.5); if ($d == 1683460) { $d++; } $d -= Solar::$J2000; } else if ($jd >= $f2 && $jd < $f3) { $d = floor(self::shuoLow(floor(($jd + $pc - 2451551) / 29.5306) * M_PI * 2) + 0.5); $from = (int)(($jd - $f2) / 29.5306); $n = substr(self::$SB, $from, 1); if (strcmp('1', $n) == 0) { $d += 1; } elseif (strcmp('2', $n) == 0) { $d -= 1; } } return $d; } public static function calcQi($jd) { if (null == self::$QB) { self::$QB = self::decode('FrcFs22AFsckF2tsDtFqEtF1posFdFgiFseFtmelpsEfhkF2anmelpFlF1ikrotcnEqEq2FfqmcDsrFor22FgFrcgDscFs22FgEeFtE2sfFs22sCoEsaF2tsD1FpeE2eFsssEciFsFnmelpFcFhkF2tcnEqEpFgkrotcnEqrEtFermcDsrE222FgBmcmr22DaEfnaF222sD1FpeForeF2tssEfiFpEoeFssD1iFstEqFppDgFstcnEqEpFg11FscnEqrAoAF2ClAEsDmDtCtBaDlAFbAEpAAAAAD2FgBiBqoBbnBaBoAAAAAAAEgDqAdBqAFrBaBoACdAAf1AACgAAAeBbCamDgEifAE2AABa1C1BgFdiAAACoCeE1ADiEifDaAEqAAFe1AcFbcAAAAAF1iFaAAACpACmFmAAAAAAAACrDaAAADG0'); } $size = count(self::$QI_KB); $d = 0; $pc = 7; $jd += Solar::$J2000; $f1 = self::$QI_KB[0] - $pc; $f2 = self::$QI_KB[$size - 1] - $pc; $f3 = 2436935; if ($jd < $f1 || $jd >= $f3) { $d = floor(self::qiHigh(floor(($jd + $pc - 2451259) / 365.2422 * 24) * M_PI / 12) + 0.5); } else if ($jd >= $f1 && $jd < $f2) { for ($i = 0; $i < $size; $i += 2) { if ($jd + $pc < self::$QI_KB[$i + 2]) { break; } } $d = self::$QI_KB[$i] + self::$QI_KB[$i + 1] * floor(($jd + $pc - self::$QI_KB[$i]) / self::$QI_KB[$i + 1]); $d = floor($d + 0.5); if ($d == 1683460) { $d++; } $d -= Solar::$J2000; } else if ($jd >= $f2 && $jd < $f3) { $d = floor(self::qiLow(floor(($jd + $pc - 2451259) / 365.2422 * 24) * M_PI / 12) + 0.5); $from = (int)(($jd - $f2) / 365.2422 * 24); $n = substr(self::$QB, $from, 1); if (strcmp('1', $n) == 0) { $d += 1; } elseif (strcmp('2', $n) == 0) { $d -= 1; } } return $d; } public static function qiAccurate($w) { $t = self::saLonT($w) * 36525; return $t - self::dtT($t) + self::$ONE_THIRD; } public static function qiAccurate2($jd) { $d = M_PI / 12; $w = floor(($jd + 293) / 365.2422 * 24) * $d; $a = self::qiAccurate($w); if ($a - $jd > 5) { return self::qiAccurate($w - $d); } if ($a - $jd < -5) { return self::qiAccurate($w + $d); } return $a; } } src/util/SolarUtil.php 0000644 00000025443 14641217602 0010752 0 ustar 00 '元旦节', '2-14' => '情人节', '3-8' => '妇女节', '3-12' => '植树节', '3-15' => '消费者权益日', '4-1' => '愚人节', '5-1' => '劳动节', '5-4' => '青年节', '6-1' => '儿童节', '7-1' => '建党节', '8-1' => '建军节', '9-10' => '教师节', '10-1' => '国庆节', '10-31' => '万圣节前夜', '11-1' => '万圣节', '12-24' => '平安夜', '12-25' => '圣诞节' ); /** * 几月第几个星期几对应的节日 * @var array */ public static $WEEK_FESTIVAL = array( '3-0-1' => '全国中小学生安全教育日', '5-2-0' => '母亲节', '6-3-0' => '父亲节', '11-4-4' => '感恩节' ); /** * 日期对应的非正式节日 * @var array */ public static $OTHER_FESTIVAL = array( '1-8' => array('周恩来逝世纪念日'), '1-10' => array('中国人民警察节'), '1-14' => array('日记情人节'), '1-21' => array('列宁逝世纪念日'), '1-26' => array('国际海关日'), '1-27' => array('国际大屠杀纪念日'), '2-2' => array('世界湿地日'), '2-4' => array('世界抗癌日'), '2-7' => array('京汉铁路罢工纪念日'), '2-10' => array('国际气象节'), '2-19' => array('邓小平逝世纪念日'), '2-20' => array('世界社会公正日'), '2-21' => array('国际母语日'), '2-24' => array('第三世界青年日'), '3-1' => array('国际海豹日'), '3-3' => array('世界野生动植物日', '全国爱耳日'), '3-5' => array('周恩来诞辰纪念日', '中国青年志愿者服务日'), '3-6' => array('世界青光眼日'), '3-7' => array('女生节'), '3-12' => array('孙中山逝世纪念日'), '3-14' => array('马克思逝世纪念日', '白色情人节'), '3-17' => array('国际航海日'), '3-18' => array('全国科技人才活动日', '全国爱肝日'), '3-20' => array('国际幸福日'), '3-21' => array('世界森林日', '世界睡眠日', '国际消除种族歧视日'), '3-22' => array('世界水日'), '3-23' => array('世界气象日'), '3-24' => array('世界防治结核病日'), '3-29' => array('中国黄花岗七十二烈士殉难纪念日'), '4-2' => array('国际儿童图书日', '世界自闭症日'), '4-4' => array('国际地雷行动日'), '4-7' => array('世界卫生日'), '4-8' => array('国际珍稀动物保护日'), '4-12' => array('世界航天日'), '4-14' => array('黑色情人节'), '4-15' => array('全民国家安全教育日'), '4-22' => array('世界地球日', '列宁诞辰纪念日'), '4-23' => array('世界读书日'), '4-24' => array('中国航天日'), '4-25' => array('儿童预防接种宣传日'), '4-26' => array('世界知识产权日', '全国疟疾日'), '4-28' => array('世界安全生产与健康日'), '4-30' => array('全国交通安全反思日'), '5-2' => array('世界金枪鱼日'), '5-3' => array('世界新闻自由日'), '5-5' => array('马克思诞辰纪念日'), '5-8' => array('世界红十字日'), '5-11' => array('世界肥胖日'), '5-12' => array('全国防灾减灾日', '护士节'), '5-14' => array('玫瑰情人节'), '5-15' => array('国际家庭日'), '5-19' => array('中国旅游日'), '5-20' => array('网络情人节'), '5-22' => array('国际生物多样性日'), '5-25' => array('525心理健康节'), '5-27' => array('上海解放日'), '5-29' => array('国际维和人员日'), '5-30' => array('中国五卅运动纪念日'), '5-31' => array('世界无烟日'), '6-3' => array('世界自行车日'), '6-5' => array('世界环境日'), '6-6' => array('全国爱眼日'), '6-8' => array('世界海洋日'), '6-11' => array('中国人口日'), '6-14' => array('世界献血日', '亲亲情人节'), '6-17' => array('世界防治荒漠化与干旱日'), '6-20' => array('世界难民日'), '6-21' => array('国际瑜伽日'), '6-25' => array('全国土地日'), '6-26' => array('国际禁毒日', '联合国宪章日'), '7-1' => array('香港回归纪念日'), '7-6' => array('国际接吻日', '朱德逝世纪念日'), '7-7' => array('七七事变纪念日'), '7-11' => array('世界人口日', '中国航海日'), '7-14' => array('银色情人节'), '7-18' => array('曼德拉国际日'), '7-30' => array('国际友谊日'), '8-3' => array('男人节'), '8-5' => array('恩格斯逝世纪念日'), '8-6' => array('国际电影节'), '8-8' => array('全民健身日'), '8-9' => array('国际土著人日'), '8-12' => array('国际青年节'), '8-14' => array('绿色情人节'), '8-19' => array('世界人道主义日', '中国医师节'), '8-22' => array('邓小平诞辰纪念日'), '8-29' => array('全国测绘法宣传日'), '9-3' => array('中国抗日战争胜利纪念日'), '9-5' => array('中华慈善日'), '9-8' => array('世界扫盲日'), '9-9' => array('毛泽东逝世纪念日', '全国拒绝酒驾日'), '9-14' => array('世界清洁地球日', '相片情人节'), '9-15' => array('国际民主日'), '9-16' => array('国际臭氧层保护日'), '9-17' => array('世界骑行日'), '9-18' => array('九一八事变纪念日'), '9-20' => array('全国爱牙日'), '9-21' => array('国际和平日'), '9-27' => array('世界旅游日'), '9-30' => array('中国烈士纪念日'), '10-1' => array('国际老年人日'), '10-2' => array('国际非暴力日'), '10-4' => array('世界动物日'), '10-11' => array('国际女童日'), '10-10' => array('辛亥革命纪念日'), '10-13' => array('国际减轻自然灾害日', '中国少年先锋队诞辰日'), '10-14' => array('葡萄酒情人节'), '10-16' => array('世界粮食日'), '10-17' => array('全国扶贫日'), '10-20' => array('世界统计日'), '10-24' => array('世界发展信息日', '程序员节'), '10-25' => array('抗美援朝纪念日'), '11-5' => array('世界海啸日'), '11-8' => array('记者节'), '11-9' => array('全国消防日'), '11-11' => array('光棍节'), '11-12' => array('孙中山诞辰纪念日'), '11-14' => array('电影情人节'), '11-16' => array('国际宽容日'), '11-17' => array('国际大学生节'), '11-19' => array('世界厕所日'), '11-28' => array('恩格斯诞辰纪念日'), '11-29' => array('国际声援巴勒斯坦人民日'), '12-1' => array('世界艾滋病日'), '12-2' => array('全国交通安全日'), '12-3' => array('世界残疾人日'), '12-4' => array('全国法制宣传日'), '12-5' => array('世界弱能人士日', '国际志愿人员日'), '12-7' => array('国际民航日'), '12-9' => array('世界足球日', '国际反腐败日'), '12-10' => array('世界人权日'), '12-11' => array('国际山岳日'), '12-12' => array('西安事变纪念日'), '12-13' => array('国家公祭日'), '12-14' => array('拥抱情人节'), '12-18' => array('国际移徙者日'), '12-26' => array('毛泽东诞辰纪念日') ); /** * 是否闰年 * @param int $year 年 * @return bool 是否闰年 */ public static function isLeapYear($year) { if ($year < 1600) { return $year % 4 === 0; } return ($year%4 === 0 && $year%100 != 0) || ($year%400 === 0); } /** * 获取某年某月有多少天 * @param int $year 年 * @param int $month 月 * @return int 天数 */ public static function getDaysOfMonth($year, $month) { if (1582 === $year && 10 === $month) { return 21; } $d = self::$DAYS_OF_MONTH[$month - 1]; //公历闰年2月多一天 if ($month === 2 && self::isLeapYear($year)) { $d++; } return $d; } /** * 获取某年有多少天(平年365天,闰年366天) * @param $year int 年 * @return int 天数 */ public static function getDaysOfYear($year) { if (1582 == $year) { return 355; } return self::isLeapYear($year) ? 366 : 365; } /** * 获取某天为当年的第几天 * @param $year int 年 * @param $month int 月 * @param $day int 日 * @return int 第几天 */ public static function getDaysInYear($year, $month, $day) { $days = 0; for ($i = 1; $i < $month; $i++) { $days += self::getDaysOfMonth($year, $i); } $d = $day; if (1582 === $year && 10 === $month) { if ($day >= 15) { $d -= 10; } else if ($day > 4){ throw new RuntimeException(sprintf('wrong solar year %d month %d day %d', $year, $month, $day)); } } $days += $d; return $days; } /** * 获取某年某月有多少周 * @param int $year 年 * @param int $month 月 * @param int $start 星期几作为一周的开始,1234560分别代表星期一至星期天 * @return int 周数 */ public static function getWeeksOfMonth($year, $month, $start) { return (int)ceil((self::getDaysOfMonth($year, $month) + Solar::fromYmd($year, $month, 1)->getWeek() - $start) / count(self::$WEEK)); } /** * 获取两个日期之间相差的天数(如果日期a比日期b小,天数为正,如果日期a比日期b大,天数为负) * @param $ay int 年a * @param $am int 月a * @param $ad int 日a * @param $by int 年b * @param $bm int 月b * @param $bd int 日b * @return int */ public static function getDaysBetween($ay, $am, $ad, $by, $bm, $bd) { if ($ay == $by) { $n = self::getDaysInYear($by, $bm, $bd) - self::getDaysInYear($ay, $am, $ad); } else if ($ay > $by) { $days = self::getDaysOfYear($by) - self::getDaysInYear($by, $bm, $bd); for ($i = $by + 1; $i < $ay; $i++) { $days += self::getDaysOfYear($i); } $days += self::getDaysInYear($ay, $am, $ad); $n = -$days; } else { $days = self::getDaysOfYear($ay) - self::getDaysInYear($ay, $am, $ad); for ($i = $ay + 1; $i < $by; $i++) { $days += self::getDaysOfYear($i); } $days += self::getDaysInYear($by, $bm, $bd); $n = $days; } return $n; } } src/util/TaoUtil.php 0000644 00000022724 14641217602 0010414 0 ustar 00 '天会', '壬午' => '地会', '壬子' => '人会', '庚午' => '日会', '庚申' => '月会', '辛酉' => '星辰会', '甲辰' => '五行会', '甲戌' => '四时会' ); /** * 八节日 * @var array */ public static $BA_JIE = array( '立春' => '东北方度仙上圣天尊同梵炁始青天君下降', '春分' => '东方玉宝星上天尊同青帝九炁天君下降', '立夏' => '东南方好生度命天尊同梵炁始丹天君下降', '夏至' => '南方玄真万福天尊同赤帝三炁天君下降', '立秋' => '西南方太灵虚皇天尊同梵炁始素天君下降', '秋分' => '西方太妙至极天尊同白帝七炁天君下降', '立冬' => '西北方无量太华天尊同梵炁始玄天君下降', '冬至' => '北方玄上玉宸天尊同黑帝五炁天君下降' ); /** * 节日 * @var array */ private static $FESTIVAL; /** 获取节日 * @param string $md 月-日 * @return TaoFestival[] 节日 */ public static function getFestivals($md) { if (null == self::$FESTIVAL) { self::init(); } $l = array(); if (!empty(self::$FESTIVAL[$md])) { $l = self::$FESTIVAL[$md]; } return $l; } private static function init() { self::$FESTIVAL = array( '1-1' => array(new TaoFestival('天腊之辰', '天腊,此日五帝会于东方九炁青天')), '1-3' => array(new TaoFestival('郝真人圣诞'), new TaoFestival('孙真人圣诞')), '1-5' => array(new TaoFestival('孙祖清静元君诞')), '1-7' => array(new TaoFestival('举迁赏会', '此日上元赐福,天官同地水二官考校罪福')), '1-9' => array(new TaoFestival('玉皇上帝圣诞')), '1-13' => array(new TaoFestival('关圣帝君飞升')), '1-15' => array(new TaoFestival('上元天官圣诞'), new TaoFestival('老祖天师圣诞')), '1-19' => array(new TaoFestival('长春邱真人(邱处机)圣诞')), '1-28' => array(new TaoFestival('许真君(许逊天师)圣诞')), '2-1' => array(new TaoFestival('勾陈天皇大帝圣诞'), new TaoFestival('长春刘真人(刘渊然)圣诞')), '2-2' => array(new TaoFestival('土地正神诞'), new TaoFestival('姜太公圣诞')), '2-3' => array(new TaoFestival('文昌梓潼帝君圣诞')), '2-6' => array(new TaoFestival('东华帝君圣诞')), '2-13' => array(new TaoFestival('度人无量葛真君圣诞')), '2-15' => array(new TaoFestival('太清道德天尊(太上老君)圣诞')), '2-19' => array(new TaoFestival('慈航真人圣诞')), '3-1' => array(new TaoFestival('谭祖(谭处端)长真真人圣诞')), '3-3' => array(new TaoFestival('玄天上帝圣诞')), '3-6' => array(new TaoFestival('眼光娘娘圣诞')), '3-15' => array(new TaoFestival('天师张大真人圣诞'), new TaoFestival('财神赵公元帅圣诞')), '3-16' => array(new TaoFestival('三茅真君得道之辰'), new TaoFestival('中岳大帝圣诞')), '3-18' => array(new TaoFestival('王祖(王处一)玉阳真人圣诞'), new TaoFestival('后土娘娘圣诞')), '3-19' => array(new TaoFestival('太阳星君圣诞')), '3-20' => array(new TaoFestival('子孙娘娘圣诞')), '3-23' => array(new TaoFestival('天后妈祖圣诞')), '3-26' => array(new TaoFestival('鬼谷先师诞')), '3-28' => array(new TaoFestival('东岳大帝圣诞')), '4-1' => array(new TaoFestival('长生谭真君成道之辰')), '4-10' => array(new TaoFestival('何仙姑圣诞')), '4-14' => array(new TaoFestival('吕祖纯阳祖师圣诞')), '4-15' => array(new TaoFestival('钟离祖师圣诞')), '4-18' => array(new TaoFestival('北极紫微大帝圣诞'), new TaoFestival('泰山圣母碧霞元君诞'), new TaoFestival('华佗神医先师诞')), '4-20' => array(new TaoFestival('眼光圣母娘娘诞')), '4-28' => array(new TaoFestival('神农先帝诞')), '5-1' => array(new TaoFestival('南极长生大帝圣诞')), '5-5' => array(new TaoFestival('地腊之辰', '地腊,此日五帝会于南方三炁丹天'), new TaoFestival('南方雷祖圣诞'), new TaoFestival('地祗温元帅圣诞'), new TaoFestival('雷霆邓天君圣诞')), '5-11' => array(new TaoFestival('城隍爷圣诞')), '5-13' => array(new TaoFestival('关圣帝君降神'), new TaoFestival('关平太子圣诞')), '5-18' => array(new TaoFestival('张天师圣诞')), '5-20' => array(new TaoFestival('马祖丹阳真人圣诞')), '5-29' => array(new TaoFestival('紫青白祖师圣诞')), '6-1' => array(new TaoFestival('南斗星君下降')), '6-2' => array(new TaoFestival('南斗星君下降')), '6-3' => array(new TaoFestival('南斗星君下降')), '6-4' => array(new TaoFestival('南斗星君下降')), '6-5' => array(new TaoFestival('南斗星君下降')), '6-6' => array(new TaoFestival('南斗星君下降')), '6-10' => array(new TaoFestival('刘海蟾祖师圣诞')), '6-15' => array(new TaoFestival('灵官王天君圣诞')), '6-19' => array(new TaoFestival('慈航(观音)成道日')), '6-23' => array(new TaoFestival('火神圣诞')), '6-24' => array(new TaoFestival('南极大帝中方雷祖圣诞'), new TaoFestival('关圣帝君圣诞')), '6-26' => array(new TaoFestival('二郎真君圣诞')), '7-7' => array(new TaoFestival('道德腊之辰', '道德腊,此日五帝会于西方七炁素天'), new TaoFestival('庆生中会', '此日中元赦罪,地官同天水二官考校罪福')), '7-12' => array(new TaoFestival('西方雷祖圣诞')), '7-15' => array(new TaoFestival('中元地官大帝圣诞')), '7-18' => array(new TaoFestival('王母娘娘圣诞')), '7-20' => array(new TaoFestival('刘祖(刘处玄)长生真人圣诞')), '7-22' => array(new TaoFestival('财帛星君文财神增福相公李诡祖圣诞')), '7-26' => array(new TaoFestival('张三丰祖师圣诞')), '8-1' => array(new TaoFestival('许真君飞升日')), '8-3' => array(new TaoFestival('九天司命灶君诞')), '8-5' => array(new TaoFestival('北方雷祖圣诞')), '8-10' => array(new TaoFestival('北岳大帝诞辰')), '8-15' => array(new TaoFestival('太阴星君诞')), '9-1' => array(new TaoFestival('北斗九皇降世之辰')), '9-2' => array(new TaoFestival('北斗九皇降世之辰')), '9-3' => array(new TaoFestival('北斗九皇降世之辰')), '9-4' => array(new TaoFestival('北斗九皇降世之辰')), '9-5' => array(new TaoFestival('北斗九皇降世之辰')), '9-6' => array(new TaoFestival('北斗九皇降世之辰')), '9-7' => array(new TaoFestival('北斗九皇降世之辰')), '9-8' => array(new TaoFestival('北斗九皇降世之辰')), '9-9' => array(new TaoFestival('北斗九皇降世之辰'), new TaoFestival('斗姥元君圣诞'), new TaoFestival('重阳帝君圣诞'), new TaoFestival('玄天上帝飞升'), new TaoFestival('酆都大帝圣诞')), '9-22' => array(new TaoFestival('增福财神诞')), '9-23' => array(new TaoFestival('萨翁真君圣诞')), '9-28' => array(new TaoFestival('五显灵官马元帅圣诞')), '10-1' => array(new TaoFestival('民岁腊之辰', '民岁腊,此日五帝会于北方五炁黑天'), new TaoFestival('东皇大帝圣诞')), '10-3' => array(new TaoFestival('三茅应化真君圣诞')), '10-6' => array(new TaoFestival('天曹诸司五岳五帝圣诞')), '10-15' => array(new TaoFestival('下元水官大帝圣诞'), new TaoFestival('建生大会', '此日下元解厄,水官同天地二官考校罪福')), '10-18' => array(new TaoFestival('地母娘娘圣诞')), '10-19' => array(new TaoFestival('长春邱真君飞升')), '10-20' => array(new TaoFestival('虚靖天师(即三十代天师弘悟张真人)诞')), '11-6' => array(new TaoFestival('西岳大帝圣诞')), '11-9' => array(new TaoFestival('湘子韩祖圣诞')), '11-11' => array(new TaoFestival('太乙救苦天尊圣诞')), '11-26' => array(new TaoFestival('北方五道圣诞')), '12-8' => array(new TaoFestival('王侯腊之辰', '王侯腊,此日五帝会于上方玄都玉京')), '12-16' => array(new TaoFestival('南岳大帝圣诞'), new TaoFestival('福德正神诞')), '12-20' => array(new TaoFestival('鲁班先师圣诞')), '12-21' => array(new TaoFestival('天猷上帝圣诞')), '12-22' => array(new TaoFestival('重阳祖师圣诞')), '12-23' => array(new TaoFestival('祭灶王', '最适宜谢旧年太岁,开启拜新年太岁')), '12-25' => array(new TaoFestival('玉帝巡天'), new TaoFestival('天神下降')), '12-29' => array(new TaoFestival('清静孙真君(孙不二)成道')) ); } } test/EightCharTest.php 0000644 00000036606 14641217602 0010750 0 ustar 00 getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('乙酉', $eightChar->getYear()); $this->assertEquals('戊子', $eightChar->getMonth()); $this->assertEquals('辛巳', $eightChar->getDay()); $this->assertEquals('壬辰', $eightChar->getTime()); } public function test2() { $solar = Solar::fromYmdHms(1988, 2, 15, 23, 30, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('戊辰', $eightChar->getYear()); $this->assertEquals('甲寅', $eightChar->getMonth()); $this->assertEquals('庚子', $eightChar->getDay()); $this->assertEquals('戊子', $eightChar->getTime()); $eightChar->setSect(1); $this->assertEquals('戊辰', $eightChar->getYear()); $this->assertEquals('甲寅', $eightChar->getMonth()); $this->assertEquals('辛丑', $eightChar->getDay()); $this->assertEquals('戊子', $eightChar->getTime()); } public function test3() { $solar = Solar::fromYmdHms(1988, 2, 2, 22, 30, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('丁卯', $eightChar->getYear()); $this->assertEquals('癸丑', $eightChar->getMonth()); $this->assertEquals('丁亥', $eightChar->getDay()); $this->assertEquals('辛亥', $eightChar->getTime()); } public function testHideGan() { $solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('辛', implode($eightChar->getYearHideGan())); $this->assertEquals('癸', implode($eightChar->getMonthHideGan())); $this->assertEquals('丙庚戊', implode($eightChar->getDayHideGan())); $this->assertEquals('戊乙癸', implode($eightChar->getTimeHideGan())); } public function testShiShenZhi() { $solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('比肩', implode($eightChar->getYearShiShenZhi())); $this->assertEquals('食神', implode($eightChar->getMonthShiShenZhi())); $this->assertEquals('正官劫财正印', implode($eightChar->getDayShiShenZhi())); $this->assertEquals('正印偏财食神', implode($eightChar->getTimeShiShenZhi())); } public function testDiShi() { $solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('临官', $eightChar->getYearDiShi()); $this->assertEquals('长生', $eightChar->getMonthDiShi()); $this->assertEquals('死', $eightChar->getDayDiShi()); $this->assertEquals('墓', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 18, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('病', $eightChar->getYearDiShi()); $this->assertEquals('死', $eightChar->getMonthDiShi()); $this->assertEquals('衰', $eightChar->getDayDiShi()); $this->assertEquals('绝', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 19, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('胎', $eightChar->getYearDiShi()); $this->assertEquals('绝', $eightChar->getMonthDiShi()); $this->assertEquals('长生', $eightChar->getDayDiShi()); $this->assertEquals('死', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 20, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('绝', $eightChar->getYearDiShi()); $this->assertEquals('胎', $eightChar->getMonthDiShi()); $this->assertEquals('病', $eightChar->getDayDiShi()); $this->assertEquals('长生', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 21, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('胎', $eightChar->getYearDiShi()); $this->assertEquals('绝', $eightChar->getMonthDiShi()); $this->assertEquals('冠带', $eightChar->getDayDiShi()); $this->assertEquals('死', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 22, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('绝', $eightChar->getYearDiShi()); $this->assertEquals('胎', $eightChar->getMonthDiShi()); $this->assertEquals('帝旺', $eightChar->getDayDiShi()); $this->assertEquals('长生', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 23, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('死', $eightChar->getYearDiShi()); $this->assertEquals('病', $eightChar->getMonthDiShi()); $this->assertEquals('沐浴', $eightChar->getDayDiShi()); $this->assertEquals('帝旺', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 24, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('长生', $eightChar->getYearDiShi()); $this->assertEquals('沐浴', $eightChar->getMonthDiShi()); $this->assertEquals('衰', $eightChar->getDayDiShi()); $this->assertEquals('临官', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 25, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('帝旺', $eightChar->getYearDiShi()); $this->assertEquals('临官', $eightChar->getMonthDiShi()); $this->assertEquals('长生', $eightChar->getDayDiShi()); $this->assertEquals('沐浴', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 26, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('临官', $eightChar->getYearDiShi()); $this->assertEquals('帝旺', $eightChar->getMonthDiShi()); $this->assertEquals('病', $eightChar->getDayDiShi()); $this->assertEquals('病', $eightChar->getTimeDiShi()); $solar = Solar::fromYmdHms(2020, 11, 27, 17, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('沐浴', $eightChar->getYearDiShi()); $this->assertEquals('长生', $eightChar->getMonthDiShi()); $this->assertEquals('养', $eightChar->getDayDiShi()); $this->assertEquals('胎', $eightChar->getTimeDiShi()); } public function testNaYin() { $solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('泉中水', $eightChar->getYearNaYin()); $this->assertEquals('霹雳火', $eightChar->getMonthNaYin()); $this->assertEquals('白蜡金', $eightChar->getDayNaYin()); $this->assertEquals('长流水', $eightChar->getTimeNaYin()); } public function testTaiYuan() { $solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('己卯', $eightChar->getTaiYuan()); $solar = Solar::fromYmdHms(1995, 12, 18, 10, 28, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('己卯', $eightChar->getTaiYuan()); } public function testMingGong() { $solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('己丑', $eightChar->getMingGong()); $solar = Solar::fromYmdHms(1998, 6, 11, 4, 28, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('辛酉', $eightChar->getMingGong()); $solar = Solar::fromYmdHms(1995, 12, 18, 10, 28, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('戊子', $eightChar->getMingGong()); } public function testShenGong() { $solar = Solar::fromYmdHms(1995, 12, 18, 10, 28, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('壬午', $eightChar->getShenGong()); } public function testShenGong1() { $solar = Solar::fromYmdHms(1994, 12, 6, 2, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('乙丑', $eightChar->getShenGong()); } public function testShenGong2() { $solar = Solar::fromYmdHms(1990, 12, 11, 6, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('庚辰', $eightChar->getShenGong()); } public function testShenGong3() { $solar = Solar::fromYmdHms(1993, 5, 23, 4, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('庚申', $eightChar->getShenGong()); } public function test4() { $lunar = Lunar::fromYmd(1985, 12, 27); $eightChar = $lunar->getEightChar(); $this->assertEquals('1995-11-05', $eightChar->getYun(1)->getStartSolar()->toYmd()); } public function test5() { $lunar = Lunar::fromYmd(1985, 1, 27); $eightChar = $lunar->getEightChar(); $this->assertEquals('1989-03-28', $eightChar->getYun(1)->getStartSolar()->toYmd()); } public function test6() { $lunar = Lunar::fromYmd(1986, 12, 27); $eightChar = $lunar->getEightChar(); $this->assertEquals('1990-04-15', $eightChar->getYun(1)->getStartSolar()->toYmd()); } public function test7() { $solar = Solar::fromYmdHms(2053, 2, 18, 13, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('癸酉 甲寅 乙酉 癸未', $eightChar->toString()); } public function test8() { $solar = Solar::fromYmdHms(8071, 12, 30, 13, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('辛卯 庚子 己丑 辛未', $eightChar->toString()); } public function test11() { $lunar = Lunar::fromYmdHms(1987, 12, 28, 23, 30, 0); $eightChar = $lunar->getEightChar(); $this->assertEquals('戊辰', $eightChar->getYear()); $this->assertEquals('甲寅', $eightChar->getMonth()); $this->assertEquals('庚子', $eightChar->getDay()); $this->assertEquals('戊子', $eightChar->getTime()); } public function test12() { $solarList = Solar::fromBaZi('丙辰', '丁酉', '丙子', '甲午'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1916-10-06 12:00:00', '1976-09-21 12:00:00'); $this->assertEquals($expected, $actual); } public function test13() { $solarList = Solar::fromBaZi('壬寅', '庚戌', '己未', '乙亥'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('2022-11-02 22:00:00'); $this->assertEquals($expected, $actual); } public function test14() { $solarList = Solar::fromBaZi('己卯', '辛未', '甲戌', '壬申'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1939-08-05 16:00:00', '1999-07-21 16:00:00'); $this->assertEquals($expected, $actual); } public function test15() { $solarList = Solar::fromBaZi('庚子', '戊子', '己卯', '庚午'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1901-01-01 12:00:00', '1960-12-17 12:00:00'); $this->assertEquals($expected, $actual); } public function test16() { $solarList = Solar::fromBaZi('庚子', '癸未', '乙丑', '丁亥'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1960-08-05 22:00:00', '2020-07-21 22:00:00'); $this->assertEquals($expected, $actual); } public function test17() { $lunar = Solar::fromYmdHms('1999', '06', '07', '09', '11', '00')->getLunar()->getEightChar(); $actual = $lunar->toString(); $expected = '己卯 庚午 庚寅 辛巳'; $this->assertEquals($expected, $actual); } public function test18() { $solarList = Solar::fromBaZiBySectAndBaseYear('癸卯','甲寅','甲寅','甲子', 2, 1843); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1843-02-09 00:00:00', '2023-02-25 00:00:00'); $this->assertEquals($expected, $actual); } public function test19() { $solarList = Solar::fromBaZi('己亥','丁丑','壬寅','戊申'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1900-01-29 16:00:00', '1960-01-15 16:00:00'); $this->assertEquals($expected, $actual); } public function test20() { $solarList = Solar::fromBaZi('己亥','丙子','癸酉','庚申'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1959-12-17 16:00:00'); $this->assertEquals($expected, $actual); } public function test21() { $solarList = Solar::fromBaZiBySectAndBaseYear('乙亥','乙酉','乙酉','乙酉', 1, 1000); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1095-09-23 18:00:00', '1155-09-08 18:00:00', '1335-09-23 18:00:00', '1395-09-08 18:00:00', '1575-09-23 18:00:00', '1635-09-18 18:00:00', '1815-10-05 18:00:00', '1875-09-20 18:00:00'); $this->assertEquals($expected, $actual); } public function test22() { $solarList = Solar::fromBaZi('癸卯','乙卯','丙辰','丁酉'); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1903-03-29 18:00:00', '1963-03-14 18:00:00'); $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); } public function test25() { $solarList = Solar::fromBaZiBySectAndBaseYear('丁卯','丁未','甲申','乙丑', 1, 1900); $actual = array(); foreach ($solarList as $solar) { $actual[] = $solar->toYmdHms(); } $expected = array('1987-08-03 02:00:00'); $this->assertEquals($expected, $actual); } public function test26() { $solar = Solar::fromYmdHms(2000, 1, 23, 22, 0, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $this->assertEquals('己卯', $eightChar->getYear()); $this->assertEquals('丁丑', $eightChar->getMonth()); $this->assertEquals('庚辰', $eightChar->getDay()); $this->assertEquals('丁亥', $eightChar->getTime()); } } test/FestivalTest.php 0000644 00000001552 14641217602 0010657 0 ustar 00 assertEquals('感恩节', implode($solar->getFestivals())); $solar = Solar::fromYmd(2020, 6, 21); $this->assertEquals('父亲节', implode($solar->getFestivals())); $solar = Solar::fromYmd(2021, 5, 9); $this->assertEquals('母亲节', implode($solar->getFestivals())); $solar = Solar::fromYmd(1986, 11, 27); $this->assertEquals('感恩节', implode($solar->getFestivals())); $solar = Solar::fromYmd(1985, 6, 16); $this->assertEquals('父亲节', implode($solar->getFestivals())); $solar = Solar::fromYmd(1984, 5, 13); $this->assertEquals('母亲节', implode($solar->getFestivals())); } } test/FotoTest.php 0000644 00000000774 14641217602 0010016 0 ustar 00 assertEquals('二五六五年十月十四 (三元降) (四天王巡行)', $foto->toFullString()); } public function test1() { $foto = Foto::fromLunar(Lunar::fromYmd(2021, 3, 16)); $this->assertEquals(array('准提菩萨圣诞'), $foto->getOtherFestivals()); } } test/FuTest.php 0000644 00000006660 14641217602 0007461 0 ustar 00 getLunar(); $fu = $lunar->getFu(); $this->assertEquals('初伏', $fu->toString()); $this->assertEquals('初伏第1天', $fu->toFullString()); } public function test2() { $solar = Solar::fromYmd(2011, 7, 23); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('初伏', $fu->toString()); $this->assertEquals('初伏第10天', $fu->toFullString()); } public function test3() { $solar = Solar::fromYmd(2011, 7, 24); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('中伏', $fu->toString()); $this->assertEquals('中伏第1天', $fu->toFullString()); } public function test4() { $solar = Solar::fromYmd(2011, 8, 12); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('中伏', $fu->toString()); $this->assertEquals('中伏第20天', $fu->toFullString()); } public function test5() { $solar = Solar::fromYmd(2011, 8, 13); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('末伏', $fu->toString()); $this->assertEquals('末伏第1天', $fu->toFullString()); } public function test6() { $solar = Solar::fromYmd(2011, 8, 22); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('末伏', $fu->toString()); $this->assertEquals('末伏第10天', $fu->toFullString()); } public function test7() { $solar = Solar::fromYmd(2011, 7, 13); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertNull($fu); } public function test8() { $solar = Solar::fromYmd(2011, 8, 23); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertNull($fu); } public function test9() { $solar = Solar::fromYmd(2012, 7, 18); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('初伏', $fu->toString()); $this->assertEquals('初伏第1天', $fu->toFullString()); } public function test10() { $solar = Solar::fromYmd(2012, 8, 5); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('中伏', $fu->toString()); $this->assertEquals('中伏第9天', $fu->toFullString()); } public function test11() { $solar = Solar::fromYmd(2012, 8, 8); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('末伏', $fu->toString()); $this->assertEquals('末伏第2天', $fu->toFullString()); } public function test12() { $solar = Solar::fromYmd(2020, 7, 17); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('初伏', $fu->toString()); $this->assertEquals('初伏第2天', $fu->toFullString()); } public function test13() { $solar = Solar::fromYmd(2020, 7, 26); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('中伏', $fu->toString()); $this->assertEquals('中伏第1天', $fu->toFullString()); } public function test14() { $solar = Solar::fromYmd(2020, 8, 24); $lunar = $solar->getLunar(); $fu = $lunar->getFu(); $this->assertEquals('末伏', $fu->toString()); $this->assertEquals('末伏第10天', $fu->toFullString()); } } test/GanZhiTest.php 0000644 00000005315 14641217602 0010263 0 ustar 00 getLunar(); $this->assertEquals('己亥', $lunar->getYearInGanZhi()); $this->assertEquals('己亥', $lunar->getYearInGanZhiByLiChun()); $this->assertEquals('己亥', $lunar->getYearInGanZhiExact()); } public function test2() { $solar = Solar::fromYmd(2012, 12, 27); $lunar = $solar->getLunar(); $this->assertEquals('壬辰', $lunar->getYearInGanZhi()); $this->assertEquals('壬子', $lunar->getMonthInGanZhi()); $this->assertEquals('壬戌', $lunar->getDayInGanZhi()); } public function test3() { $solar = Solar::fromYmd(2012, 12, 20); $lunar = $solar->getLunar(); $this->assertEquals('壬辰', $lunar->getYearInGanZhi()); $this->assertEquals('壬子', $lunar->getMonthInGanZhi()); $this->assertEquals('乙卯', $lunar->getDayInGanZhi()); } public function test4() { $solar = Solar::fromYmd(2012, 11, 20); $lunar = $solar->getLunar(); $this->assertEquals('壬辰', $lunar->getYearInGanZhi()); $this->assertEquals('辛亥', $lunar->getMonthInGanZhi()); $this->assertEquals('乙酉', $lunar->getDayInGanZhi()); } public function test15() { $solar = Solar::fromYmd(1988, 2, 15); $lunar = $solar->getLunar(); $this->assertEquals('丁卯', $lunar->getYearInGanZhi()); } public function test16() { $solar = Solar::fromYmdHms(1988, 2, 15, 23, 30,0); $lunar = $solar->getLunar(); $this->assertEquals('丁卯', $lunar->getYearInGanZhi()); $this->assertEquals('戊辰', $lunar->getYearInGanZhiByLiChun()); $this->assertEquals('戊辰', $lunar->getYearInGanZhiExact()); } public function test17() { $solar = Solar::fromYmdHms(2019, 2, 8, 13, 22, 0); $lunar = $solar->getLunar(); $this->assertEquals('己亥', $lunar->getYearInGanZhi()); $this->assertEquals('己亥', $lunar->getYearInGanZhiByLiChun()); $this->assertEquals('己亥', $lunar->getYearInGanZhiExact()); $this->assertEquals('丙寅', $lunar->getMonthInGanZhi()); $this->assertEquals('丙寅', $lunar->getMonthInGanZhiExact()); } public function test18() { $solar = Solar::fromYmdHms(2020,2,4,13,22,0); $lunar = $solar->getLunar(); $this->assertEquals('庚子', $lunar->getYearInGanZhi()); $this->assertEquals('庚子', $lunar->getYearInGanZhiByLiChun()); $this->assertEquals('己亥', $lunar->getYearInGanZhiExact()); $this->assertEquals('戊寅', $lunar->getMonthInGanZhi()); $this->assertEquals('丁丑', $lunar->getMonthInGanZhiExact()); } } test/HalfYearTest.php 0000644 00000001015 14641217602 0010567 0 ustar 00 assertEquals('2019.1', $halfYear->toString()); $this->assertEquals('2019年上半年', $halfYear->toFullString()); $this->assertEquals('2019.2', $halfYear->next(1)->toString()); $this->assertEquals('2019年下半年', $halfYear->next(1)->toFullString()); } } test/HolidayTest.php 0000644 00000002036 14641217602 0010471 0 ustar 00 assertEquals('2020-01-01 元旦节 2020-01-01', $holiday->toString()); } public function test1() { $holiday = HolidayUtil::getHolidayByYmd(2016,10,4); $this->assertEquals('2016-10-01', $holiday->getTarget()); } public function test2() { // 将2020-01-01修改为春节 HolidayUtil::fix(null,'202001011120200101'); $holiday = HolidayUtil::getHoliday('2020-01-01'); $this->assertEquals('2020-01-01 春节 2020-01-01', $holiday->toString()); } public function testRemove() { $holiday = HolidayUtil::getHolidayByYmd(2010,1,1); $this->assertEquals('元旦节', $holiday->getName()); HolidayUtil::fix(null, '20100101~000000000000000000000000000'); $holiday = HolidayUtil::getHolidayByYmd(2010,1,1); $this->assertNull($holiday); } } test/JieQiTest.php 0000644 00000001613 14641217602 0010101 0 ustar 00 getLunar(); $this->assertEquals('冬至', $lunar->getJieQi()); } public function test7() { $lunar = Lunar::fromYmd(2012, 9, 1); $jieQi = $lunar->getJieQiTable(); $this->assertEquals('2012-09-07 13:29:01', $jieQi['白露']->toYmdHms()); } public function test8() { $lunar = Lunar::fromYmd(2050, 12, 1); $jieQiTable = $lunar->getJieQiTable(); $this->assertEquals('2050-12-07 06:41:13', $jieQiTable['DA_XUE']->toYmdHms()); } public function test9() { $lunar = Solar::fromYmd(2023, 6, 1)->getLunar(); $jieQiTable = $lunar->getJieQiTable(); $this->assertEquals('2022-12-22 05:48:11', $jieQiTable['冬至']->toYmdHms()); } } test/JulianDayTest.php 0000644 00000000732 14641217602 0010761 0 ustar 00 assertEquals(2459045.5, $solar->getJulianDay()); } public function test2() { $solar = Solar::fromJulianDay(2459045.5); $this->assertEquals('2020-07-15 00:00:00', $solar->toYmdHms()); } } test/LunarMonthTest.php 0000644 00000002536 14641217602 0011174 0 ustar 00 assertEquals(1, $month->getIndex()); $this->assertEquals('甲寅', $month->getGanZhi()); } public function test2() { $month = LunarMonth::fromYm(2023, -2); $this->assertEquals(3, $month->getIndex()); $this->assertEquals('丙辰', $month->getGanZhi()); } public function test3() { $month = LunarMonth::fromYm(2023, 3); $this->assertEquals(4, $month->getIndex()); $this->assertEquals('丁巳', $month->getGanZhi()); } public function test4() { $month = LunarMonth::fromYm(2024, 1); $this->assertEquals(1, $month->getIndex()); $this->assertEquals('丙寅', $month->getGanZhi()); } public function test5() { $month = LunarMonth::fromYm(2023, 12); $this->assertEquals(13, $month->getIndex()); $this->assertEquals('丙寅', $month->getGanZhi()); } public function test6() { $month = LunarMonth::fromYm(2022, 1); $this->assertEquals(1, $month->getIndex()); $this->assertEquals('壬寅', $month->getGanZhi()); } public function test7() { $month = LunarMonth::fromYm(2016, 1); $this->assertEquals(1, $month->getIndex()); } } test/LunarTest.php 0000644 00000026110 14641217602 0010160 0 ustar 00 assertEquals('二〇一九年三月廿七', $lunar->toString()); $this->assertEquals('二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[艮](东北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]', $lunar->toFullString()); $this->assertEquals('2019-05-01', $lunar->getSolar()->toString()); $this->assertEquals('2019-05-01 00:00:00 星期三 (劳动节) 金牛座', $lunar->getSolar()->toFullString()); } public function test1() { $solar = Solar::fromYmdHms(1, 1, 1, 12, 0, 0); $this->assertEquals('〇年冬月十八', $solar->getLunar()->toString()); } public function test2() { $solar = Solar::fromYmdHms(9998, 1, 1, 12, 0, 0); $this->assertEquals('九九九七年腊月十一', $solar->getLunar()->toString()); } public function test3() { $lunar = Lunar::fromYmdHms(1, 11, 18, 12, 0, 0); $this->assertEquals('0001-12-22', $lunar->getSolar()->toString()); } public function test4() { $lunar = Lunar::fromYmdHms(7777, 12, 2, 12, 0, 0); $this->assertEquals('7778-01-09', $lunar->getSolar()->toString()); } public function test5() { $lunar = Lunar::fromYmdHms(1905, 1, 1, 12, 0, 0); $this->assertEquals('1905-02-04', $lunar->getSolar()->toString()); } public function test6() { $lunar = Lunar::fromYmdHms(2038, 12, 29, 12, 0, 0); $this->assertEquals('2039-01-23', $lunar->getSolar()->toString()); } public function test7() { $lunar = Lunar::fromYmdHms(2020, -4, 2, 13, 0, 0); $this->assertEquals('二〇二〇年闰四月初二', $lunar->toString()); $this->assertEquals('2020-05-24', $lunar->getSolar()->toString()); } public function test8() { $lunar = Lunar::fromYmdHms(2020, 12, 10, 13, 0, 0); $this->assertEquals('二〇二〇年腊月初十', $lunar->toString()); $this->assertEquals('2021-01-22', $lunar->getSolar()->toString()); } public function test9() { $lunar = Lunar::fromYmdHms(1500, 1, 1, 12, 0, 0); $this->assertEquals('1500-01-31', $lunar->getSolar()->toString()); } public function test10() { $lunar = Lunar::fromYmdHms(1500, 12, 29, 12, 0, 0); $this->assertEquals('1501-01-18', $lunar->getSolar()->toString()); } public function test11() { $solar = new Solar(1500, 1, 1, 12, 0, 0); $this->assertEquals('一四九九年腊月初一', $solar->getLunar()->toString()); } public function test12() { $solar = new Solar(1500, 12, 31, 12, 0, 0); $this->assertEquals('一五〇〇年腊月十一', $solar->getLunar()->toString()); } public function test13() { $solar = new Solar(1582, 10, 4, 12, 0, 0); $this->assertEquals('一五八二年九月十八', $solar->getLunar()->toString()); } public function test14() { $solar = new Solar(1582, 10, 15, 12, 0, 0); $this->assertEquals('一五八二年九月十九', $solar->getLunar()->toString()); } public function test15() { $lunar = Lunar::fromYmdHms(1582, 9, 18, 12, 0, 0); $this->assertEquals('1582-10-04', $lunar->getSolar()->toString()); } public function test16() { $lunar = Lunar::fromYmdHms(1582, 9, 19, 12, 0, 0); $this->assertEquals('1582-10-15', $lunar->getSolar()->toString()); } public function test17() { $lunar = Lunar::fromYmdHms(2019, 12, 12, 11, 22, 0); $this->assertEquals('2020-01-06', $lunar->getSolar()->toString()); } public function test18() { $lunar = Lunar::fromYmd(2021, 12, 29); $fs = $lunar->getFestivals(); $this->assertEquals('除夕', $fs[0]); } public function test19() { $lunar = Lunar::fromYmd(2020, 12, 30); $fs = $lunar->getFestivals(); $this->assertEquals('除夕', $fs[0]); } public function test20() { $lunar = Lunar::fromYmd(2020, 12, 29); $fs = $lunar->getFestivals(); $this->assertEquals(0, count($fs)); } public function test21() { $solar = Solar::fromYmd(2022, 1, 31); $lunar = $solar->getLunar(); $fs = $lunar->getFestivals(); $this->assertEquals('除夕', $fs[0]); } public function test24() { $lunar = Lunar::fromYmd(2033, -11, 1); $this->assertEquals('2033-12-22', $lunar->getSolar()->toString()); } public function test25() { $solar = Solar::fromYmdHms(2021, 6, 7, 21, 18, 0); $this->assertEquals('二〇二一年四月廿七', $solar->getLunar()->toString()); } public function test26() { $lunar = Lunar::fromYmdHms(2021, 6, 7, 21, 18, 0); $this->assertEquals('2021-07-16', $lunar->getSolar()->toString()); } public function test27() { $solar = Solar::fromYmd(1989, 4, 28); $this->assertEquals(23, $solar->getLunar()->getDay()); } public function test28() { $solar = Solar::fromYmd(1990, 10, 8); $this->assertEquals('乙酉', $solar->getLunar()->getMonthInGanZhiExact()); } public function test29() { $solar = Solar::fromYmd(1990, 10, 9); $this->assertEquals('丙戌', $solar->getLunar()->getMonthInGanZhiExact()); } public function test30() { $solar = Solar::fromYmd(1990, 10, 8); $this->assertEquals('丙戌', $solar->getLunar()->getMonthInGanZhi()); } public function test31() { $solar = Solar::fromYmdHms(1987, 4, 17, 9, 0, 0); $this->assertEquals('一九八七年三月二十', $solar->getLunar()->toString()); } public function test32() { $lunar = Lunar::fromYmd(2034, 1, 1); $this->assertEquals('2034-02-19', $lunar->getSolar()->toString()); } public function test33() { $lunar = Lunar::fromYmd(2033, 12, 1); $this->assertEquals('2034-01-20', $lunar->getSolar()->toString()); } public function test34() { $lunar = Lunar::fromYmd(37, -12, 1); $this->assertEquals('闰腊', $lunar->getMonthInChinese()); } public function test35() { $lunar = Lunar::fromYmd(56, -12, 1); $this->assertEquals('闰腊', $lunar->getMonthInChinese()); $lunar = Lunar::fromYmd(75, -11, 1); $this->assertEquals('闰冬', $lunar->getMonthInChinese()); $lunar = Lunar::fromYmd(94, -11, 1); $this->assertEquals('闰冬', $lunar->getMonthInChinese()); $lunar = Lunar::fromYmd(94, 12, 1); $this->assertEquals('腊', $lunar->getMonthInChinese()); $lunar = Lunar::fromYmd(113, 12, 1); $this->assertEquals('腊', $lunar->getMonthInChinese()); $lunar = Lunar::fromYmd(113, -12, 1); $this->assertEquals('闰腊', $lunar->getMonthInChinese()); $lunar = Lunar::fromYmd(5552, -12, 1); $this->assertEquals('闰腊', $lunar->getMonthInChinese()); } public function test36() { $solar = Solar::fromYmd(5553, 1, 22); $this->assertEquals('五五五二年闰腊月初二', $solar->getLunar()->toString()); } public function test37() { $solar = Solar::fromYmd(7013, 12, 24); $this->assertEquals('七〇一三年闰冬月初四', $solar->getLunar()->toString()); } public function test38() { $lunar = Lunar::fromYmd(7013, -11, 4); $this->assertEquals('7013-12-24', $lunar->getSolar()->toString()); } public function test41() { $solar = Solar::fromYmd(4, 2, 10); $this->assertEquals('鼠', $solar->getLunar()->getYearShengXiao()); } public function test42() { $solar = Solar::fromYmd(4, 2, 9); $this->assertEquals('猪', $solar->getLunar()->getYearShengXiao()); } public function test43() { $solar = Solar::fromYmd(1, 2, 12); $this->assertEquals('鸡', $solar->getLunar()->getYearShengXiao()); } public function test44() { $solar = Solar::fromYmd(1, 1, 1); $this->assertEquals('猴', $solar->getLunar()->getYearShengXiao()); } public function test45() { $solar = Solar::fromYmd(2017, 2, 15); $this->assertEquals('子命互禄 辛命进禄', $solar->getLunar()->getDayLu()); } public function test46() { $solar = Solar::fromYmd(2017, 2, 16); $this->assertEquals('寅命互禄', $solar->getLunar()->getDayLu()); } public function test48() { $solar = Solar::fromYmd(2021, 11, 13); $this->assertEquals('碓磨厕 外东南', $solar->getLunar()->getDayPositionTai()); } public function test49() { $solar = Solar::fromYmd(2021, 11, 12); $this->assertEquals('占门碓 外东南', $solar->getLunar()->getDayPositionTai()); } public function test50() { $solar = Solar::fromYmd(2021, 11, 13); $this->assertEquals('西南', $solar->getLunar()->getDayPositionFuDesc()); } public function test51() { $solar = Solar::fromYmd(2021, 11, 12); $this->assertEquals('正北', $solar->getLunar()->getDayPositionFuDesc()); } public function test52() { $solar = Solar::fromYmd(2011, 11, 12); $this->assertEquals('厨灶厕 外西南', $solar->getLunar()->getDayPositionTai()); } public function test53() { $solar = Solar::fromYmd(2021, 12, 25); $this->assertEquals('二〇二一年冬月廿二', $solar->getLunar()->toString()); } public function test54() { $solar = Solar::fromYmd(1722, 9, 25); $fs = array(); $fs[] = '秋社'; $this->assertEquals($fs, $solar->getLunar()->getOtherFestivals()); } public function test55() { $solar = Solar::fromYmd(2022, 3, 16); $fs = array(); $fs[] = '春社'; $this->assertEquals($fs, $solar->getLunar()->getOtherFestivals()); } public function test56() { $solar = Solar::fromYmd(2022, 12, 1); $lunar = $solar->getLunar(); $this->assertEquals('初八', $lunar->getDayInChinese()); } public function test57() { $lunar = Lunar::fromYmd(1582, 9, 18); $this->assertEquals('1582-10-04', $lunar->getSolar()->toYmd()); } public function test58() { $lunar = Lunar::fromYmd(1582, 9, 19); $this->assertEquals('1582-10-15', $lunar->getSolar()->toYmd()); } public function test59() { $lunar = Lunar::fromYmd(41, 1, 1); $this->assertEquals('0041-02-20', $lunar->getSolar()->toYmd()); } public function test60() { $lunar = Lunar::fromYmd(345, 1, 1); $this->assertEquals('0345-02-18', $lunar->getSolar()->toYmd()); } public function test61() { $lunar = Lunar::fromYmd(1051, 1, 1); $this->assertEquals('1051-02-14', $lunar->getSolar()->toYmd()); } public function test62() { $lunar = Lunar::fromYmd(1537, 1, 1); $this->assertEquals('1537-02-10', $lunar->getSolar()->toYmd()); } public function test63() { $lunar = Solar::fromYmd(917, 12, 1)->getLunar(); $this->assertEquals('九一七年闰十月十四', $lunar->toString()); } public function test64() { $lunar = Solar::fromYmd(917, 12, 31)->getLunar(); $this->assertEquals('九一七年冬月十五', $lunar->toString()); } public function test65() { $lunar = Solar::fromYmd(918, 1, 1)->getLunar(); $this->assertEquals('九一七年冬月十六', $lunar->toString()); } } test/MonthTest.php 0000644 00000000751 14641217602 0010167 0 ustar 00 assertEquals('2019-5', $month->toString()); $this->assertEquals('2019年5月', $month->toFullString()); $this->assertEquals('2019-6', $month->next(1)->toString()); $this->assertEquals('2019年6月', $month->next(1)->toFullString()); } } test/NineStarTest.php 0000644 00000001151 14641217602 0010620 0 ustar 00 getLunar(); $this->assertEquals('六', $lunar->getYearNineStar()->getNumber()); } public function test22() { $lunar = Lunar::fromYmd(2022, 1, 1); $this->assertEquals('六白金开阳', $lunar->getYearNineStar()->toString()); } public function test23() { $lunar = Lunar::fromYmd(2033, 1, 1); $this->assertEquals('四绿木天权', $lunar->getYearNineStar()->toString()); } } test/SeasonTest.php 0000644 00000000767 14641217602 0010341 0 ustar 00 assertEquals('2019.2', $season->toString()); $this->assertEquals('2019年2季度', $season->toFullString()); $this->assertEquals('2019.3', $season->next(1)->toString()); $this->assertEquals('2019年3季度', $season->next(1)->toFullString()); } } test/ShuJiuTest.php 0000644 00000003615 14641217602 0010313 0 ustar 00 getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertEquals('一九', $shuJiu->toString()); $this->assertEquals('一九第1天', $shuJiu->toFullString()); } public function test2() { $solar = Solar::fromYmd(2020, 12, 22); $lunar = $solar->getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertEquals('一九', $shuJiu->toString()); $this->assertEquals('一九第2天', $shuJiu->toFullString()); } public function test3() { $solar = Solar::fromYmd(2020, 1, 7); $lunar = $solar->getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertEquals('二九', $shuJiu->toString()); $this->assertEquals('二九第8天', $shuJiu->toFullString()); } public function test4() { $solar = Solar::fromYmd(2021, 1, 6); $lunar = $solar->getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertEquals('二九', $shuJiu->toString()); $this->assertEquals('二九第8天', $shuJiu->toFullString()); } public function test5() { $solar = Solar::fromYmd(2021, 1, 8); $lunar = $solar->getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertEquals('三九', $shuJiu->toString()); $this->assertEquals('三九第1天', $shuJiu->toFullString()); } public function test6() { $solar = Solar::fromYmd(2021, 3, 5); $lunar = $solar->getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertEquals('九九', $shuJiu->toString()); $this->assertEquals('九九第3天', $shuJiu->toFullString()); } public function test7() { $solar = Solar::fromYmd(2021, 7, 5); $lunar = $solar->getLunar(); $shuJiu = $lunar->getShuJiu(); $this->assertNull($shuJiu); } } test/SolarTest.php 0000644 00000010706 14641217602 0010163 0 ustar 00 assertEquals('2019-05-01', $solar->toString()); $this->assertEquals('2019-05-01 00:00:00 星期三 (劳动节) 金牛座', $solar->toFullString()); $this->assertEquals('二〇一九年三月廿七', $solar->getLunar()->toString()); $this->assertEquals('二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[艮](东北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]', $solar->getLunar()->toFullString()); } public function test1() { $solar = Solar::fromYmd(2020, 1, 23); $this->assertEquals('2020-01-24', $solar->next(1)->toString()); $this->assertEquals('2020-02-03', $solar->nextWorkday(1)->toString()); } public function test2() { $solar = Solar::fromYmd(2020, 2, 3); $this->assertEquals('2020-01-31', $solar->next(-3)->toString()); $this->assertEquals('2020-01-21', $solar->nextWorkday(-3)->toString()); } public function test3() { $solar = Solar::fromYmd(2020, 2, 9); $this->assertEquals('2020-02-15', $solar->next(6)->toString()); $this->assertEquals('2020-02-17', $solar->nextWorkday(6)->toString()); } public function test4() { $solar = Solar::fromYmd(2020, 1, 17); $this->assertEquals('2020-01-18', $solar->next(1)->toString()); $this->assertEquals('2020-01-19', $solar->nextWorkday(1)->toString()); } public function test10() { $this->assertEquals(true, SolarUtil::isLeapYear(1500)); } public function test11() { $solar = Solar::fromYmd(2022, 3, 31); $this->assertEquals('四', $solar->getWeekInChinese()); } public function test12() { $solar = Solar::fromYmd(2021, 3, 29); $fs = array(); $fs[] = '全国中小学生安全教育日'; $this->assertEquals($fs, $solar->getFestivals()); } public function test13() { $solar = Solar::fromYmd(2022, 1, 1); $this->assertEquals('2022-01-02', $solar->next(1)->toYmd()); } public function test14() { $solar = Solar::fromYmd(2022, 1, 31); $this->assertEquals('2022-02-01', $solar->next(1)->toYmd()); } public function test15() { $solar = Solar::fromYmd(2022, 1, 1); $this->assertEquals('2023-01-01', $solar->next(365)->toYmd()); } public function test16() { $solar = Solar::fromYmd(2023, 1, 1); $this->assertEquals('2022-01-01', $solar->next(-365)->toYmd()); } public function test17() { $solar = Solar::fromYmd(1582, 10, 4); $this->assertEquals('1582-10-15', $solar->next(1)->toYmd()); } public function test18() { $solar = Solar::fromYmd(1582, 10, 4); $this->assertEquals('1582-11-01', $solar->next(18)->toYmd()); } public function test19() { $solar = Solar::fromYmd(1582, 11, 1); $this->assertEquals('1582-10-04', $solar->next(-18)->toYmd()); } public function test20() { $solar = Solar::fromYmd(1582, 11, 1); $this->assertEquals('1582-10-15', $solar->next(-17)->toYmd()); } public function test21() { $days = SolarUtil::getDaysBetween(1582, 10, 4, 1582, 10, 15); $this->assertEquals(1, $days); } public function test22() { $days = SolarUtil::getDaysBetween(1582, 10, 4, 1582, 11, 1); $this->assertEquals(18, $days); } public function test23() { $days = SolarUtil::getDaysBetween(1582, 1, 1, 1583, 1, 1); $this->assertEquals(355, $days); } 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()); } } test/TaoTest.php 0000644 00000001263 14641217602 0007624 0 ustar 00 assertEquals('四七一八年十月十七', $tao->toString()); $this->assertEquals('道歷四七一八年,天運辛丑年,己亥月,癸酉日。十月十七日,酉時。', $tao->toFullString()); } public function test1() { $tao = Tao::fromYmd(4718, 10, 18); $this->assertEquals(2, count($tao->getFestivals())); $tao = Lunar::fromYmd(2021, 10, 18)->getTao(); $this->assertEquals(2, count($tao->getFestivals())); } } test/WeekTest.php 0000644 00000006450 14641217602 0007777 0 ustar 00 assertEquals('2019.5.1', $week->toString()); $this->assertEquals('2019年5月第1周', $week->toFullString()); //当月共几周 $this->assertEquals(5, SolarUtil::getWeeksOfMonth($week->getYear(), $week->getMonth(), $start)); //当周第一天 $this->assertEquals('2019-04-29', $week->getFirstDay()->toString()); //当周第一天(本月) $this->assertEquals('2019-05-01', $week->getFirstDayInMonth()->toString()); } public function test2() { //一周的开始从星期一开始计 $start = 0; $week = SolarWeek::fromYmd(2019, 5, 1, $start); $this->assertEquals('2019.5.1', $week->toString()); $this->assertEquals('2019年5月第1周', $week->toFullString()); //当月共几周 $this->assertEquals(5, SolarUtil::getWeeksOfMonth($week->getYear(), $week->getMonth(), $start)); //当周第一天 $this->assertEquals('2019-04-28', $week->getFirstDay()->toString()); //当周第一天(本月) $this->assertEquals('2019-05-01', $week->getFirstDayInMonth()->toString()); } public function test3() { $start = 0; $week = SolarWeek::fromYmd(2022, 5, 1, $start); $this->assertEquals(1, $week->getIndex()); } public function test4() { $start = 2; $week = SolarWeek::fromYmd(2022, 5, 4, $start); $this->assertEquals(2, $week->getIndex()); } public function test5() { $start = 0; $week = SolarWeek::fromYmd(2022, 3, 6, $start); $this->assertEquals(11, $week->getIndexInYear()); } public function test6() { $solar = Solar::fromYmd(1582, 10, 1); $this->assertEquals(1, $solar->getWeek()); } public function test7() { $solar = Solar::fromYmd(1582, 10, 15); $this->assertEquals(5, $solar->getWeek()); } public function test8() { $solar = Solar::fromYmd(2023, 1, 31); $this->assertEquals(2, $solar->getWeek()); } public function test9() { $this->assertEquals(0, Solar::fromYmd(1129, 11, 17)->getWeek()); } public function test10() { $this->assertEquals(5, Solar::fromYmd(1129, 11, 1)->getWeek()); } public function test11() { $this->assertEquals(4, Solar::fromYmd(8, 11, 1)->getWeek()); } public function test12() { $this->assertEquals(0, Solar::fromYmd(1582, 9, 30)->getWeek()); } public function test13() { $this->assertEquals(1, Solar::fromYmd(1582, 1, 1)->getWeek()); } public function test14() { $this->assertEquals(6, Solar::fromYmd(1500, 2, 29)->getWeek()); } public function test15() { $this->assertEquals(3, Solar::fromYmd(9865, 7, 26)->getWeek()); } public function test16() { $this->assertEquals(6, Solar::fromYmd(1961, 9, 30)->getWeek()); $this->assertEquals(6, Solar::fromYmdHms(1961, 9, 30, 23, 59, 59)->getWeek()); } public function test17() { $this->assertEquals(3, Solar::fromYmdHms(2021, 9, 15, 20, 0, 0)->getWeek()); $this->assertEquals(3, Solar::fromYmdHms(2021, 9, 15, 23, 59, 59)->getWeek()); } } test/WuHouTest.php 0000644 00000003730 14641217602 0010151 0 ustar 00 getLunar(); $this->assertEquals('萍始生', $lunar->getWuHou()); } public function test2() { $solar = Solar::fromYmd(2021, 1, 15); $lunar = $solar->getLunar(); $this->assertEquals('雉始雊', $lunar->getWuHou()); } public function test3() { $solar = Solar::fromYmd(2017, 1, 5); $lunar = $solar->getLunar(); $this->assertEquals('雁北乡', $lunar->getWuHou()); } public function test4() { $solar = Solar::fromYmd(2020, 4, 10); $lunar = $solar->getLunar(); $this->assertEquals('田鼠化为鴽', $lunar->getWuHou()); } public function test5() { $solar = Solar::fromYmd(2020, 6, 11); $lunar = $solar->getLunar(); $this->assertEquals('鵙始鸣', $lunar->getWuHou()); } public function test6() { $solar = Solar::fromYmd(2020, 6, 1); $lunar = $solar->getLunar(); $this->assertEquals('麦秋至', $lunar->getWuHou()); } public function test7() { $solar = Solar::fromYmd(2020, 12, 8); $lunar = $solar->getLunar(); $this->assertEquals('鹖鴠不鸣', $lunar->getWuHou()); } public function test8() { $solar = Solar::fromYmd(2020, 12, 11); $lunar = $solar->getLunar(); $this->assertEquals('鹖鴠不鸣', $lunar->getWuHou()); } public function test9() { $solar = Solar::fromYmd(1982,12,22); $lunar = $solar->getLunar(); $this->assertEquals('蚯蚓结', $lunar->getWuHou()); } public function test15() { $solar = Solar::fromYmd(2022,8,22); $lunar = $solar->getLunar(); $this->assertEquals('寒蝉鸣', $lunar->getWuHou()); } public function test16() { $solar = Solar::fromYmd(2022,8,23); $lunar = $solar->getLunar(); $this->assertEquals('鹰乃祭鸟', $lunar->getWuHou()); } } test/XingZuoTest.php 0000644 00000005616 14641217602 0010512 0 ustar 00 assertEquals('白羊', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 4, 19); $this->assertEquals('白羊', $solar->getXingZuo()); } public function test2() { $solar = Solar::fromYmd(2020, 4, 20); $this->assertEquals('金牛', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 5, 20); $this->assertEquals('金牛', $solar->getXingZuo()); } public function test3() { $solar = Solar::fromYmd(2020, 5, 21); $this->assertEquals('双子', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 6, 21); $this->assertEquals('双子', $solar->getXingZuo()); } public function test4() { $solar = Solar::fromYmd(2020, 6, 22); $this->assertEquals('巨蟹', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 7, 22); $this->assertEquals('巨蟹', $solar->getXingZuo()); } public function test5() { $solar = Solar::fromYmd(2020, 7, 23); $this->assertEquals('狮子', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 8, 22); $this->assertEquals('狮子', $solar->getXingZuo()); } public function test6() { $solar = Solar::fromYmd(2020, 8, 23); $this->assertEquals('处女', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 9, 22); $this->assertEquals('处女', $solar->getXingZuo()); } public function test7() { $solar = Solar::fromYmd(2020, 9, 23); $this->assertEquals('天秤', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 10, 23); $this->assertEquals('天秤', $solar->getXingZuo()); } public function test8() { $solar = Solar::fromYmd(2020, 10, 24); $this->assertEquals('天蝎', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 11, 22); $this->assertEquals('天蝎', $solar->getXingZuo()); } public function test9() { $solar = Solar::fromYmd(2020, 11, 23); $this->assertEquals('射手', $solar->getXingZuo()); $solar = Solar::fromYmd(2020, 12, 21); $this->assertEquals('射手', $solar->getXingZuo()); } public function test10() { $solar = Solar::fromYmd(2020, 12, 22); $this->assertEquals('摩羯', $solar->getXingZuo()); $solar = Solar::fromYmd(2021, 1, 19); $this->assertEquals('摩羯', $solar->getXingZuo()); } public function test11() { $solar = Solar::fromYmd(2021, 1, 20); $this->assertEquals('水瓶', $solar->getXingZuo()); $solar = Solar::fromYmd(2021, 2, 18); $this->assertEquals('水瓶', $solar->getXingZuo()); } public function test12() { $solar = Solar::fromYmd(2021, 2, 19); $this->assertEquals('双鱼', $solar->getXingZuo()); $solar = Solar::fromYmd(2021, 3, 20); $this->assertEquals('双鱼', $solar->getXingZuo()); } } test/YearTest.php 0000644 00000003514 14641217602 0010002 0 ustar 00 assertEquals('2019', $year->toString()); $this->assertEquals('2019年', $year->toFullString()); $this->assertEquals('2020', $year->next(1)->toString()); $this->assertEquals('2020年', $year->next(1)->toFullString()); } public function test2() { $year = LunarYear::fromYear(2017); $this->assertEquals('二龙治水', $year->getZhiShui()); $this->assertEquals('二人分饼', $year->getFenBing()); } public function test3() { $year = LunarYear::fromYear(2018); $this->assertEquals('二龙治水', $year->getZhiShui()); $this->assertEquals('八人分饼', $year->getFenBing()); } public function test4() { $year = LunarYear::fromYear(5); $this->assertEquals('三龙治水', $year->getZhiShui()); $this->assertEquals('一人分饼', $year->getFenBing()); } public function test5() { $year = LunarYear::fromYear(2021); $this->assertEquals('十一牛耕田', $year->getGengTian()); } public function test6() { $year = LunarYear::fromYear(2018); $this->assertEquals('三日得金', $year->getDeJin()); } public function test7() { $year = LunarYear::fromYear(2023); $this->assertEquals(384, $year->getDayCount()); } public function test8() { $year = LunarYear::fromYear(2021); $this->assertEquals(354, $year->getDayCount()); } public function test9() { $year = LunarYear::fromYear(2022); $this->assertEquals(355, $year->getDayCount()); } public function test10() { $year = LunarYear::fromYear(1518); $this->assertEquals(355, $year->getDayCount()); } } test/YunTest.php 0000644 00000005124 14641217602 0007654 0 ustar 00 getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYun(0); $this->assertEquals(8, $yun->getStartYear()); $this->assertEquals(0, $yun->getStartMonth()); $this->assertEquals(20, $yun->getStartDay()); $this->assertEquals('1989-02-18', $yun->getStartSolar()->toYmd()); } public function test2() { $lunar = Lunar::fromYmdHms(2019, 12, 12, 11, 22, 0); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYun(1); $this->assertEquals(0, $yun->getStartYear()); $this->assertEquals(1, $yun->getStartMonth()); $this->assertEquals(0, $yun->getStartDay()); $this->assertEquals('2020-02-06', $yun->getStartSolar()->toYmd()); } public function test3() { $solar = Solar::fromYmdHms(2020, 1, 6, 11, 22, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYun(1); $this->assertEquals(0, $yun->getStartYear()); $this->assertEquals(1, $yun->getStartMonth()); $this->assertEquals(0, $yun->getStartDay()); $this->assertEquals('2020-02-06', $yun->getStartSolar()->toYmd()); } public function test4() { $solar = Solar::fromYmdHms(2022, 3, 9, 20, 51, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYun(1); $this->assertEquals('2030-12-19', $yun->getStartSolar()->toYmd()); } public function test5() { $solar = Solar::fromYmdHms(2022, 3, 9, 20, 51, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYunBySect(1, 2); $this->assertEquals(8, $yun->getStartYear()); $this->assertEquals(9, $yun->getStartMonth()); $this->assertEquals(2, $yun->getStartDay()); $this->assertEquals('2030-12-12', $yun->getStartSolar()->toYmd()); } public function test6() { $solar = Solar::fromYmdHms(2018, 6, 11, 9, 30, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYunBySect(0, 2); $this->assertEquals('2020-03-21', $yun->getStartSolar()->toYmd()); } public function test7() { $solar = Solar::fromYmdHms(1984, 12, 25, 20, 30, 0); $lunar = $solar->getLunar(); $eightChar = $lunar->getEightChar(); $yun = $eightChar->getYun(0); $this->assertEquals('1991-03-07', $yun->getStartSolar()->toYmd()); } }