Skip to content
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ navigator.geolocation.getCurrentPosition(function(position) {
var sunset = new Date().sunset(position.coords.latitude, position.coords.longitude);
});

//You can set a custom zenith to get twilight times.
//See the source for available zenith values and their meanings.
//Get civil dusk for Forks, WA
var twilight = new Date().sunset(47.95, -124.38, Date.zenith.CIVIL);

```

By Matt Kane (@ascorbic). Copyright © 2012 Triggertrap Ltd. All Rights Reserved.
Expand Down
16 changes: 15 additions & 1 deletion sun.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ Date.prototype.sunset = function(latitude, longitude, zenith) {
return this.sunriseSet(latitude, longitude, false, zenith);
}

Date.zenith = {
/** Astronomical sunrise/set is when the sun is 18 degrees below the horizon. */
ASTRONOMICAL: 108,

/** Nautical sunrise/set is when the sun is 12 degrees below the horizon. */
NAUTICAL: 102,

/** Civil sunrise/set (dawn/dusk) is when the sun is 6 degrees below the horizon. */
CIVIL: 96,

/** Official sunrise/set is when the sun is 50' below the horizon. */
OFFICIAL: 90.8333
}

Date.prototype.sunriseSet = function(latitude, longitude, sunrise, zenith) {
if(!zenith) {
zenith = 90.8333;
zenith = Date.zenith.OFFICIAL;
}


Expand Down