Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including calculation-ofsun with all npm packages installed. Try it out:

var calculationOfsun = require("calculation-ofsun")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

calculation-ofsun v1.0.3

Sun calculation based on formula from

Calculation of sun

Inline docs npm version contributions welcome HitCount
Sun calculation fully based on formula from


This program is not really accurate about the calculation. For the sunrise and sunset, the error value is about 2 minutes miss from the actual time. For the Altitude the error value is near 0.6 degrees and the azimuth as well.

Install with npm

npm install calculation-ofsun

Without npm

  1. Clone this project
  2. Create your new js file
  3. Import the solar-calculation.js to your code. You could find the script in dist directory
  4. Then, have fun


If you didn't understand what I'm saying about how to use it without npm. You could check the main.js. That's it.

How to Use It

    const cls = require('calculation-ofsun')
    console.log(cls.getSunInformation(new Date(), 33, 3))
    /* Get Sun Information expected 3 parameters */
    /* Date, lat, long */
    /* For the other function and it's parameter. You could check on the table below */

How to use another functions that require juliandate as the parameter

    const cls = require('calculation-ofsun');
    const myJD = cls.dateToJD(new Date());
    const lw = -96.555324
    console.log(cls.solarTransit(myJD, lw));

You can also call any function except getSunPosition, because it automatically calls by the getSunInformation function to get sun position according to your input parameters for getSunInformation.

Functions parameter

Function NameExpected Parameter
getSunInformationDate, latitude, longtitude
sideraltimeJulianDate, West Longitude
getHourAngleJulianDate, West Longitude
getSunPositionNone, Dont use it
solarTransitJulianDate. West Longitude
sunriseandsunsetJulianDate, Latitude, Longitude

Example of return object from getSunInformation functions

Nethereland GMT +1 It'll return time denpend on your local time

{   sun_position: { 
        azimuth: -101.53872252647008, 
        altitude: 57.268164438252526 
    date: 'Sat Apr 14 2018 10:16:32 GMT+0700 (WIB)',
    observe_location: { 
        latitude: 3.597031, 
        longitude: 98.678513
    sunrise: 'Sat Apr 14 2018 06:21:42 GMT+0700 (WIB)',
    sunset: 'Sat Apr 14 2018 18:32:54 GMT+0700 (WIB)',
    solar_transit: 2458222.7272965494,
    hour_angle: 327.53679257420777,
        {   degrees: 22.060782554336377, 
            rad: 0.38503329113969464 
    clientJD: 2458222.6364905904 


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free