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

To install, run:

haxelib install suncalc 1.7.0 

See using Haxelib in Haxelib documentation for more information.


<!-- This file was generated by scripts/template. Do not edit this file directly but

 instead have a look at: metainfo.json, templates/ -->

Build Status NPM version PHP version

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.

The library was ported to Haxe by Robin ypid Schneider to allow using it in a library for opening hours.

It is based on the JavaScript implementation created by Vladimir Agafonkin (@mourner) as a part of the 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:

npm install suncalc             # JavaScript/Node.JS
composer require ypid/suncalc   # PHP

Supported languages/platforms

Supported languages/platforms not generated by Haxe


The following limitations seems to be related which should mean that when they are fixed for one target, the tests for the other targets should also pass. If you need SunCalc.getMoonTimes for one of those targets, feel free to debug it further.

  • Python: SunCalc.getMoonTimes (rise date can not be calculated.).
  • C++: SunCalc.getMoonTimes (segmentation fault).
  • Java: SunCalc.getMoonTimes (java.lang.NullPointerException).
  • Neko: SunCalc.getMoonTimes


  • ActionScript 3: Does compile but I have no idea how to test it.
  • Flash: Does compile but I have no idea how to test it.


  • C#: Dependency datetime does not compile on target "datetime/3,0,2/src/datetime/DateTime.hx:146: characters 28-110 : haxe.Int64 should be Float"

Priority low.



2 years ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser!

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github