Coder Social home page Coder Social logo

suncalc's Introduction

SunCalc

Build Status

SunCalc is a tiny BSD-licensed JavaScript library for calculating sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for the given location and time, 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.

Usage example

// get today's sunlight times for London
var times = SunCalc.getTimes(new Date(), 51.5, -0.1);

// format sunrise time from the Date object
var sunriseStr = times.sunrise.getHours() + ':' + times.sunrise.getMinutes();

// get position of the sun (azimuth and altitude) at today's sunrise
var sunrisePos = SunCalc.getPosition(times.sunrise, 51.5, -0.1);

// get sunrise azimuth in degrees
var sunriseAzimuth = sunrisePos.azimuth * 180 / Math.PI;

SunCalc is also available as an NPM package:

$ npm install suncalc
var SunCalc = require('suncalc');

Reference

Sunlight times

SunCalc.getTimes(/*Date*/ date, /*Number*/ latitude, /*Number*/ longitude, /*Number (default=0)*/ height)

Returns an object with the following properties (each is a Date object):

Property Description
sunrise sunrise (top edge of the sun appears on the horizon)
sunriseEnd sunrise ends (bottom edge of the sun touches the horizon)
goldenHourEnd morning golden hour (soft light, best time for photography) ends
solarNoon solar noon (sun is in the highest position)
goldenHour evening golden hour starts
sunsetStart sunset starts (bottom edge of the sun touches the horizon)
sunset sunset (sun disappears below the horizon, evening civil twilight starts)
dusk dusk (evening nautical twilight starts)
nauticalDusk nautical dusk (evening astronomical twilight starts)
night night starts (dark enough for astronomical observations)
nadir nadir (darkest moment of the night, sun is in the lowest position)
nightEnd night ends (morning astronomical twilight starts)
nauticalDawn nautical dawn (morning nautical twilight starts)
dawn dawn (morning nautical twilight ends, morning civil twilight starts)
SunCalc.addTime(/*Number*/ angleInDegrees, /*String*/ morningName, /*String*/ eveningName)

Adds a custom time when the sun reaches the given angle to results returned by SunCalc.getTimes.

SunCalc.times property contains all currently defined times.

Sun position

SunCalc.getPosition(/*Date*/ timeAndDate, /*Number*/ latitude, /*Number*/ longitude)

Returns an object with the following properties:

  • altitude: sun altitude above the horizon in radians, e.g. 0 at the horizon and PI/2 at the zenith (straight over your head)
  • azimuth: sun azimuth in radians (direction along the horizon, measured from south to west), e.g. 0 is south and Math.PI * 3/4 is northwest

Moon position

SunCalc.getMoonPosition(/*Date*/ timeAndDate, /*Number*/ latitude, /*Number*/ longitude)

Returns an object with the following properties:

  • altitude: moon altitude above the horizon in radians
  • azimuth: moon azimuth in radians
  • distance: distance to moon in kilometers
  • parallacticAngle: parallactic angle of the moon in radians

Moon illumination

SunCalc.getMoonIllumination(/*Date*/ timeAndDate)

Returns an object with the following properties:

  • fraction: illuminated fraction of the moon; varies from 0.0 (new moon) to 1.0 (full moon)
  • phase: moon phase; varies from 0.0 to 1.0, described below
  • angle: midpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk; the moon is waxing if the angle is negative, and waning if positive

Moon phase value should be interpreted like this:

Phase Name
0 New Moon
Waxing Crescent
0.25 First Quarter
Waxing Gibbous
0.5 Full Moon
Waning Gibbous
0.75 Last Quarter
Waning Crescent

By subtracting the parallacticAngle from the angle one can get the zenith angle of the moons bright limb (anticlockwise). The zenith angle can be used do draw the moon shape from the observers perspective (e.g. moon lying on its back).

Moon rise and set times

SunCalc.getMoonTimes(/*Date*/ date, /*Number*/ latitude, /*Number*/ longitude[, inUTC])

