Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to give time when in extream #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/solarCalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SolarCalc {
}

get sunset() {
return this.sun.timeAtAngle(degreesBelowHorizon.sunrise);
return this.sun.timeAtAngle(degreesBelowHorizon.sunrise, false);
}

get sunriseEnd() {
Expand Down
8 changes: 4 additions & 4 deletions src/sun.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,24 @@ function calcSunriseSet(rise, angle, JD, date, latitude, longitude)
if (((latitude > 66.4) && (doy > 79) && (doy < 267)) ||
((latitude < -66.4) && ((doy < 83) || (doy > 263)))) { //previous sunrise/next sunset
jdy = calcJDofNextPrevRiseSet(!rise, rise, angle, JD, latitude, longitude);
return dayString(jdy);
} else { //previous sunset/next sunrise
jdy = calcJDofNextPrevRiseSet(rise, rise, angle, JD, latitude, longitude);
return dayString(jdy);
}
timeUTC = calcSunriseSetUTC(rise, angle, jdy, latitude, longitude);
newTimeUTC = calcSunriseSetUTC(rise, angle, jdy + timeUTC / 1440.0, latitude, longitude);
var newDate = dayString(jdy);
return formatDate(newDate, newTimeUTC);
}
}

function calcJDofNextPrevRiseSet(next, rise, type, JD, latitude, longitude) {
var julianday = JD;
var increment = ((next) ? 1.0 : -1.0);

var time = calcSunriseSetUTC(rise, type, julianday, latitude, longitude);
while (!isNumber(time)) {
julianday += increment;
time = calcSunriseSetUTC(rise, type, julianday, latitude, longitude);
}

return julianday;
}

Expand Down
24 changes: 12 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,51 +96,51 @@ describe('suncalc', function() {
});

it('get golden hour start', function() {
assert.equal(1439856000000, solarCalc.goldenHourStart.getTime());
assert.equal(1439951815000, solarCalc.goldenHourStart.getTime());
});

it('get golden hour end', function() {
assert.equal(1430006400000, solarCalc.goldenHourEnd.getTime());
assert.equal(1430023977000, solarCalc.goldenHourEnd.getTime());
});

it('get night end', function() {
assert.equal(1424476800000, solarCalc.nightEnd.getTime());
assert.equal(1424495885000, solarCalc.nightEnd.getTime());
});

it('get nautical dawn', function() {
assert.equal(1425859200000, solarCalc.nauticalDawn.getTime());
assert.equal(1425877733000, solarCalc.nauticalDawn.getTime());
});

it('get dawn', function() {
assert.equal(1427155200000, solarCalc.dawn.getTime());
assert.equal(1427174160000, solarCalc.dawn.getTime());
});

it('get sunrise', function() {
assert.equal(1428364800000, solarCalc.sunrise.getTime());
assert.equal(1428380823000, solarCalc.sunrise.getTime());
});

it('get sunriseEnd', function() {
assert.equal(1428451200000, solarCalc.sunriseEnd.getTime());
assert.equal(1428469232000, solarCalc.sunriseEnd.getTime());
});

it('get sunsetStart', function() {
assert.equal(1441411200000, solarCalc.sunsetStart.getTime());
assert.equal(1441506692000, solarCalc.sunsetStart.getTime());
});

it('get sunset', function() {
assert.equal(1441497600000, solarCalc.sunset.getTime());
assert.equal(1441593806000, solarCalc.sunset.getTime());
});

it('get dusk', function() {
assert.equal(1442707200000, solarCalc.dusk.getTime());
assert.equal(1442802301000, solarCalc.dusk.getTime());
});

it('get nautical dusk', function() {
assert.equal(1444003200000, solarCalc.nauticalDusk.getTime());
assert.equal(1444098841000, solarCalc.nauticalDusk.getTime());
});

it('get night start', function() {
assert.equal(1445385600000, solarCalc.nightStart.getTime());
assert.equal(1445481337000, solarCalc.nightStart.getTime());
});

it('should get moon illuminosity', function() {
Expand Down