lyyteam/huaxia-lunar-calendar

面向 PHP 8 的专业中国历法库:公历/农历/佛历/道历、24 节气(寿星天文历秒级)、四柱八字、大运流年、真太阳时与法定假日,零框架依赖,适用于 ThinkPHP/Laravel/任意 PHP 项目

Maintainers

Package info

github.com/lyyteam/huaxia-lunar-calendar

pkg:composer/lyyteam/huaxia-lunar-calendar

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-06-22 03:50 UTC

This package is auto-updated.

Last update: 2026-06-22 04:16:54 UTC


README

面向 PHP 8+ 的专业中国历法计算库。基于寿星天文历实现秒级节气,支持四柱八字、大运流年、真太阳时校正及法定假日查询,零框架依赖、零第三方 Composer 依赖,可嵌入 ThinkPHP、Laravel、Symfony 或任意 PHP 应用。

Tests PHP License

特性

  • 历法互转:公历、农历、佛历、道历
  • 节气精确:寿星天文历 ShouXingUtil,交接时刻秒级
  • 八字命理:四柱 EightChar、大运 Yun / DaYun、流年 LiuNian、流月 LiuYue
  • 流派支持:晚子时 sect1/2、起运 sect1/2 可分离配置
  • 真太阳时:经度校正 + 同源均时差 + 1986–1991 夏令时
  • 民俗辅助:法定假日、三伏数九、星座、城市经度库
  • 专业验证:2424 项节气双锁、5600+ 属性断言、HKO 外部对照,详见 ACCURACY.md

源码仓库: https://github.com/lyyteam/huaxia-lunar-calendar

安装

composer require lyyteam/huaxia-lunar-calendar:^1.0

尚未发布到 Packagist 时,可添加 VCS 仓库:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/lyyteam/huaxia-lunar-calendar"
        }
    ],
    "require": {
        "lyyteam/huaxia-lunar-calendar": "^1.0"
    }
}

快速开始

<?php
declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use Lyyteam\HuaxiaLunar\Calendar;
use Lyyteam\HuaxiaLunar\Solar;

// 公历 → 农历
$solar = Calendar::solar(2025, 6, 11);
echo $solar->getLunar()->toString();

// 农历 → 公历(闰月用负数,如闰四月为 -4)
$lunar = Calendar::lunar(1986, 4, 21);
echo $lunar->getSolar()->toYmd();

// 四柱八字
$solar = Solar::fromYmdHms(2005, 12, 23, 8, 37, 0);
$eightChar = $solar->getLunar()->getEightChar();
echo $eightChar->getYear(), $eightChar->getMonth(), $eightChar->getDay(), $eightChar->getTime();

命名空间 Lyyteam\HuaxiaLunar,PSR-4 自动加载。

主要模块

模块 说明
入口 Calendar 快捷创建公历/农历对象
公历 SolarSolarYearSolarMonth 公历日期及推算
农历 LunarLunarYearLunarMonth 农历转换与推算
八字 EightCharYunDaYunLiuNian 四柱、大运、流年流月
节气 JieQi 24 节气查询
工具 Util\ShouXingUtilHolidayUtilTrueSolarUtil 天文历、假日、真太阳时

开发与测试

composer install
composer test

许可证

MIT License