Returns an object with the following properties:

  • rise: moonrise time as Date
  • set: moonset time as Date
  • alwaysUp: true if the moon never rises/sets and is always above the horizon during the day
  • alwaysDown: true if the moon is always below the horizon

By default, it will search for moon rise and set during local user's day (frou 0 to 24 hours). If inUTC is set to true, it will instead search the specified date from 0 to 24 UTC hours.

Changelog

1.8.0 — Dec 22, 2016

  • Improved precision of moonrise/moonset calculations.
  • Added parallacticAngle calculation to getMoonPosition.
  • Default to today's date in getMoonIllumination.
  • Fixed incompatibility when using Browserify/Webpack together with a global AMD loader.

1.7.0 — Nov 11, 2015

  • Added inUTC argument to getMoonTimes.

1.6.0 — Oct 27, 2014

  • Added SunCalc.getMoonTimes for calculating moon rise and set times.

1.5.1 — May 16, 2014

  • Exposed SunCalc.times property with defined daylight times.
  • Slightly improved SunCalc.getTimes performance.

1.4.0 — Apr 10, 2014

  • Added phase to SunCalc.getMoonIllumination results (moon phase).
  • Switched from mocha to tape for tests.

1.3.0 — Feb 21, 2014

  • Added SunCalc.getMoonIllumination (in place of getMoonFraction) that returns an object with fraction and angle (angle of illuminated limb of the moon).

1.2.0 — Mar 07, 2013

  • Added SunCalc.getMoonFraction function that returns illuminated fraction of the moon.

1.1.0 — Mar 06, 2013

  • Added SunCalc.getMoonPosition function.
  • Added nadir (darkest time of the day, middle of the night).
  • Added tests.

1.0.0 — Dec 07, 2011

  • Published to NPM.
  • Added SunCalc.addTime function.

0.0.0 — Aug 25, 2011

  • First commit.

suncalc's People

Contributors

brettz9 avatar fabiz avatar jazzzz avatar mourner avatar mpetroff avatar nikolas avatar ryanp54 avatar tylershuster avatar victorthompson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

suncalc's Issues

Wrong azimuth angle

Sorry but i find that the sun azimuth must plus 180 degree so:
function getAzimuth(H, phi, dec) {
return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi));
}

must be:
function getAzimuth(H, phi, dec) {
return PI + atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi));
}

Exact semantics of sun times?

