The SunCalc module allows to calculate sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for the given location and time.
SunCalc was ported to Haxe by Robin ypid
Schneider to allow using it in a planed rewrite of the opening hours library.
It is based on the JavaScript implementation created by Vladimir Agafonkin (@mourner) as a part of the SunCalc.net project.
Most calculations are based on the formulas given in the excellent Astronomy Answers articles about position of the sun and the planets. You can read about different twilight phases calculated by SunCalc in the Twilight article on Wikipedia.
Refer to the API documentation for details.
Install the library for your favorite language by executing one of the following commands:
haxelib install suncalc # Haxe
npm install suncalc # JavaScript/Node.JS
composer require ypid/suncalc # PHP
Check out the following example to get started.
## Needed when executed in the root of this repository.
require_once __DIR__ . '/lib/php/Boot.class.php';
## Needed when installed via composer. FIXME
# require_once __DIR__ . '/vendor/ypid/suncalc/lib/php/Boot.class.php';
echo suncalc_SunCalc::getMoonIllumination(new Date(2000, 1, 1, 0, 0, 0));
Maintainer/tester with PHP knowledge wanted 😉
Composer does provide a autoload feature which is currently not used. My experience with PHP is very limited which is the reason I wrote in Haxe and generated this PHP target only because all unit tests for PHP passed. If you know how to properly support the autoload feature for this library, I will be happy to integrate it.
This library was automatically build using Haxe to target PHP.
Refer to https://github.com/ypid/suncalc when you want to contribute. Note that you should only report issues against the PHP target repository when you think the issue only occurs in the PHP port of this library. If you are unsure, report against the source repository instead.
Unit testing is done against the source repository in Haxe, as well as against each transcompile target (PHP in this case). You can check them out in the source repository.
- Robin Schneider, role: Maintainer, Rewrite in Haxe