rik0253/moon-phase

根据给定的日期提供月相。

v1.0.4 2020-05-12 14:30 UTC

This package is auto-updated.

Last update: 2024-09-13 00:22:26 UTC


README

MoonPhase 是一个用于计算月亮相位及其他相关变量的 PHP 类。它基于 Windows 版 Moontool。月亮升起/落下时间基于 (https://dxprog.com/entry/calculate-moon-rise-and-set-in-php)。

安装

composer require rik0253/moon-phase

用法

通过 'new Moonphase('YYYY-MM-DD');' 创建类的实例,提供一个日期以确定所需的月相(如果没有提供,则使用当前时间)。然后可以使用以下类函数访问对象的属性

  • phase():获取终止线相位角作为完整圆的分数(即,0 到 1)。0 和 1 都对应新月,而 0.5 对应满月。
  • getMoonData('illumination'):获取月亮的照明部分(0 = 新月,1 = 满月)。
  • getMoonData('age'):获取月亮的年龄,以天为单位。
  • getMoonData('distance'):获取月亮与地球中心的距离(公里)。
  • getMoonData('diameter'):获取月亮在地球中心观察者眼中的角直径(度)。
  • getMoonData('sundistance'):获取到太阳的距离(公里)。
  • getMoonData('sundiameter'):获取太阳在地球中心观察者眼中的角直径(度)。
  • getPhaseData('new_moon'):获取上一次新月的日期(DateTime)。
  • getPhaseData('next_new_moon'):获取下一次新月的日期(DateTime)。
  • getPhaseData('full_moon'):获取当前农历周期中的满月时间(DateTime)。
  • getPhaseData('next_full_moon'):获取当前农历周期中下一次满月的时间(DateTime)。
  • getPhaseData('first_quarter'):获取当前农历周期的第一个季度时间(DateTime)。
  • getPhaseData('next_first_quarter'):获取当前农历周期中下一次第一个季度的时间(DateTime)。
  • getPhaseData('last_quarter'):获取当前农历周期的最后一个季度时间(DateTime)。
  • getPhaseData('next_last_quarter'):获取当前农历周期中下一次最后一个季度的时间(DateTime)。
  • getPhaseName():获取相位名称。

新用法

现在您可以通过获取对象的属性来获取月亮升起和落下的 Unix 时间戳。

  • getMoonTimes('latitude','longitude'):获取月亮升起和落下的时间(Unix 时间戳)。

示例

//create an instance of the class, and use the current time
$moon = new Moonphase('1990-04-21');
$age = round($moon->get('age'), 1);
$stage = $moon->phase() < 0.5 ? 'waxing' : 'waning';
$distance = round($moon->get('distance'), 2);
$next = $moon->getPhaseData('next_new_moon');
$phaseName = $moon->getPhaseName();
echo "The moon is currently $age days old, and is therefore $stage. ";
echo "It is $distance km from the centre of the Earth. ";
echo "The next new moon is at $next.";
//To get the moon rise/set time
$moonTime = getMoonTimes(22.5655,88.3653);
echo "Moon rise at ".date('Y-m-d H:i A',strtotime($moonTime->moonrise));	
echo "Moon set at ".date('Y-m-d H:i A',strtotime($moonTime->moonset));	

帮助

对于错误/增强功能,您可以在 GitHub 上提交问题或拉取请求,或者联系我