Git Product home page Git Product logo

php-moon-phase's Introduction

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.
  • illumination(): the illuminated fraction of the Moon (0 = New, 1 = Full).
  • age(): the age of the Moon, in days.
  • distance(): the distance of the Moon from the centre of the Earth (kilometres).
  • diameter(): the angular diameter subtended by the Moon as seen by an observer at the centre of the Earth (degrees).
  • sundistance(): the distance to the Sun (kilometres).
  • sundiameter(): the angular diameter subtended by the Sun as seen by an observer at the centre of the Earth (degrees).
  • new_moon(): the time of the last New Moon (UNIX timestamp).
  • next_new_moon(): the time of the next New Moon (UNIX timestamp).
  • full_moon(): the time of the Full Moon in the current lunar cycle (UNIX timestamp).
  • first_quarter(): the time of the first quarter in the current lunar cycle (UNIX timestamp).
  • last_quarter(): the time of the 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->age(), 1 );
$stage = $moon->phase() < 0.5 ? 'waxing' : 'waning';
$distance = round( $moon->distance(), 2 );
$next = gmdate( 'G:i:s, j M Y', $moon->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.

php-moon-phase's People

Contributors

solarissmoke avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.