Hi @mourner! I had another question regarding your excellent SunCalc library. (Hopefully, this time you won't need to write any code or publish a new version of the library ;) )

Right now, in our weather API, we try to generate sunrise and sunset times for each day, when a user requests daily weather data. The way we do this is very simplistic, and perhaps best illustrated by the following example:

var SunCalc = require("suncalc");

function solar_times(midnight_today, midnight_tomorrow, lat, lon) {
  var noon_today   = new Date(midnight_today.getTime() + 43200000.0),
      sun_times    = SunCalc.getTimes(noon_today, lat, lon),
      sunrise_time = null,
      sunset_time  = null;

  /* Make sure sunrise occurs today! */
  if(sun_times.sunrise.getTime() >= midnight_today.getTime() &&
     sun_times.sunrise.getTime() <  midnight_tomorrow.getTime())
    sunrise_time = sun_times.sunrise;

  /* Make sure sunset occurs today! */
  if(sun_times.sunset.getTime() >= midnight_today.getTime() &&
     sun_times.sunset.getTime() <  midnight_tomorrow.getTime())
    sunset_time = sun_times.sunset;

  return {sunrise: sunrise_time, sunset: sunset_time};
}

console.log(solar_times(
  /* kangaroo-rat:~ jason$ TZ=America/Anchorage date -j -f %s 1401436800
   * Fri May 30 00:00:00 AKDT 2014 */
  new Date(1401436800000.0),

  /* kangaroo-rat:~ jason$ TZ=America/Anchorage date -j -f %s 1401523200
   * Sat May 31 00:00:00 AKDT 2014 */
  new Date(1401523200000.0),

  /* Fairbanks, AK. */
  64.8283644, -147.6690026
));
/* { sunrise: Fri May 30 2014 07:38:49 GMT-0400 (EDT),
 *   sunset: null } */

That is, we call SunCalc.getTimes for noon on the given day (since we'd expect to get the "nearest" sunrise and sunset times); however, this ends up giving us a sunset date on a different day, and so our API returns nothing. Oops.

Since the documentation doesn't make it explicit, I was wondering if you could explain how SunCalc decides which sunrise and sunset times it should return? Is there a simple way I could get the sunrise and sunset times that occur within a given 24 hour period (perhaps by making two calls to SunCalc)?

Thanks a bunch!
Jay

NPM Install Issue

Hi,

this is the only package I'm having issues downloading on NPM

Pretty sure this isn't a connection issue.

I'm trying to download the package 'suncalc' and I'm getting a 404 error.

Link to the Package

log:

npm http GET https://registry.npmjs.org/suncalc
npm http 304 https://registry.npmjs.org/suncalc
npm http GET https://registry.npmjs.org/suncalc/-/suncalc-1.5.1.tgz
npm http 404 https://registry.npmjs.org/suncalc/-/suncalc-1.5.1.tgz
npm ERR! fetch failed https://registry.npmjs.org/suncalc/-/suncalc-1.5.1.tgz
npm ERR! Error: 404 Not Found
npm ERR!     at WriteStream.<anonymous> (/usr/local/Cellar/node/0.10.26/lib/node_modules/npm/lib/utils/fetch.js:57:12)
npm ERR!     at WriteStream.EventEmitter.emit (events.js:117:20)
npm ERR!     at fs.js:1598:14
npm ERR!     at /usr/local/Cellar/node/0.10.26/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:105:5
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

MoonCalc?

Awesome library! Did you ever get anywhere with MoonCalc (position, lunar phase, etc)?

Official Minified Version

This would be a nice feature, especially for bower users. Also, some minifiers can cause bugs and corruptions in the code so an official tested version would ensure maximum ensured compatibility. UglifyJS2 is the most popular right now, but the YUI Compressor, JSmin, and Google Closure are also options.

Feature request: Return time for sun at a particular azimuth

Hi love the module - Have my lights turning on and off at the rights time using my Ninja Blocks driver https://github.com/chrisn-au/ninja_timeofday

Would love to go one step further and optimise my solar pool heating costs by having the pump turned on at the most effective times based on Azimuth.

SunCalc.getTimeforAzimuth(/Date/ Date, /* Number _/ azimuth, /Number/ latitude, /_Number*/ longitude)

I could always do it myself but if it is easy :-)

Thanks again for an awesome module

Adding sun position for mid-afternoon

Thanks for the great module. I am looking at the different results that come in the calculation and wished to add one data point. Is it possible to know the time when the sun would create a shadow of equal height as the object it's self (example: a 1 meter tall stick in the ground creates a 1 meter long shadow)?

moonTimes tests fail

Tests 23 and 24 fail.

getMoonTimes returns moon rise and set times

not ok 23 should be equal


operator: equal
expected: 'Mon, 04 Mar 2013 23:57:55 GMT'
actual:   'Mon, 04 Mar 2013 23:57:52 GMT'
at: Test.<anonymous> (/devel/suncalc/test.js:68:7)

...
not ok 24 should be equal


operator: equal
expected: 'Tue, 05 Mar 2013 08:41:31 GMT'
actual:   'Mon, 04 Mar 2013 07:19:22 GMT'
at: Test.<anonymous> (/devel/suncalc/test.js:69:7)

...

Validity of the constants

Thanks for creating such great program. I would like to know:

  1. What is the accuracy of the constants?
  2. where can we find the up-to-date values of constants so that we can update them year by year?

npm retrieval error

Any idea why I'd be getting this error when including a dependency on suncalc (whether I specify 1.x , 1.5.1, etc.)?

156 error fetch failed https://registry.npmjs.org/suncalc/-/suncalc-1.5.1.tgz

Report to npm?

moon rise error

Moon rise time returned undefined today.
Moon set is fine.

Times seem off?

I'm making a call to getTimes like below:

getTimes(new Date("5/13/15 23:53"), Number("-122.4258917"), Number("37.7745986"));

Which returns:

{  
   "solarNoon":"2015-05-14T09:26:36.756Z",
   "nadir":"2015-05-13T21:26:36.756Z",
   "sunrise":"2015-05-14T01:26:51.946Z",
   "sunset":"2015-05-14T17:26:21.566Z",
   "sunriseEnd":"2015-05-14T01:21:59.805Z",
   "sunsetStart":"2015-05-14T17:31:13.707Z",
   "dawn":"2015-05-14T02:11:28.048Z",
   "dusk":"2015-05-14T16:41:45.464Z",
   "nauticalDawn":"2015-05-14T02:59:20.761Z",
   "nauticalDusk":"2015-05-14T15:53:52.751Z",
   "nightEnd":"2015-05-14T03:45:00.407Z",
   "night":"2015-05-14T15:08:13.104Z",
   "goldenHourEnd":"2015-05-14T00:17:58.717Z",
   "goldenHour":"2015-05-14T18:35:14.795Z"
}

These times seem off - for example it has sunrise at 2015-05-14T01:26:51.946Z which I'm reading as 1:26 am (correct?). Similarly night is 2015-05-14T15:08:13.104Z aka 3pm?

Are the times returned for a specific time zone?

Incorrect moon rise/set times when Dec 31st

Hey,

I've just grabbed this library to do some day/night cycle stuff, and noticed an error when using getMoonTimes(). Code to reproduce is below (I've manually set the date and time since it might not be 31st December when you see this):

