PHPackages                             ypid/suncalc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ypid/suncalc

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ypid/suncalc
============

Calculate sun position, sunlight phases, moon position and lunar phase.

v1.7.0(10y ago)11.7k↑33.9%2[1 issues](https://github.com/ypid/suncalc-php/issues)BSD-2-ClausePHP

Since Dec 12Pushed 8y ago2 watchersCompare

[ Source](https://github.com/ypid/suncalc-php)[ Packagist](https://packagist.org/packages/ypid/suncalc)[ Docs](https://github.com/ypid/suncalc)[ RSS](/packages/ypid-suncalc/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

suncalc
=======

[](#suncalc)

[![Build Status](https://camo.githubusercontent.com/0d7505243e0020231128f6e54d333bbb4b6b9ce6207ba6e677c944aa895f4b50/68747470733a2f2f7472617669732d63692e6f72672f797069642f73756e63616c632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ypid/suncalc)[![BSD licensed](https://camo.githubusercontent.com/2b599ab1ace97388d4375b87919f92781a1a61d016fe640a5c4d15fc365deed1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d626c75652e737667)](https://tldrlegal.com/license/bsd-2-clause-license-%28freebsd%29)[![haxelib version](https://camo.githubusercontent.com/c6004e8123cce4e8e68dbe3ce6610373377e12fa3cd45ebf369c95830b4dd3f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f486178652d76312e372e302d626c75652e737667)](https://lib.haxe.org/p/suncalc)[![NPM version](https://camo.githubusercontent.com/3dc1e760afd5150b2e389dbe63d4b516cd458190f5bf3675c53697e0e34b8bb3/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f73756e63616c632e737667)](https://www.npmjs.org/package/suncalc)[![Packagist version](https://camo.githubusercontent.com/f001150dc06650e3d54a756fc4492e4c96d9b28504a5c37dd5116ffe3e9a0b73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f797069642f73756e63616c632e737667)](https://packagist.org/packages/ypid/suncalc)

[![GitHub stars](https://camo.githubusercontent.com/baecfbbe5e522b85cde1c9546a58789cc89e97fc05a8f74860609bc5a8337e5d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f797069642f73756e63616c632d7068702e7376673f7374796c653d736f6369616c266c6162656c3d53746172266d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/stargazers)[![GitHub forks](https://camo.githubusercontent.com/e9b572107a83959ab0480ec74959b7d2a52e7472edfc48db6a03849f230dd865/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f797069642f73756e63616c632d7068702e7376673f7374796c653d736f6369616c266c6162656c3d466f726b266d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/network)[![GitHub watchers](https://camo.githubusercontent.com/12d28f85ad9700bc0d7a529bb04185250b3999fd3865a114fe54277f784d2299/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f797069642f73756e63616c632d7068702e7376673f7374796c653d736f6369616c266c6162656c3d5761746368266d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/watchers)[![GitHub open issues](https://camo.githubusercontent.com/6f1e7a318a44c006328ae6915cf298b6caf3853161401848a4c4c06ca831e632/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f797069642f73756e63616c632d7068702e7376673f266d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/issues)[![GitHub closed issues](https://camo.githubusercontent.com/202b43928d58efe61107f89eee4a9e328ee281dfa4f512573c93e3db8abb9110/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d636c6f7365642d7261772f797069642f73756e63616c632d7068702e7376673f6d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/issues?q=is%3Aissue+is%3Aclosed)[![GitHub open pull requests](https://camo.githubusercontent.com/d9fb6af6a8047c16ba581d397d9861ce76fcfc0f69bbbe865c57d8f1a65fedd7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722d7261772f797069642f73756e63616c632d7068702e7376673f266d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/pulls)[![GitHub closed pull requests](https://camo.githubusercontent.com/a47519aa80cb59df67c2bc723db7b3b632c7f78764f38fc18c9838ccf189c35d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722d636c6f7365642d7261772f797069642f73756e63616c632d7068702e7376673f266d61784167653d32353932303030)](https://github.com/ypid/suncalc-php/pulls?q=is%3Apr+is%3Aclosed)

[![PHPPackages Rank](https://camo.githubusercontent.com/11ea3dfbc33e77f31c204763c1fe2d7b49a81c6ffdc1f13924c691071639950f/68747470733a2f2f7068707061636b616765732e6f72672f702f797069642f73756e63616c632f62616467652f72616e6b2e737667)](https://phppackages.org/p/ypid/suncalc)[![PHPPackages Referenced By](https://camo.githubusercontent.com/87d70cd91fe91ae9c1190a4ff4e60b4099d7a6f17351012d745845c0e2e471e8/68747470733a2f2f7068707061636b616765732e6f72672f702f797069642f73756e63616c632f62616467652f7265666572656e6365642d62792e737667)](https://phppackages.org/p/ypid/suncalc)[![Packagist monthly downloads](https://camo.githubusercontent.com/e240969cd8b933720773e476bedb478b5887f38a55b2f0fd0d87ef06eec310fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f797069642f73756e63616c632e737667)](https://packagist.org/packages/ypid/suncalc)[![Packagist daily downloads](https://camo.githubusercontent.com/6e6d7e0b31e416d03149ef496353110c5938d303b1876c881da6d1dd6e60f3a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f797069642f73756e63616c632e737667)](https://packagist.org/packages/ypid/suncalc)[![Packagist total downloads](https://camo.githubusercontent.com/8734726ed91a3758fe6318b56567d4208dac660f87e457dfada28c827fa8a39b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f797069642f73756e63616c632e737667)](https://packagist.org/packages/ypid/suncalc)

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](https://en.wikipedia.org/wiki/Haxe) by [Robin `ypid` Schneider](https://github.com/ypid) to allow using it in a [planed rewrite of the opening hours library](https://github.com/opening-hours/opening_hours.js/issues/136).

It is based on the [JavaScript implementation](https://github.com/mourner/suncalc)created by [Vladimir Agafonkin](http://agafonkin.com/en) ([@mourner](https://github.com/mourner)) as a part of the [SunCalc.net project](http://suncalc.net).

Most calculations are based on the formulas given in the excellent Astronomy Answers articles about [position of the sun](http://aa.quae.nl/en/reken/zonpositie.html)and [the planets](http://aa.quae.nl/en/reken/hemelpositie.html). You can read about different twilight phases calculated by SunCalc in the [Twilight article on Wikipedia](https://en.wikipedia.org/wiki/Twilight).

Refer to the [API documentation](https://ypid.github.io/suncalc/suncalc/SunCalc.html) for details.

Install
-------

[](#install)

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
```

Getting started
---------------

[](#getting-started)

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));
```

TODO
----

[](#todo)

Maintainer/tester with PHP knowledge wanted 😉

Composer does provide a [autoload feature](https://getcomposer.org/doc/04-schema.md#autoload) 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.

Internals
---------

[](#internals)

This library was automatically build using [Haxe](http://haxe.org/) to target PHP.

Refer to  when you want to contribute. Note that you should only report issues against [the PHP target repository](https://github.com/ypid/suncalc-php) when you think the issue only occurs in the PHP port of this library. If you are unsure, report [against the source repository](https://github.com/ypid/suncalc) instead.

Unit testing
------------

[](#unit-testing)

Unit testing is done [against the source repository](https://github.com/ypid/suncalc) in Haxe, as well as against each transcompile target (PHP in this case). You can check them out in the [source repository](https://github.com/ypid/suncalc).

Maintainer
----------

[](#maintainer)

- [Robin Schneider](http://ypid.de/), role: Maintainer, Rewrite in Haxe

License
-------

[](#license)

[BSD-2-Clause](https://tldrlegal.com/license/bsd-2-clause-license-%28freebsd%29)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3856d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1301158?v=4)[Robin Schneider](/maintainers/ypid)[@ypid](https://github.com/ypid)

---

Top Contributors

[![ypid](https://avatars.githubusercontent.com/u/1301158?v=4)](https://github.com/ypid "ypid (22 commits)")

---

Tags

sunmoonastronomy

### Embed Badge

![Health badge](/badges/ypid-suncalc/health.svg)

```
[![Health](https://phpackages.com/badges/ypid-suncalc/health.svg)](https://phpackages.com/packages/ypid-suncalc)
```

###  Alternatives

[athlon1600/youtube-downloader

PHP powered alternative for youtube-dl

926163.7k13](/packages/athlon1600-youtube-downloader)[solaris/php-moon-phase

Calculate the phases of the Moon in PHP.

16671.1k1](/packages/solaris-php-moon-phase)[spatie/sun

Get information on the position of the sun

75181.3k3](/packages/spatie-sun)[coreproc/msisdn-ph

An MSISDN identification and cleaner library for Philippine telco subscribers

2829.1k4](/packages/coreproc-msisdn-ph)[sun/country

Sun Country is the package that helps you to get the country name &amp; dialing code by the country ISO 3166-1 Alpha-2 code.

1016.8k](/packages/sun-country)[andkirby/modman-generator

Simple script which helps generate modman file based update "git ls-files" command.

151.4k1](/packages/andkirby-modman-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
