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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?