var suncalc = require( 'suncalc' );

var moonDate = new Date();
moonDate.setHours( 14 );
moonDate.setDate( 31 );
moonDate.setMonth( 11 );
moonDate.setYear( 2015 );

var moontimes = suncalc.getMoonTimes(
    moonDate,
    51.51, 
    -0.13
);

console.log( moontimes );

// Outputs:
//    { 
//      rise: Thu Dec 31 2015 10:59:33 GMT+0000 (GMT),
//      set: Thu Dec 31 2015 10:09:59 GMT+0000 (GMT) 
//    }

I think the rise time is out by 12 hours, and the rise and set times should exchange places?

Thanks for the lib, btw!

EDIT: Corrected moonDate.setDate to set 31st, not 30th! Apologies.

No night/end calculations for specific place and date

Following place and date give no "night/nightEnd"
http://suncalc.net/#/50.6252,12.9239,13/2015.06.01/23:29

Why?

00:00— n/a — night
n/a —03:16 — astronomical twilight
03:16—04:19 — nautical twilight
04:19—05:02 — civil twilight
05:02—05:07 — sunrise
05:07—21:07 — daylight
21:07—21:12 — sunset
21:12—21:55 — civil twilight
21:55—22:58 — nautical twilight
22:58— n/a — astronomical twilight
n/a —00:00 — night

How to get moon phase?

Hi there!

We use your excellent SunCalc library in Forecast and our weather API and love it. Thanks for your hard work!

I don't have a bug to report; just a question: what is the correct way to calculate the moon phase? (That is, I would like the percentage of the way through the current lunation cycle: 0%=new moon, 25%=first quarter moon, 50%=full moon, 75%=last quarter moon.)

I came up with the following function:

function phase(date) {
  var m = SunCalc.getMoonIllumination(date);
  return m.angle < 0.0 ? m.fraction * 50.0 : 100.0 - m.fraction * 50.0;
}

