php-moon-phase

A PHP Class for calculating the phase of the moon, and other related variables.

  • 所有者: BitAndBlack/php-moon-phase
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

A PHP class for calculating the phase of the Moon.

MoonPhase is a PHP class for calculating the phase of the Moon, and other related variables. It is based on Moontool for Windows.

Installation

MoonPhase is available on Packagist (solaris/php-moon-phase)
and can be installed using Composer. Alternatively you can grab the code directly from GitHub and include the MoonPhase.php script directly or via a PSR-0 autoloader.

Usage

Create an instance of the Solaris\MoonPhase class, supplying a UNIX timestamp for when you want to determine the moon phase (if you don't then the current time will be used). You can then use the following class functions to access the properties of the object:

  • phase(): the terminator phase angle as a fraction of a full circle (i.e., 0 to 1). Both 0 and 1 correspond to a New Moon, and 0.5 corresponds to a Full Moon.
  • get('illumination'): the illuminated fraction of the Moon (0 = New, 1 = Full).
  • get('age'): the age of the Moon, in days.
  • get('distance'): the distance of the Moon from the centre of the Earth (kilometres).
  • get('diameter'): the angular diameter subtended by the Moon as seen by an observer at the centre of the Earth (degrees).
  • get('sundistance'): the distance to the Sun (kilometres).
  • get('sundiameter'): the angular diameter subtended by the Sun as seen by an observer at the centre of the Earth (degrees).
  • get_phase('new_moon'): the time of the last New Moon (UNIX timestamp).
  • get_phase('next_new_moon'): the time of the next New Moon (UNIX timestamp).
  • get_phase('full_moon'): the time of the Full Moon in the current lunar cycle (UNIX timestamp).
  • get_phase('next_full_moon'): the time of the next Full Moon in the current lunar cycle (UNIX timestamp).
  • get_phase('first_quarter'): the time of the first quarter in the current lunar cycle (UNIX timestamp).
  • get_phase('next_first_quarter'): the time of the next first quarter in the current lunar cycle (UNIX timestamp).
  • get_phase('last_quarter'): the time of the last quarter in the current lunar cycle (UNIX timestamp).
  • get_phase('next_last_quarter'): the time of the next last quarter in the current lunar cycle (UNIX timestamp).
  • phase_name(): the phase name.

Example

// create an instance of the class, and use the current time
$moon = new Solaris\MoonPhase();
$age = round($moon->get('age'), 1);
$stage = $moon->phase() < 0.5 ? 'waxing' : 'waning';
$distance = round($moon->get('distance'), 2);
$next = gmdate('G:i:s, j M Y', $moon->get_phase('next_new_moon'));
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.";

Help

For bugs/enhancements, feel free to either raise an issue or pull request in GitHub, or contact me.

主要指标

概览
名称与所有者BitAndBlack/php-moon-phase
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证Other
所有者活动
创建于2012-08-13 04:19:36
推送于2024-11-07 14:23:54
最后一次提交2024-11-07 15:23:45
发布数11
最新版本名称v3.2.0 (发布于 2024-11-07 15:23:52)
第一版名称v1.0.0 (发布于 2013-08-29 07:51:17)
用户参与
星数160
关注者数12
派生数45
提交数85
已启用问题?
问题数33
打开的问题数0
拉请求数10
打开的拉请求数0
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?