It's certainly simple, however, I'm not sure it's correct: I get the impression that the illuminated fraction of the lunar disk is a nonlinear value (due to the spherical shape of the moon), and thus treating it as a linear value above is flawed. (While it will return correct values at 0%, 25%, 50%, and 75%, I suspect it will be incorrect between those points. By how much, I'm not sure.)

My intuition is that I should simply be mapping the angle property (plus, perhaps, some offset) from 0..π to 0%..100%, but this doesn't seem to work. Am I misunderstanding that property?

Thanks for your help!
Jay LaPorte

How to convert sun azimuth degrees to degrees in circle?

This is not an issue, just a question, because my math is incredibly rusty. From the documentation, I noticed this will return the sun's azimuth in degrees:

var sunriseAzimuth = sunrisePos.azimuth * 180 / Math.PI;

My question is how to convert those degrees to a classic circle, where:

North: 0 degrees
East: 90 degrees
South: 180 degrees
West: 270 degrees

What I'm doing now is that I add 180 degrees to the value returned by the library, but I'm not confident this is correct, accurate or mathematically sound.

[object Object]

var datetime = new Date();
var latitude = 29.97;
var longitude = -90.1;

var sunPosition = SunCalc.getPosition(datetime, latitude, longitude);
var moon = SunCalc.getMoonIllumination(datetime);
document.write(sunPosition + "<br/>");
document.write(moon + "<br/>");

sunPosition and moon return [object Object] which is fine, but it should be easier for users to grab the variables. Maybe a library?

Moon Rise / Set is backwards ?

I am passing in my local time (PST) and GPS location (for Vancouver) and this is the object I am getting back for getMoonTimes():

Object {rise: Sat Feb 07 2015 04:28:44 GMT-0800 (PST), set: Sat Feb 07 2015 16:39:38 GMT-0800 (PST)}

How does this makes sense that the moon rises after 4am and sets at 4pm? I am looking outside and I can see the moon!

I think that these are being returned in the wrong order...

And... Thanks for the wonderful library!

Sunrise / Sunset during "midnight sun" in polar areas

I've run into an issue;

For instance, at latitude 66.017 by longitude 29.136 (Northern Finland) at unix timestamp 1434447174, the sun rises on June 11th and does not set at all until July 3rd (Polar region, midnight sun).

I would like to get the time for the last sunrise, and get the time for the first following sundown, or vice versa, in winter time.
However, I only seem to be able to get the first following sunrise and sunset for the day both those events are on the same day (June 10th and July 4th respectively).
Otherwise, both sunset and sunrise return NaN, while I (apparently wrongly) expected the module to return a timestamp for only a sunrise, and only a sunset.

Would you be willing to assist me with this, or, fix this to make suncalc an even greater product?

Daylight saving issue

I had an issue with the daylight saving and the Julian date conversion.

The library was working but all the results for the daylight saving period were offset by -1 day.

Without being an expert in date format transformation, replacing the toJulian method seems to fix it:

function toJulian(date) {
        return (date.getTime() / 86400000) - (date.getTimezoneOffset()/1440) + 2440587.5;
}

Ported to Haxe.

Hi

I just wanted to let you know that I have ported your library to Haxe: https://github.com/ypid/suncalc

Haxe allows to target multiple languages. The reason for this is that I want to rewrite opening_hours.js in Haxe.

If you plan on adding new features you now have the option to either implement them in Haxe or in JavaScript as Haxe can easily target js and your test.js is passing with the transcomipled version from Haxe. But you don’t have to do that. I am going to maintain the Haxe port and might port features/bugfixes from you to it.

Thanks for writing this library 👍

Exposing times array

Hi,

Would you be open to a PR which exposed the times array on SunCalc? I'd like to be able to introspect upon it in order to provide users (of a reminder app I am hoping to finish) with a list of choices for setting reminders relative to astronomical events. I'm mostly interested in dawn/sunrise/sunsets (for religious reasons), but I figure it wouldn't hurt and would be more DRY to programmatically iterate the times array... Not a big deal though...

moon rise date earlier than moon set date

SunCalc.getMoonTimes is based on http://www.stargazing.net/kepler/moonrise.html and that algorithm returns a relative moon rise and moon set. So for instance, at 45 lat and -92.12 lon on 20151028 SunCalc.getMoonTimes returns that the moon rise is Wed Oct 28 2015 19:22:01 GMT-0500 (Central Daylight Time) and the moon set is Wed Oct 28 2015 08:58:15 GMT-0500 (Central Daylight Time). These times are relatively correct, but the moon rise date returned is later than the moon set date returned. The fix is to add 24 to the moon set hours parameter of the hoursLater function call to get the result.set to return when the moon rise hours parameter is greater than the moon set hours.

public sunCoords and moonCords functions

I need the RA values but I cannot access the functions sunCoords and moonCords. Is there any idea why it isn't exported?

I think the only possible way is to export the functions to SunCalc object, right?

No moonrise/moonset when moon rises after midnight

Sat Nov 15 2014: does not return any moonrise/set. Local weatherclock says moonrise 0:46 moonset 13:23

This seems to be an off by 1 error in SunCalc.getMoonTimes

// go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set)
for (var i = 1; i <= 24; i += 2) {
            ^^^

will start trying one hour too late. Changing to
for (var i = 0; i <= 24; i += 2) {

apparently fixes this.

suncalc.net calculating incorrect times

I'm researching your script and found suncalc.net. It loaded on Westminster, London initially, with these details:

19:57 — dawn
20:45 — sunrise
05:04 — solar noon
13:23 — sunset
14:10 — dusk

When I try Auckland, NZ it produces these results:

12:06 — dawn
12:35 — sunrise
17:24 — solar noon
22:13 — sunset (I was there last week and this should be approx 17:30)
22:42 — dusk

I'm currently in San Francisco, and using 'detect my location' the results appear correct:

05:17 — dawn
05:48 — sunrise
13:12 — solar noon
20:36 — sunset
21:07 — dusk

I'm wondering if this is a timezone/DST issue? SF is -8:00, Auckland is +12:00.

"SunCalc.getTimesBetween" call?

So many <3 for SunCalc. Thanks again for providing it.

I am interested in a rather different API call: I'd like to provide a location, start date, and end date, and get all "events" that happen between those times. That is, for each of the following:

  • sunrise
  • sunriseEnd
  • goldenHourEnd
  • solarNoon
  • goldenHour
  • sunsetStart
  • sunset
  • dusk
  • nauticalDusk
  • night
  • nadir
  • nightEnd
  • nauticalDawn
  • dawn
  • moonrise
  • moonset
  • newMoon
  • firstQuarterMoon
  • fullMoon
  • thirdQuarterMoon

I'd like a list to be generated and returned for every one of the above events that happens between those two dates (inclusive). (It'd be especially nice if I could select, using an optional object, which properties I care about, in order to cut down on unnecessary computations...)

This might be something that's starting to get a little out-of-scope of the project; but on the other hand, one could conceivably implement the SunCalc.getTimes function in terms of this one, so maybe it's a 2.0 thing (that is, a change in API).

Moon phase - waxing or waning?

Salutations, and thank you for this great library.

Does the library provide a way to calculate whether the moon is waxing or waning?
Am i correct in thinking that "getMoonFraction" does not differentiate between waxing and waning?

Much appreciated,

calculation error ?

Hi,

I have tried the module using:
SunCalc.getTimes(new Date(), 51.59,-4.77);

However the results for sunrise and sunset are approx 39 minutes off (later) than found on:
http://www.timeanddate.com/worldclock/astronomy.html?n=1298
The longitude and lattitude in the function parameters match those of Dordrecht.

I've developed my own code in lua a few years ago based on some math that I found on the internet and that does (almost) match the results of timeanddate.com

Do you have any idea what I'm doing wrong ?

Kind regards,

Hans

Add Timezone offset argument

After date, lat and lng we should add an offset argument from GMT to display the calculations in the correct time to the location being calculated for. If we leave this as a simple argument requiring "5" or "-5" and so on then the user can get this using the Node.js package tzwhere or use an API from Google, Geonames or other sources.

Problem with sunset calculation: I don't get the right time

Hello!

First of all, thank you for this great library!

Unfortunately, I have a problem when calculating sunset hours.

Here is an example to illustrate my problem:
If I go on: http://www.suncalc.net The sunset hour for today in Brussels is 21h37. When I use the JavaScript Library Downloaded on GitHub, I obtain 21h40. Why this difference between the two results?

Thank you!

Michael.

Just want to say thanks

@mourner Big thanks for this nice library. 😄 I am amazed how it's possible to apply math here to get this information. When I first saw it, I expected that it will make requests to some external service, but actually it's just mathematics. 💫

Keep up the good work! 🌝

UTC causing issues?

Something is odd, perhaps someone can explain, if I run this from my mac laptop (which is in MST by default) everything returns as expected, spot on.

If I move the script to our server, which is in UTC time, all the dawn, disk, sunrise, sunset, etc. values are all off, even though the date/locations are all the same as my computer. I suspect maybe the fact the date is UTC is causing issues perhaps?

Anyone have any ideas?

Strange solar azimuth/altitudes near and below equator

I've been building an application for graphing the sun position throughout the day by taking az/alt samples at intervals before and after solar noon. This has worked brilliantly for most places on the globe, but doesn't behave correctly near and below the equator.

By my rough checks the times solarcalc provides at these lat/longs for solar noon/rise/set seem correct, but the altitudes and azimuths definitely aren't. In a lot of cases the graph ends up looking upside-down, or asymptotic.

Before I dive in myself I wanted to check if the experts here had an inkling of what might be going on!


Quito, Equador (0.233, 78.517)

Expected

screen shot 2015-06-23 at 10 34 17 am

Actual

quito equador

Sydney, Australia (–33.868, 151.206)

Expected

screen shot 2015-06-23 at 10 32 13 am

Actual

sydney australia

McMurdo Station, Antartica (–77.850, 166.667)

Expected

screen shot 2015-06-23 at 10 34 28 am

Actual

mcmurdo antartica

SunCalc.getMoonTimes returns object with no "set" property

This issue appears to be related to the closed issue: No moonrise/moonset when moon rises after midnight #37

When the moon set time should be within the hour after midnight, no set property gets returned. I would expect from the code this would also be the case with moon rise.

Following is a call with exact date and coordinates to reproduce the issue.

currentDate = Sun Jun 21 2015 00:00:00 GMT-0700 (Pacific Daylight Time)
mapSettings.latitude = 48.41894
mapSettings.longitude = -122.63909999999998

SunCalc.getMoonTimes(currentDate, mapSettings.latitude, mapSettings.longitude);

This returns a moonTimes object with a rise property only.

As discussed in the referenced issue, it appears that line 253 is off by 1.
253: for (var i = 1; i <= 24; i += 2) {

The hours of the day are 0 - 23, not 1 - 24 as this for loop suggests.
Changing this line to the following rectifies the problem:
253: for (var i = 0; i < 24; i += 2) {
OR
253: for (var i = 0; i <= 23; i += 2) {

is Moon position correct?

Hi all,
I'm not sure if what I did was correct or not but I guess I'm getting different numbers from realty. This is the example I did:
The location is Makkah, Saudi Arabia:
lat=21.41667, long = 39.81667
The date is 27/07/2014 at 07:04:06 (Sunset time at that date).

The result:
moonIllumination.phase = 0.9841400857315085

where the actual was < 0.09 i.e. New Moon.

Real Time Sun Movement

I would like to move a representation of the sun and the moon and an x and y axis across the browser runtime in real time in a manner similar to the attached photograph. However I cannot find the correct calculations.

How did you represent the suns movement on a flat X Y plane for suncalc.net?

10389967_10206442225590678_5409985522669922473_n 1

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.